diff --git a/app/controllers/admins/base_controller.rb b/app/controllers/admins/base_controller.rb index fbfc3fc41..e2882978b 100644 --- a/app/controllers/admins/base_controller.rb +++ b/app/controllers/admins/base_controller.rb @@ -23,10 +23,23 @@ class Admins::BaseController < ApplicationController def require_admin! return if current_user.blank? || !current_user.logged? return if current_user.admin_or_business? + return if current_user.admin_or_glcc_admin? render_forbidden 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,执行一些因为局部刷新后失效的绑定事件 def rebind_event_if_ajax_render_partial return if request.format.symbol != :js diff --git a/app/controllers/admins/edu_settings_controller.rb b/app/controllers/admins/edu_settings_controller.rb index 9d9334b23..8d9985998 100644 --- a/app/controllers/admins/edu_settings_controller.rb +++ b/app/controllers/admins/edu_settings_controller.rb @@ -1,4 +1,5 @@ class Admins::EduSettingsController < Admins::BaseController + before_action :require_admin before_action :find_setting, only: [:edit,:update, :destroy] def index diff --git a/app/controllers/admins/faqs_controller.rb b/app/controllers/admins/faqs_controller.rb index 250d3d60a..c16cca934 100644 --- a/app/controllers/admins/faqs_controller.rb +++ b/app/controllers/admins/faqs_controller.rb @@ -1,4 +1,5 @@ class Admins::FaqsController < Admins::BaseController + before_action :require_business before_action :find_faq, only: [:edit,:update, :destroy] def index diff --git a/app/controllers/admins/feedbacks_controller.rb b/app/controllers/admins/feedbacks_controller.rb index ff64ae5a1..59515ad2a 100644 --- a/app/controllers/admins/feedbacks_controller.rb +++ b/app/controllers/admins/feedbacks_controller.rb @@ -1,4 +1,5 @@ class Admins::FeedbacksController < Admins::BaseController + before_action :require_business before_action :get_feedback, only: [:new_history, :create_history, :destroy] def index diff --git a/app/controllers/admins/glcc_pr_check_controller.rb b/app/controllers/admins/glcc_pr_check_controller.rb index 1d79ba802..8d6d9dd70 100644 --- a/app/controllers/admins/glcc_pr_check_controller.rb +++ b/app/controllers/admins/glcc_pr_check_controller.rb @@ -1,4 +1,6 @@ class Admins::GlccPrCheckController < Admins::BaseController + before_action :require_glcc_admin + def index params[:sort_by] = params[:sort_by].presence || 'created_on' params[:sort_direction] = params[:sort_direction].presence || 'desc' diff --git a/app/controllers/admins/identity_verifications_controller.rb b/app/controllers/admins/identity_verifications_controller.rb index 1db1a9883..aec9aee61 100644 --- a/app/controllers/admins/identity_verifications_controller.rb +++ b/app/controllers/admins/identity_verifications_controller.rb @@ -1,4 +1,5 @@ class Admins::IdentityVerificationsController < Admins::BaseController + before_action :require_business before_action :finder_identity_verification, except: [:index] def index params[:sort_by] = params[:sort_by].presence || 'created_at' diff --git a/app/controllers/admins/issues_rank_controller.rb b/app/controllers/admins/issues_rank_controller.rb index 79450fbfb..53be77a4d 100644 --- a/app/controllers/admins/issues_rank_controller.rb +++ b/app/controllers/admins/issues_rank_controller.rb @@ -1,4 +1,5 @@ class Admins::IssuesRankController < Admins::BaseController + before_action :require_admin def index @statistics = DailyProjectStatistic.where('date >= ? AND date <= ?', begin_date, end_date) diff --git a/app/controllers/admins/laboratories_controller.rb b/app/controllers/admins/laboratories_controller.rb index 7044b6218..e201372c5 100644 --- a/app/controllers/admins/laboratories_controller.rb +++ b/app/controllers/admins/laboratories_controller.rb @@ -1,4 +1,5 @@ class Admins::LaboratoriesController < Admins::BaseController + before_action :require_admin def index default_sort('id', 'desc') diff --git a/app/controllers/admins/message_templates_controller.rb b/app/controllers/admins/message_templates_controller.rb index abe332ac5..502adbed1 100644 --- a/app/controllers/admins/message_templates_controller.rb +++ b/app/controllers/admins/message_templates_controller.rb @@ -1,4 +1,5 @@ class Admins::MessageTemplatesController < Admins::BaseController + before_action :require_admin before_action :get_template, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/nps_controller.rb b/app/controllers/admins/nps_controller.rb index 8b3d828ff..bfb72f730 100644 --- a/app/controllers/admins/nps_controller.rb +++ b/app/controllers/admins/nps_controller.rb @@ -1,4 +1,5 @@ class Admins::NpsController < Admins::BaseController + before_action :require_business def index @on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true' @user_nps = UserNp.joins(:user).order(created_at: :desc) diff --git a/app/controllers/admins/organizations_controller.rb b/app/controllers/admins/organizations_controller.rb index 3d4eac4c6..0b0e60966 100644 --- a/app/controllers/admins/organizations_controller.rb +++ b/app/controllers/admins/organizations_controller.rb @@ -1,5 +1,6 @@ class Admins::OrganizationsController < Admins::BaseController - before_action :finder_org, except: [:index] + before_action :require_admin + before_action :finder_org, except: [:index] def index params[:sort_by] = params[:sort_by].presence || 'created_on' diff --git a/app/controllers/admins/page_themes_controller.rb b/app/controllers/admins/page_themes_controller.rb index 1b2cd8ebe..025fa5106 100644 --- a/app/controllers/admins/page_themes_controller.rb +++ b/app/controllers/admins/page_themes_controller.rb @@ -1,4 +1,5 @@ class Admins::PageThemesController < Admins::BaseController + before_action :require_admin before_action :finder_page_theme, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/project_categories_controller.rb b/app/controllers/admins/project_categories_controller.rb index 72cb833fa..2a518cfa0 100644 --- a/app/controllers/admins/project_categories_controller.rb +++ b/app/controllers/admins/project_categories_controller.rb @@ -1,4 +1,5 @@ class Admins::ProjectCategoriesController < Admins::BaseController + before_action :require_admin before_action :get_category, only: [:edit,:update, :destroy] before_action :validate_names, only: [:create, :update] diff --git a/app/controllers/admins/project_ignores_controller.rb b/app/controllers/admins/project_ignores_controller.rb index 6450f6afc..5153bf23f 100644 --- a/app/controllers/admins/project_ignores_controller.rb +++ b/app/controllers/admins/project_ignores_controller.rb @@ -1,4 +1,5 @@ class Admins::ProjectIgnoresController < Admins::BaseController + before_action :require_admin before_action :set_ignore, only: [:edit,:update, :destroy,:show] # before_action :validate_params, only: [:create, :update] diff --git a/app/controllers/admins/project_languages_controller.rb b/app/controllers/admins/project_languages_controller.rb index 69594eb50..34b787563 100644 --- a/app/controllers/admins/project_languages_controller.rb +++ b/app/controllers/admins/project_languages_controller.rb @@ -1,4 +1,5 @@ class Admins::ProjectLanguagesController < Admins::BaseController + before_action :require_admin before_action :get_language, only: [:edit,:update, :destroy] before_action :validate_names, only: [:create, :update] diff --git a/app/controllers/admins/project_licenses_controller.rb b/app/controllers/admins/project_licenses_controller.rb index 44ae75118..d573d3c23 100644 --- a/app/controllers/admins/project_licenses_controller.rb +++ b/app/controllers/admins/project_licenses_controller.rb @@ -1,4 +1,5 @@ class Admins::ProjectLicensesController < Admins::BaseController + before_action :require_admin before_action :set_license, only: [:edit,:update, :destroy,:show] # before_action :validate_params, only: [:create, :update] diff --git a/app/controllers/admins/projects_controller.rb b/app/controllers/admins/projects_controller.rb index 926ab8a29..fd576b8c8 100644 --- a/app/controllers/admins/projects_controller.rb +++ b/app/controllers/admins/projects_controller.rb @@ -1,4 +1,5 @@ class Admins::ProjectsController < Admins::BaseController + before_action :require_admin before_action :find_project, only: [:edit, :update] def index diff --git a/app/controllers/admins/projects_rank_controller.rb b/app/controllers/admins/projects_rank_controller.rb index 9e7df34f7..55dde85e9 100644 --- a/app/controllers/admins/projects_rank_controller.rb +++ b/app/controllers/admins/projects_rank_controller.rb @@ -1,4 +1,6 @@ class Admins::ProjectsRankController < Admins::BaseController + before_action :require_admin + def index @statistics = DailyProjectStatistic.where("date >= ? AND date <= ?", begin_date, end_date) @statistics = @statistics.group(:project_id).select("project_id, diff --git a/app/controllers/admins/reversed_keywords_controller.rb b/app/controllers/admins/reversed_keywords_controller.rb index 8a8442f72..0184c542d 100644 --- a/app/controllers/admins/reversed_keywords_controller.rb +++ b/app/controllers/admins/reversed_keywords_controller.rb @@ -1,4 +1,5 @@ class Admins::ReversedKeywordsController < Admins::BaseController + before_action :require_admin before_action :get_keyword, only: [:edit,:update, :destroy] # before_action :validate_identifer, only: [:create, :update] diff --git a/app/controllers/admins/site_pages_controller.rb b/app/controllers/admins/site_pages_controller.rb index 306c91627..24b605247 100644 --- a/app/controllers/admins/site_pages_controller.rb +++ b/app/controllers/admins/site_pages_controller.rb @@ -1,4 +1,5 @@ class Admins::SitePagesController < Admins::BaseController + before_action :require_admin before_action :finder_site_page, except: [:index] def index diff --git a/app/controllers/admins/sites_controller.rb b/app/controllers/admins/sites_controller.rb index f3da4ccf2..56252b1c4 100644 --- a/app/controllers/admins/sites_controller.rb +++ b/app/controllers/admins/sites_controller.rb @@ -1,4 +1,5 @@ class Admins::SitesController < Admins::BaseController + before_action :require_admin before_action :find_site, only: [:edit,:update, :destroy] def index diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index 33f3f20f1..1127b81fe 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -1,4 +1,5 @@ class Admins::SystemNotificationsController < Admins::BaseController + before_action :require_business before_action :get_notification, only: [:history, :edit,:update, :destroy] # before_action :validate_identifer, only: [:create, :update] diff --git a/app/controllers/admins/topic/activity_forums_controller.rb b/app/controllers/admins/topic/activity_forums_controller.rb index b027dc003..76a14027f 100644 --- a/app/controllers/admins/topic/activity_forums_controller.rb +++ b/app/controllers/admins/topic/activity_forums_controller.rb @@ -1,4 +1,5 @@ class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController + before_action :require_business before_action :find_activity_forum, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/topic/banners_controller.rb b/app/controllers/admins/topic/banners_controller.rb index c0350e355..66596792a 100644 --- a/app/controllers/admins/topic/banners_controller.rb +++ b/app/controllers/admins/topic/banners_controller.rb @@ -1,4 +1,5 @@ class Admins::Topic::BannersController < Admins::Topic::BaseController + before_action :require_business before_action :find_banner, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/topic/cards_controller.rb b/app/controllers/admins/topic/cards_controller.rb index 732f17e5b..ce14f192b 100644 --- a/app/controllers/admins/topic/cards_controller.rb +++ b/app/controllers/admins/topic/cards_controller.rb @@ -1,4 +1,5 @@ class Admins::Topic::CardsController < Admins::Topic::BaseController + before_action :require_business before_action :find_card, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/topic/cooperators_controller.rb b/app/controllers/admins/topic/cooperators_controller.rb index a1a700cbc..354188132 100644 --- a/app/controllers/admins/topic/cooperators_controller.rb +++ b/app/controllers/admins/topic/cooperators_controller.rb @@ -1,4 +1,5 @@ class Admins::Topic::CooperatorsController < Admins::Topic::BaseController + before_action :require_business before_action :find_cooperator, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/topic/excellent_projects_controller.rb b/app/controllers/admins/topic/excellent_projects_controller.rb index b60dac54c..3f8f3006b 100644 --- a/app/controllers/admins/topic/excellent_projects_controller.rb +++ b/app/controllers/admins/topic/excellent_projects_controller.rb @@ -1,4 +1,5 @@ class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController + before_action :require_business before_action :find_excellent_project, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/topic/experience_forums_controller.rb b/app/controllers/admins/topic/experience_forums_controller.rb index 420670c1b..59b4e20e6 100644 --- a/app/controllers/admins/topic/experience_forums_controller.rb +++ b/app/controllers/admins/topic/experience_forums_controller.rb @@ -1,4 +1,5 @@ class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController + before_action :require_business before_action :find_experience_forum, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/topic/glcc_news_controller.rb b/app/controllers/admins/topic/glcc_news_controller.rb index 3c1769e5f..6252b6d91 100644 --- a/app/controllers/admins/topic/glcc_news_controller.rb +++ b/app/controllers/admins/topic/glcc_news_controller.rb @@ -1,4 +1,5 @@ class Admins::Topic::GlccNewsController < Admins::Topic::BaseController + before_action :require_glcc_admin before_action :find_glcc, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/topic/pinned_forums_controller.rb b/app/controllers/admins/topic/pinned_forums_controller.rb index ac5bf69a7..50577ea95 100644 --- a/app/controllers/admins/topic/pinned_forums_controller.rb +++ b/app/controllers/admins/topic/pinned_forums_controller.rb @@ -1,4 +1,5 @@ class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController + before_action :require_business before_action :find_pinned_forum, only: [:edit, :update, :destroy] def index diff --git a/app/controllers/admins/users_controller.rb b/app/controllers/admins/users_controller.rb index e15e39242..e544cfb8e 100644 --- a/app/controllers/admins/users_controller.rb +++ b/app/controllers/admins/users_controller.rb @@ -1,4 +1,5 @@ class Admins::UsersController < Admins::BaseController + before_action :require_admin before_action :finder_user, except: [:index] def index @@ -73,6 +74,6 @@ class Admins::UsersController < Admins::BaseController def update_params params.require(:user).permit(%i[lastname nickname gender technical_title is_shixun_marker mail phone location location_city school_id department_id admin - password login website_permission]) + password login website_permission business glcc_admin]) end end diff --git a/app/controllers/admins/users_rank_controller.rb b/app/controllers/admins/users_rank_controller.rb index 2c7a62ae5..24407257c 100644 --- a/app/controllers/admins/users_rank_controller.rb +++ b/app/controllers/admins/users_rank_controller.rb @@ -1,4 +1,5 @@ class Admins::UsersRankController < Admins::BaseController + before_action :require_admin def index @rank_date = rank_date diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0c134a3bd..6957922d4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -75,7 +75,11 @@ class ApplicationController < ActionController::Base def admin_or_business? - User.current.admin? || User.current.business? + User.current.admin? || User.current.business? + end + + def admin_or_glcc_admin? + User.current.admin? || User.current.glcc_admin? end # 判断用户的邮箱或者手机是否可用 @@ -195,6 +199,10 @@ class ApplicationController < ActionController::Base normal_status(403, "") unless admin_or_business? end + def require_glcc_admin + normal_status(403, "") unless admin_or_glcc_admin? + end + # 前端会捕捉401,弹登录弹框 # 未授权的捕捉407,弹试用申请弹框 def require_login diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index fa83f6e5c..12b668d9b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -64,7 +64,8 @@ class ProjectsController < ApplicationController end rescue Gitea::Api::ServerError => ex uid_logger_error(ex.message) - tip_exception(ex.http_code, ex.message) + # tip_exception(ex.http_code, ex.message) + tip_exception(ex.message) rescue ApplicationService::Error => e uid_logger_error(e.message) tip_exception(e.message) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index a71c2ff1a..536bda3a8 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -7,6 +7,7 @@ class RepositoriesController < ApplicationController before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror] before_action :require_profile_completed, only: [:create_file] before_action :load_repository + before_action :require_operate_above, only: %i[create_file update_file replace_file delete_file] before_action :authorizate!, except: [:sync_mirror, :tags, :commit, :archive] before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror] before_action :get_ref, only: %i[entries sub_entries top_counts files archive] @@ -437,4 +438,8 @@ class RepositoriesController < ApplicationController end end + def require_operate_above + return render_forbidden if !current_user.admin? && !@project.operator?(current_user) + end + end diff --git a/app/forms/base_form.rb b/app/forms/base_form.rb index 44b5109c3..19af61026 100644 --- a/app/forms/base_form.rb +++ b/app/forms/base_form.rb @@ -26,6 +26,16 @@ class BaseForm raise "项目标识已被使用." if Repository.where(user_id: user_id, identifier: repository_name.strip).exists? end + def check_gitea_repository_name(user_id, repository_name) + user_login = User.find_by_id(user_id)&.login + begin + gitea_result = $gitea_client.get_repos_by_owner_repo(user_login, repository_name) + raise "项目标识已被使用." if gitea_result["id"].present? + rescue Gitea::Api::ServerError => e + raise "服务器错误,请联系系统管理员!" unless e.http_code.to_i == 404 + end + end + def check_project_name(user_id, project_name) raise "项目名称已被使用." if Project.where(user_id: user_id, name: project_name.strip).exists? end diff --git a/app/forms/projects/create_form.rb b/app/forms/projects/create_form.rb index 8ef7befac..d2d83bce9 100644 --- a/app/forms/projects/create_form.rb +++ b/app/forms/projects/create_form.rb @@ -16,6 +16,7 @@ class Projects::CreateForm < BaseForm check_project_language(project_language_id) check_project_name(user_id, name) unless name.blank? check_repository_name(user_id, repository_name) unless repository_name.blank? + # check_gitea_repository_name(user_id, repository_name) unless repository_name.blank? check_blockchain_token_all(blockchain_token_all) unless blockchain_token_all.blank? check_blockchain_init_token(blockchain_init_token) unless blockchain_init_token.blank? end diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index 98ebbc7ac..8c1d04968 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -11,6 +11,7 @@ class Projects::MigrateForm < BaseForm validate do check_project_name(user_id, name) unless name.blank? check_repository_name(user_id, repository_name) unless repository_name.blank? + # check_gitea_repository_name(user_id, repository_name) unless repository_name.blank? check_project_category(project_category_id) check_project_language(project_language_id) check_owner diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index 226b2dc59..e8d59ac7a 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -10,6 +10,7 @@ class Projects::UpdateForm < BaseForm check_project_language(project_language_id) check_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier + # check_gitea_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier check_project_name(user_id, name) unless name.blank? || name == project_name end diff --git a/app/helpers/manage_back_helper.rb b/app/helpers/manage_back_helper.rb index ed3f13826..cb320f80f 100644 --- a/app/helpers/manage_back_helper.rb +++ b/app/helpers/manage_back_helper.rb @@ -2,29 +2,33 @@ module ManageBackHelper extend ActiveSupport::Concern def sidebar_item_group(url, text, **opts) - link_opts = url.start_with?('/') ? {} : { 'data-toggle': 'collapse', 'aria-expanded': false } - content = - link_to url, link_opts do - content_tag(:i, '', class: "fa fa-#{opts[:icon]}", 'data-toggle': 'tooltip', 'data-placement': 'right', 'data-boundary': 'window', title: text) + - content_tag(:span, text) - end + if opts[:has_permission] + link_opts = url.start_with?('/') ? {} : { 'data-toggle': 'collapse', 'aria-expanded': false } + content = + link_to url, link_opts do + content_tag(:i, '', class: "fa fa-#{opts[:icon]}", 'data-toggle': 'tooltip', 'data-placement': 'right', 'data-boundary': 'window', title: text) + + content_tag(:span, text) + end - content += - content_tag(:ul, id: url[1..-1], class: 'collapse list-unstyled', "data-parent": '#sidebar') do - yield - end + content += + content_tag(:ul, id: url[1..-1], class: 'collapse list-unstyled', "data-parent": '#sidebar') do + yield + end - raw content + raw content + end end def sidebar_item(url, text, **opts) - content = - link_to url, 'data-controller': opts[:controller] do - content_tag(:i, '', class: "fa fa-#{opts[:icon]} fa-fw", 'data-toggle': 'tooltip', 'data-placement': 'right', 'data-boundary': 'window', title: text) + - content_tag(:span, text) - end + if opts[:has_permission] + content = + link_to url, 'data-controller': opts[:controller] do + content_tag(:i, '', class: "fa fa-#{opts[:icon]} fa-fw", 'data-toggle': 'tooltip', 'data-placement': 'right', 'data-boundary': 'window', title: text) + + content_tag(:span, text) + end - raw content + raw content + end end def admin_sidebar_controller diff --git a/app/jobs/migrate_remote_repository_job.rb b/app/jobs/migrate_remote_repository_job.rb index 1d6e41128..144d9a084 100644 --- a/app/jobs/migrate_remote_repository_job.rb +++ b/app/jobs/migrate_remote_repository_job.rb @@ -10,7 +10,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob gitea_repository = Gitea::Repository::MigrateService.new(token, params).call puts "#gitea_repository#{gitea_repository}" if gitea_repository[0]==201 - repo&.project&.update_columns(gpid: gitea_repository[2]["id"]) + repo&.project&.update_columns(gpid: gitea_repository[2]["id"], default_branch: gitea_repository[2]["default_branch"]) repo&.mirror&.succeeded! ## open jianmu devops project_id = repo&.project&.id @@ -24,7 +24,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob repo&.mirror&.failed! repo&.project&.update_columns(status: 0) else - repo&.project&.update_columns(gpid: gitea_result["id"]) + repo&.project&.update_columns(gpid: gitea_repository[2]["id"], default_branch: gitea_repository[2]["default_branch"]) repo&.mirror&.succeeded! project_id = repo&.project&.id puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############" diff --git a/app/models/user.rb b/app/models/user.rb index 9d623f949..933300c70 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -833,7 +833,11 @@ class User < Owner end def admin_or_business? - admin? || business? + admin? || business? + end + + def admin_or_glcc_admin? + admin? || glcc_admin? end def self.generate_login(prefix) diff --git a/app/services/admins/update_user_service.rb b/app/services/admins/update_user_service.rb index 4dd80b9d0..2d58b000f 100644 --- a/app/services/admins/update_user_service.rb +++ b/app/services/admins/update_user_service.rb @@ -31,7 +31,7 @@ class Admins::UpdateUserService < ApplicationService private def user_attributes - params.slice(*%i[lastname nickname mail phone admin business is_test login + params.slice(*%i[lastname nickname mail phone admin business glcc_admin is_test login professional_certification authentication is_shixun_marker website_permission]) end diff --git a/app/services/repositories/create_service.rb b/app/services/repositories/create_service.rb index 800d5f420..38b2e2cd9 100644 --- a/app/services/repositories/create_service.rb +++ b/app/services/repositories/create_service.rb @@ -38,18 +38,27 @@ class Repositories::CreateService < ApplicationService private def create_gitea_repository - if project.owner.is_a?(User) - # @gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call - @gitea_repository = $gitea_client.post_user_repos({query: {token: user.gitea_token}, body: gitea_repository_params.to_json}) - elsif project.owner.is_a?(Organization) - # @gitea_repository = Gitea::Organization::Repository::CreateService.call(user.gitea_token, project.owner.login, gitea_repository_params) - @gitea_repository = $gitea_client.post_orgs_repos_by_org(project.owner.login, {query: {token: user.gitea_token}, body: gitea_repository_params.to_json}) + begin + @gitea_repository = $gitea_client.get_repos_by_owner_repo(project.owner.login, params[:identifier]) + rescue Gitea::Api::ServerError => e + if e.http_code.to_i == 404 + if project.owner.is_a?(User) + # @gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call + @gitea_repository = $gitea_client.post_user_repos({query: {token: user.gitea_token}, body: gitea_repository_params.to_json}) + elsif project.owner.is_a?(Organization) + # @gitea_repository = Gitea::Organization::Repository::CreateService.call(user.gitea_token, project.owner.login, gitea_repository_params) + @gitea_repository = $gitea_client.post_orgs_repos_by_org(project.owner.login, {query: {token: user.gitea_token}, body: gitea_repository_params.to_json}) + end + else + raise "服务器错误,请联系系统管理员!" + end end end def sync_project if gitea_repository project.update_columns( + is_public: !gitea_repository["private"], gpid: gitea_repository["id"], identifier: repository.identifier, default_branch: gitea_repository["default_branch"], @@ -58,7 +67,7 @@ class Repositories::CreateService < ApplicationService end def sync_repository - repository.update_columns(url: remote_repository_url,) if gitea_repository + repository.update_columns(url: remote_repository_url, hidden: gitea_repository["private"]) if gitea_repository end def remote_repository_url diff --git a/app/views/admins/projects_rank/shared/_data_list.html.erb b/app/views/admins/projects_rank/shared/_data_list.html.erb index 1437a27c8..5ba24985b 100644 --- a/app/views/admins/projects_rank/shared/_data_list.html.erb +++ b/app/views/admins/projects_rank/shared/_data_list.html.erb @@ -16,7 +16,7 @@
<% statistics.each_with_index do |item, index| %>