From c52458a7e39af275e2ae31732fe0d999493132f6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 31 Aug 2021 18:00:54 +0800 Subject: [PATCH] add: require profile completed --- app/controllers/application_controller.rb | 4 ++++ app/controllers/forks_controller.rb | 1 + app/controllers/issues_controller.rb | 1 + app/controllers/journals_controller.rb | 1 + app/controllers/organizations/organizations_controller.rb | 1 + app/controllers/praise_tread_controller.rb | 1 + app/controllers/projects/project_applies_controller.rb | 1 + app/controllers/projects_controller.rb | 1 + app/controllers/pull_requests_controller.rb | 1 + app/controllers/users_controller.rb | 1 + app/controllers/versions_controller.rb | 1 + app/controllers/watchers_controller.rb | 1 + 12 files changed, 15 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d3f9c193a..99b988cb5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -246,6 +246,10 @@ class ApplicationController < ActionController::Base tip_exception(401, "请登录后再操作") unless User.current.logged? end + def require_profile_completed + tip_exception(411, "请完善资料后再操作") unless User.current.profile_completed + end + # 异常提醒 def tip_exception(status = -1, message) raise Educoder::TipException.new(status, message) diff --git a/app/controllers/forks_controller.rb b/app/controllers/forks_controller.rb index cb18091c1..409133f06 100644 --- a/app/controllers/forks_controller.rb +++ b/app/controllers/forks_controller.rb @@ -1,5 +1,6 @@ class ForksController < ApplicationController before_action :require_login + before_action :require_profile_completed, only: [:create] before_action :load_project before_action :authenticate_project!, :authenticate_user! diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index ca74247d5..cfbd8a624 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -1,5 +1,6 @@ class IssuesController < ApplicationController before_action :require_login, except: [:index, :show, :index_chosen] + before_action :require_profile_completed, only: [:create] before_action :load_project before_action :set_user before_action :check_issue_permission diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 6917974b8..ab00628d9 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -1,5 +1,6 @@ class JournalsController < ApplicationController before_action :require_login, except: [:index, :get_children_journals] + before_action :require_profile_completed, only: [:create] before_action :set_issue before_action :check_issue_permission before_action :set_journal, only: [:destroy, :edit, :update] diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index 104db90ed..76aaca0fc 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -1,5 +1,6 @@ class Organizations::OrganizationsController < Organizations::BaseController before_action :require_login, except: [:index, :show, :recommend] + before_action :require_profile_completed, only: [:create] before_action :convert_image!, only: [:create, :update] before_action :load_organization, only: [:show, :update, :destroy] before_action :check_user_can_edit_org, only: [:update, :destroy] diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 983697e08..c355e8fd2 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -1,5 +1,6 @@ class PraiseTreadController < ApplicationController before_action :require_login, except: %i[index] + before_action :require_profile_completed, only: [:like] before_action :find_project_with_id def index diff --git a/app/controllers/projects/project_applies_controller.rb b/app/controllers/projects/project_applies_controller.rb index 37d9d615e..63922a461 100644 --- a/app/controllers/projects/project_applies_controller.rb +++ b/app/controllers/projects/project_applies_controller.rb @@ -1,4 +1,5 @@ class Projects::ProjectAppliesController < Projects::BaseController + before_action :require_profile_completed, only: [:create] def create project = Projects::ApplyJoinService.call(current_user, create_params) render_ok(project_id: project.id) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 818abf548..02403bbd9 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -5,6 +5,7 @@ class ProjectsController < ApplicationController include Acceleratorable before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users recommend about menu_list] + before_action :require_profile_completed, only: [:create, :migrate] before_action :load_repository, except: %i[index group_type_list migrate create recommend] before_action :authorizate_user_can_edit_project!, only: %i[update] before_action :project_public?, only: %i[fork_users praise_users watch_users] diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 1a74e91a3..e1639969a 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,5 +1,6 @@ class PullRequestsController < ApplicationController before_action :require_login, except: [:index, :show, :files, :commits] + before_action :require_profile_completed, only: [:create] before_action :load_repository before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits] before_action :load_pull_request, only: [:files, :commits] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a0184a348..f41a8a4ca 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -78,6 +78,7 @@ class UsersController < ApplicationController return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) Util.write_file(@image, avatar_path(@user)) if user_params[:image].present? @user.attributes = user_params.except(:image) + @user.profile_completed = true if @user.nickname.present? && @user.gender.present? && @user.mail.present? && @user.custom_department.present? unless @user.save render_error(@user.errors.full_messages.join(", ")) end diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 58cd9e87f..cf5b3b9f1 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -1,5 +1,6 @@ class VersionsController < ApplicationController before_action :require_login, except: [:index, :show] + before_action :require_profile_completed, only: [:create] before_action :load_repository before_action :check_issue_permission, except: [:show, :index] before_action :set_version, only: [:edit, :update, :destroy, :show,:update_status] diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 38f60ebae..aa3642616 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -1,5 +1,6 @@ class WatchersController < ApplicationController before_action :require_login, except: %i[index] + before_action :require_profile_completed, only: [:follow] # before_action :find_project_with_id before_action :get_target