| @@ -23,10 +23,23 @@ class Admins::BaseController < ApplicationController | |||||
| def require_admin! | def require_admin! | ||||
| return if current_user.blank? || !current_user.logged? | return if current_user.blank? || !current_user.logged? | ||||
| return if current_user.admin_or_business? | return if current_user.admin_or_business? | ||||
| return if current_user.admin_or_glcc_admin? | |||||
| render_forbidden | render_forbidden | ||||
| end | end | ||||
| def require_admin | |||||
| render_forbidden unless User.current.admin? | |||||
| end | |||||
| def require_business | |||||
| render_forbidden unless admin_or_business? | |||||
| end | |||||
| def require_glcc_admin | |||||
| render_forbidden unless admin_or_glcc_admin? | |||||
| end | |||||
| # 触发after ajax render partial hooks,执行一些因为局部刷新后失效的绑定事件 | # 触发after ajax render partial hooks,执行一些因为局部刷新后失效的绑定事件 | ||||
| def rebind_event_if_ajax_render_partial | def rebind_event_if_ajax_render_partial | ||||
| return if request.format.symbol != :js | return if request.format.symbol != :js | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::EduSettingsController < Admins::BaseController | class Admins::EduSettingsController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :find_setting, only: [:edit,:update, :destroy] | before_action :find_setting, only: [:edit,:update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::FaqsController < Admins::BaseController | class Admins::FaqsController < Admins::BaseController | ||||
| before_action :require_business | |||||
| before_action :find_faq, only: [:edit,:update, :destroy] | before_action :find_faq, only: [:edit,:update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::FeedbacksController < Admins::BaseController | class Admins::FeedbacksController < Admins::BaseController | ||||
| before_action :require_business | |||||
| before_action :get_feedback, only: [:new_history, :create_history, :destroy] | before_action :get_feedback, only: [:new_history, :create_history, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,6 @@ | |||||
| class Admins::GlccPrCheckController < Admins::BaseController | class Admins::GlccPrCheckController < Admins::BaseController | ||||
| before_action :require_glcc_admin | |||||
| def index | def index | ||||
| params[:sort_by] = params[:sort_by].presence || 'created_on' | params[:sort_by] = params[:sort_by].presence || 'created_on' | ||||
| params[:sort_direction] = params[:sort_direction].presence || 'desc' | params[:sort_direction] = params[:sort_direction].presence || 'desc' | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::IdentityVerificationsController < Admins::BaseController | class Admins::IdentityVerificationsController < Admins::BaseController | ||||
| before_action :require_business | |||||
| before_action :finder_identity_verification, except: [:index] | before_action :finder_identity_verification, except: [:index] | ||||
| def index | def index | ||||
| params[:sort_by] = params[:sort_by].presence || 'created_at' | params[:sort_by] = params[:sort_by].presence || 'created_at' | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::IssuesRankController < Admins::BaseController | class Admins::IssuesRankController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| def index | def index | ||||
| @statistics = DailyProjectStatistic.where('date >= ? AND date <= ?', begin_date, end_date) | @statistics = DailyProjectStatistic.where('date >= ? AND date <= ?', begin_date, end_date) | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::LaboratoriesController < Admins::BaseController | class Admins::LaboratoriesController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| def index | def index | ||||
| default_sort('id', 'desc') | default_sort('id', 'desc') | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::MessageTemplatesController < Admins::BaseController | class Admins::MessageTemplatesController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :get_template, only: [:edit, :update, :destroy] | before_action :get_template, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::NpsController < Admins::BaseController | class Admins::NpsController < Admins::BaseController | ||||
| before_action :require_business | |||||
| def index | def index | ||||
| @on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true' | @on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true' | ||||
| @user_nps = UserNp.joins(:user).order(created_at: :desc) | @user_nps = UserNp.joins(:user).order(created_at: :desc) | ||||
| @@ -1,5 +1,6 @@ | |||||
| class Admins::OrganizationsController < Admins::BaseController | class Admins::OrganizationsController < Admins::BaseController | ||||
| before_action :finder_org, except: [:index] | |||||
| before_action :require_admin | |||||
| before_action :finder_org, except: [:index] | |||||
| def index | def index | ||||
| params[:sort_by] = params[:sort_by].presence || 'created_on' | params[:sort_by] = params[:sort_by].presence || 'created_on' | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::PageThemesController < Admins::BaseController | class Admins::PageThemesController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :finder_page_theme, only: [:edit, :update, :destroy] | before_action :finder_page_theme, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::ProjectCategoriesController < Admins::BaseController | class Admins::ProjectCategoriesController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :get_category, only: [:edit,:update, :destroy] | before_action :get_category, only: [:edit,:update, :destroy] | ||||
| before_action :validate_names, only: [:create, :update] | before_action :validate_names, only: [:create, :update] | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::ProjectIgnoresController < Admins::BaseController | class Admins::ProjectIgnoresController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :set_ignore, only: [:edit,:update, :destroy,:show] | before_action :set_ignore, only: [:edit,:update, :destroy,:show] | ||||
| # before_action :validate_params, only: [:create, :update] | # before_action :validate_params, only: [:create, :update] | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::ProjectLanguagesController < Admins::BaseController | class Admins::ProjectLanguagesController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :get_language, only: [:edit,:update, :destroy] | before_action :get_language, only: [:edit,:update, :destroy] | ||||
| before_action :validate_names, only: [:create, :update] | before_action :validate_names, only: [:create, :update] | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::ProjectLicensesController < Admins::BaseController | class Admins::ProjectLicensesController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :set_license, only: [:edit,:update, :destroy,:show] | before_action :set_license, only: [:edit,:update, :destroy,:show] | ||||
| # before_action :validate_params, only: [:create, :update] | # before_action :validate_params, only: [:create, :update] | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::ProjectsController < Admins::BaseController | class Admins::ProjectsController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :find_project, only: [:edit, :update] | before_action :find_project, only: [:edit, :update] | ||||
| def index | def index | ||||
| @@ -1,4 +1,6 @@ | |||||
| class Admins::ProjectsRankController < Admins::BaseController | class Admins::ProjectsRankController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| def index | def index | ||||
| @statistics = DailyProjectStatistic.where("date >= ? AND date <= ?", begin_date, end_date) | @statistics = DailyProjectStatistic.where("date >= ? AND date <= ?", begin_date, end_date) | ||||
| @statistics = @statistics.group(:project_id).select("project_id, | @statistics = @statistics.group(:project_id).select("project_id, | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::ReversedKeywordsController < Admins::BaseController | class Admins::ReversedKeywordsController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :get_keyword, only: [:edit,:update, :destroy] | before_action :get_keyword, only: [:edit,:update, :destroy] | ||||
| # before_action :validate_identifer, only: [:create, :update] | # before_action :validate_identifer, only: [:create, :update] | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::SitePagesController < Admins::BaseController | class Admins::SitePagesController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :finder_site_page, except: [:index] | before_action :finder_site_page, except: [:index] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::SitesController < Admins::BaseController | class Admins::SitesController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :find_site, only: [:edit,:update, :destroy] | before_action :find_site, only: [:edit,:update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::SystemNotificationsController < Admins::BaseController | class Admins::SystemNotificationsController < Admins::BaseController | ||||
| before_action :require_business | |||||
| before_action :get_notification, only: [:history, :edit,:update, :destroy] | before_action :get_notification, only: [:history, :edit,:update, :destroy] | ||||
| # before_action :validate_identifer, only: [:create, :update] | # before_action :validate_identifer, only: [:create, :update] | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController | class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController | ||||
| before_action :require_business | |||||
| before_action :find_activity_forum, only: [:edit, :update, :destroy] | before_action :find_activity_forum, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::Topic::BannersController < Admins::Topic::BaseController | class Admins::Topic::BannersController < Admins::Topic::BaseController | ||||
| before_action :require_business | |||||
| before_action :find_banner, only: [:edit, :update, :destroy] | before_action :find_banner, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::Topic::CardsController < Admins::Topic::BaseController | class Admins::Topic::CardsController < Admins::Topic::BaseController | ||||
| before_action :require_business | |||||
| before_action :find_card, only: [:edit, :update, :destroy] | before_action :find_card, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::Topic::CooperatorsController < Admins::Topic::BaseController | class Admins::Topic::CooperatorsController < Admins::Topic::BaseController | ||||
| before_action :require_business | |||||
| before_action :find_cooperator, only: [:edit, :update, :destroy] | before_action :find_cooperator, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController | class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController | ||||
| before_action :require_business | |||||
| before_action :find_excellent_project, only: [:edit, :update, :destroy] | before_action :find_excellent_project, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController | class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController | ||||
| before_action :require_business | |||||
| before_action :find_experience_forum, only: [:edit, :update, :destroy] | before_action :find_experience_forum, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::Topic::GlccNewsController < Admins::Topic::BaseController | class Admins::Topic::GlccNewsController < Admins::Topic::BaseController | ||||
| before_action :require_glcc_admin | |||||
| before_action :find_glcc, only: [:edit, :update, :destroy] | before_action :find_glcc, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController | class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController | ||||
| before_action :require_business | |||||
| before_action :find_pinned_forum, only: [:edit, :update, :destroy] | before_action :find_pinned_forum, only: [:edit, :update, :destroy] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::UsersController < Admins::BaseController | class Admins::UsersController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| before_action :finder_user, except: [:index] | before_action :finder_user, except: [:index] | ||||
| def index | def index | ||||
| @@ -1,4 +1,5 @@ | |||||
| class Admins::UsersRankController < Admins::BaseController | class Admins::UsersRankController < Admins::BaseController | ||||
| before_action :require_admin | |||||
| def index | def index | ||||
| @rank_date = rank_date | @rank_date = rank_date | ||||
| @@ -75,7 +75,11 @@ class ApplicationController < ActionController::Base | |||||
| def admin_or_business? | def admin_or_business? | ||||
| User.current.admin? || User.current.business? || User.current.glcc_admin? | |||||
| User.current.admin? || User.current.business? | |||||
| end | |||||
| def admin_or_glcc_admin? | |||||
| User.current.admin? || User.current.glcc_admin? | |||||
| end | end | ||||
| # 判断用户的邮箱或者手机是否可用 | # 判断用户的邮箱或者手机是否可用 | ||||
| @@ -195,6 +199,10 @@ class ApplicationController < ActionController::Base | |||||
| normal_status(403, "") unless admin_or_business? | normal_status(403, "") unless admin_or_business? | ||||
| end | end | ||||
| def require_glcc_admin | |||||
| normal_status(403, "") unless admin_or_glcc_admin? | |||||
| end | |||||
| # 前端会捕捉401,弹登录弹框 | # 前端会捕捉401,弹登录弹框 | ||||
| # 未授权的捕捉407,弹试用申请弹框 | # 未授权的捕捉407,弹试用申请弹框 | ||||
| def require_login | def require_login | ||||
| @@ -833,7 +833,11 @@ class User < Owner | |||||
| end | end | ||||
| def admin_or_business? | def admin_or_business? | ||||
| admin? || business? || glcc_admin? | |||||
| admin? || business? | |||||
| end | |||||
| def admin_or_glcc_admin? | |||||
| admin? || glcc_admin? | |||||
| end | end | ||||
| def self.generate_login(prefix) | def self.generate_login(prefix) | ||||