From 7aea481ccf881f4feeba2205736e90289f3b9b58 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Apr 2022 10:24:54 +0800 Subject: [PATCH 1/9] add: glcc_apply_infomations admin navbar --- app/views/admins/shared/_sidebar.html.erb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 055988731..4c6e6de70 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -45,6 +45,11 @@
  • <%= sidebar_item_group('#setting-glcc', 'GLCC配置', icon: 'fire') do %>
  • <%= sidebar_item(admins_topic_glcc_news_index_path, '新闻稿管理', icon: 'edit', controller: 'admins-topic-glcc_news') %>
  • +
  • + <% if EduSetting.get("glcc_apply_informations_admin_url")%> + <%= sidebar_item(EduSetting.get("glcc_apply_informations_admin_url"), '报名列表', icon: 'user', controller: 'root') %> + <% end %> +
  • <% end %>
  • From 8f5bb0e2d9b8c146cb42f8f84e642eb59c5344b5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Apr 2022 10:52:48 +0800 Subject: [PATCH 2/9] fix: organization gitea_token read by associations --- app/models/organization.rb | 4 ++++ app/services/organizations/create_service.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index 40c676e05..56351a415 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -83,6 +83,10 @@ class Organization < Owner after_save :reset_cache_data + def gitea_token + team_users.joins(:team).where(teams: {authorize: "owner"}).take&.user&.gitea_token + end + def reset_cache_data Cache::V2::OwnerCommonService.new(self.id).reset end diff --git a/app/services/organizations/create_service.rb b/app/services/organizations/create_service.rb index a430ed6f4..263779191 100644 --- a/app/services/organizations/create_service.rb +++ b/app/services/organizations/create_service.rb @@ -47,7 +47,7 @@ class Organizations::CreateService < ApplicationService end def create_org_and_extension - @organization = Organization.build(params[:name], params[:nickname], user.gitea_token) + @organization = Organization.build(params[:name], params[:nickname]) org_extension = OrganizationExtension.build(organization.id, description, website, location, repo_admin_change_team_access, visibility, max_repo_creation) From fc3cf01d3f6f730d9ae82b5da0a9ee66164d50ed Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Apr 2022 13:49:08 +0800 Subject: [PATCH 3/9] add: get user image action --- app/controllers/users_controller.rb | 7 +++++++ app/helpers/application_helper.rb | 9 +++++++++ app/views/users/get_user_info.json.jbuilder | 2 +- config/routes.rb | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 00ea926fd..acc826614 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -97,6 +97,13 @@ class UsersController < ApplicationController render_error(-1, '头像修改失败!') end + def get_image + return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) + return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) + + redirect_to Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(@user).to_s + end + def me @user = current_user end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f2a9f93b6..e7f8611e7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -147,6 +147,15 @@ module ApplicationHelper end end + def url_to_avatar_with_platform_url(source) + platform_url = Rails.application.config_for(:configuration)['platform_url'] + if platform_url + return Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(source).to_s + else + return url_to_avatar(source).to_s + end + end + # 主页banner图 def banner_img(source_type) if File.exist?(disk_filename(source_type, "banner")) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 2f96c6969..5fa4df167 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -22,4 +22,4 @@ json.city @user.city json.custom_department @user.custom_department json.description @user.description json.(@user, :show_email, :show_department, :show_location) -json.message_unread_total @message_unread_total +json.message_unread_total @message_unread_total diff --git a/config/routes.rb b/config/routes.rb index 7e280820a..da63dab64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -214,6 +214,7 @@ Rails.application.routes.draw do get :fan_users get :hovercard put :update_image + get :get_image end collection do post :following From 088c617cc12be188a51c5840d82cfbc237e741ce Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 26 Apr 2022 17:15:59 +0800 Subject: [PATCH 4/9] add: name query for branches --- app/controllers/projects_controller.rb | 2 +- app/controllers/pull_requests_controller.rb | 4 ++-- app/controllers/version_releases_controller.rb | 2 +- app/services/branches/list_service.rb | 7 ++++--- .../gitea/repository/branches/list_name_service.rb | 7 ++++--- app/services/gitea/repository/branches/list_service.rb | 7 ++++--- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index be9a93d9f..b14b105b8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -88,7 +88,7 @@ class ProjectsController < ApplicationController return @branches = [] unless @project.forge? # result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier) - result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier) + result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier, params[:name]) @branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result["branch_name"]) : result end diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 189c5c6bf..0ac7a7144 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -29,7 +29,7 @@ class PullRequestsController < ApplicationController end def new - @all_branches = Branches::ListService.call(@owner, @project) + @all_branches = Branches::ListService.call(@owner, @project, params[:branch_name]) @is_fork = @project.forked_from_project_id.present? @projects_names = [{ project_user_login: @owner.try(:login), @@ -50,7 +50,7 @@ class PullRequestsController < ApplicationController end def get_branches - branch_result = Branches::ListService.call(@owner, @project) + branch_result = Branches::ListService.call(@owner, @project, params[:name]) render json: branch_result # return json: branch_result end diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 2d7546a1c..dd59098f7 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -14,7 +14,7 @@ class VersionReleasesController < ApplicationController def new #获取所有的分支 @all_branches = [] - get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @repository.try(:identifier)).call + get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @repository.try(:identifier), params[:branch_name]).call if get_all_branches && get_all_branches.size > 0 get_all_branches.each do |b| @all_branches.push(b["name"]) diff --git a/app/services/branches/list_service.rb b/app/services/branches/list_service.rb index a3b77a7b0..7b47658e3 100644 --- a/app/services/branches/list_service.rb +++ b/app/services/branches/list_service.rb @@ -1,17 +1,18 @@ class Branches::ListService < ApplicationService - attr_reader :user, :project + attr_reader :user, :project, :name - def initialize(user, project) + def initialize(user, project, name=nil) @user = user @project = project + @name = name end def call all_branches = [] user_name = user.try(:show_real_name) identifier = project.repository.try(:identifier) - get_all_branches = Gitea::Repository::Branches::ListService.new(user, identifier).call + get_all_branches = Gitea::Repository::Branches::ListService.new(user, identifier, name).call all_branches = branch_lists(user_name,user.try(:login), identifier, get_all_branches) if get_all_branches && get_all_branches.size > 0 return all_branches end diff --git a/app/services/gitea/repository/branches/list_name_service.rb b/app/services/gitea/repository/branches/list_name_service.rb index 716ee464c..c005c8359 100644 --- a/app/services/gitea/repository/branches/list_name_service.rb +++ b/app/services/gitea/repository/branches/list_name_service.rb @@ -1,9 +1,10 @@ class Gitea::Repository::Branches::ListNameService < Gitea::ClientService - attr_reader :user, :repo + attr_reader :user, :repo, :name - def initialize(user, repo) + def initialize(user, repo, name=nil) @user = user @repo = repo + @name = name end def call @@ -13,7 +14,7 @@ class Gitea::Repository::Branches::ListNameService < Gitea::ClientService private def params - Hash.new.merge(token: user.gitea_token) + Hash.new.merge(token: user.gitea_token, name: name) end def url diff --git a/app/services/gitea/repository/branches/list_service.rb b/app/services/gitea/repository/branches/list_service.rb index f42965098..7722ecd0b 100644 --- a/app/services/gitea/repository/branches/list_service.rb +++ b/app/services/gitea/repository/branches/list_service.rb @@ -1,9 +1,10 @@ class Gitea::Repository::Branches::ListService < Gitea::ClientService - attr_reader :user, :repo + attr_reader :user, :repo, :name - def initialize(user, repo) + def initialize(user, repo, name=nil) @user = user @repo = repo + @name = name end def call @@ -13,7 +14,7 @@ class Gitea::Repository::Branches::ListService < Gitea::ClientService private def params - Hash.new.merge(token: user.gitea_token) + Hash.new.merge(token: user.gitea_token, name: name) end def url From 396ac55429d37e72d56fd505258e9900f2c4f7e7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Apr 2022 10:42:55 +0800 Subject: [PATCH 5/9] add: user super description --- app/controllers/users_controller.rb | 1 + app/models/user.rb | 2 +- app/models/user_extension.rb | 57 +++++++++---------- app/views/users/get_user_info.json.jbuilder | 3 +- app/views/users/show.json.jbuilder | 1 + ...dd_super_description_to_user_extensions.rb | 6 ++ 6 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 db/migrate/20220428015313_add_super_description_to_user_extensions.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index acc826614..532f29ba1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -313,6 +313,7 @@ class UsersController < ApplicationController :occupation, :technical_title, :school_id, :department_id, :province, :city, :custom_department, :identity, :student_id, :description, + :show_super_description, :super_description, :show_email, :show_location, :show_department] ) end diff --git a/app/models/user.rb b/app/models/user.rb index d661ab591..fa940c29e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -187,7 +187,7 @@ class User < Owner attr_accessor :password, :password_confirmation delegate :description, :gender, :department_id, :school_id, :location, :location_city, - :show_email, :show_location, :show_department, + :show_email, :show_location, :show_department, :super_description, :show_super_description, :technical_title, :province, :city, :custom_department, to: :user_extension, allow_nil: true before_save :update_hashed_password, :set_lastname diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index ee208af7e..379243bf8 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -2,35 +2,34 @@ # # Table name: user_extensions # -# id :integer not null, primary key -# user_id :integer not null -# birthday :date -# brief_introduction :string(255) -# gender :integer -# location :string(255) -# occupation :string(255) -# work_experience :integer -# zip_code :integer -# created_at :datetime not null -# updated_at :datetime not null -# technical_title :string(255) -# identity :integer -# student_id :string(255) -# teacher_realname :string(255) -# student_realname :string(255) -# location_city :string(255) -# school_id :integer -# description :string(255) default("") -# department_id :integer -# honor :text(65535) -# edu_background :integer -# edu_entry_year :integer -# province :string(255) -# city :string(255) -# custom_department :string(255) -# show_email :boolean default("0") -# show_location :boolean default("0") -# show_department :boolean default("0") +# id :integer not null, primary key +# user_id :integer not null +# birthday :date +# brief_introduction :string(255) +# gender :integer +# location :string(255) +# occupation :string(255) +# work_experience :integer +# zip_code :integer +# created_at :datetime not null +# updated_at :datetime not null +# technical_title :string(255) +# identity :integer +# student_id :string(255) +# teacher_realname :string(255) +# student_realname :string(255) +# location_city :string(255) +# school_id :integer +# description :string(255) default("") +# department_id :integer +# province :string(255) +# city :string(255) +# custom_department :string(255) +# show_email :boolean default("0") +# show_location :boolean default("0") +# show_department :boolean default("0") +# super_description :text(4294967295) +# show_super_description :boolean # # Indexes # diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 5fa4df167..8fcadb1c8 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -21,5 +21,6 @@ json.province @user.province json.city @user.city json.custom_department @user.custom_department json.description @user.description -json.(@user, :show_email, :show_department, :show_location) +json.super_description @user.super_description +json.(@user, :show_email, :show_department, :show_location, :show_super_description) json.message_unread_total @message_unread_total diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder index 1c9e7793f..f35705ce6 100644 --- a/app/views/users/show.json.jbuilder +++ b/app/views/users/show.json.jbuilder @@ -13,4 +13,5 @@ json.email @user.show_email ? @user.mail : nil json.province @user.show_location ? @user.province : nil json.city @user.show_location ? @user.city : nil json.custom_department @user.show_department ? @user.custom_department : nil +json.super_description @user.show_super_description ? @user.super_description : nil json.description @user.description \ No newline at end of file diff --git a/db/migrate/20220428015313_add_super_description_to_user_extensions.rb b/db/migrate/20220428015313_add_super_description_to_user_extensions.rb new file mode 100644 index 000000000..076516779 --- /dev/null +++ b/db/migrate/20220428015313_add_super_description_to_user_extensions.rb @@ -0,0 +1,6 @@ +class AddSuperDescriptionToUserExtensions < ActiveRecord::Migration[5.2] + def change + add_column :user_extensions, :super_description, :text, :limit => 4294967295 + add_column :user_extensions, :show_super_description, :boolean + end +end From ec3a556a6f31fb162d47db88c88ba0e3f99f2c34 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Apr 2022 11:03:42 +0800 Subject: [PATCH 6/9] fix: default value for show super description --- app/models/user_extension.rb | 2 +- .../20220428015313_add_super_description_to_user_extensions.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index 379243bf8..c1046ac2f 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -29,7 +29,7 @@ # show_location :boolean default("0") # show_department :boolean default("0") # super_description :text(4294967295) -# show_super_description :boolean +# show_super_description :boolean default("0") # # Indexes # diff --git a/db/migrate/20220428015313_add_super_description_to_user_extensions.rb b/db/migrate/20220428015313_add_super_description_to_user_extensions.rb index 076516779..3e00416e9 100644 --- a/db/migrate/20220428015313_add_super_description_to_user_extensions.rb +++ b/db/migrate/20220428015313_add_super_description_to_user_extensions.rb @@ -1,6 +1,6 @@ class AddSuperDescriptionToUserExtensions < ActiveRecord::Migration[5.2] def change add_column :user_extensions, :super_description, :text, :limit => 4294967295 - add_column :user_extensions, :show_super_description, :boolean + add_column :user_extensions, :show_super_description, :boolean, default: false end end From 3abd6037d99e16931f6ad44ece25d004ec28cf9e Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Apr 2022 11:12:16 +0800 Subject: [PATCH 7/9] fix: show super description aways desplay --- app/views/users/show.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder index f35705ce6..dfeb45cfe 100644 --- a/app/views/users/show.json.jbuilder +++ b/app/views/users/show.json.jbuilder @@ -14,4 +14,5 @@ json.province @user.show_location ? @user.province : nil json.city @user.show_location ? @user.city : nil json.custom_department @user.show_department ? @user.custom_department : nil json.super_description @user.show_super_description ? @user.super_description : nil +json.show_super_description @user.show_super_description json.description @user.description \ No newline at end of file From f15cd44dff87a2df8072133140fa7f2c787a4c13 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Apr 2022 18:53:33 +0800 Subject: [PATCH 8/9] add: compare add paginate --- app/controllers/compare_controller.rb | 12 ++++++++++++ app/helpers/repositories_helper.rb | 1 - app/views/compare/show.json.jbuilder | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb index 382e7506e..1aab7adbe 100644 --- a/app/controllers/compare_controller.rb +++ b/app/controllers/compare_controller.rb @@ -9,6 +9,10 @@ class CompareController < ApplicationController load_compare_params compare @merge_status, @merge_message = get_merge_message + @page_size = page_size <= 0 ? 1 : page_size + @page_limit = page_limit <=0 ? 15 : page_limit + @page_offset = (@page_size -1) * @page_limit + Rails.logger.info("+========#{@page_size}-#{@page_limit}-#{@page_offset}") end private @@ -53,4 +57,12 @@ class CompareController < ApplicationController def gitea_compare(base, head) Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, Addressable::URI.escape(base), Addressable::URI.escape(head), current_user.gitea_token) end + + def page_size + params.fetch(:page, 1).to_i + end + + def page_limit + params.fetch(:limit, 15).to_i + end end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index e6e7e87f8..b8bfc31cd 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -36,7 +36,6 @@ module RepositoriesHelper end def render_cache_commit_author(author_json) - Rails.logger.info author_json['Email'] if author_json["name"].present? && author_json["email"].present? return find_user_in_redis_cache(author_json['name'], author_json['email']) end diff --git a/app/views/compare/show.json.jbuilder b/app/views/compare/show.json.jbuilder index deca41037..26a7cb769 100644 --- a/app/views/compare/show.json.jbuilder +++ b/app/views/compare/show.json.jbuilder @@ -1,7 +1,7 @@ -json.commits_count @compare_result['Commits']&.size +json.commits_count @compare_result['CommitsCount'] # json.commits @compare_result['Commits'], partial: 'pull_requests/commit', as: :commit json.commits do - json.array! @compare_result['Commits'] do |commit| + json.array! @compare_result['Commits'][@page_offset...(@page_offset + @page_limit)] do |commit| json.author do json.partial! 'repositories/commit_author', locals: { user: render_cache_commit_author(commit['Committer']), name: commit['Committer']['Name'] } end From 7c88ea3d6713065f29421d025288947a5194b11b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 5 May 2022 10:00:02 +0800 Subject: [PATCH 9/9] add: quit repo --- app/controllers/projects_controller.rb | 21 ++++++++++++++++++++- config/routes.rb | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b14b105b8..c4e440aff 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -13,6 +13,8 @@ class ProjectsController < ApplicationController def menu_list menu = [] + user_is_admin = current_user.admin? || @project.manager?(current_user) + menu.append(menu_hash_by_name("home")) menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code") menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues") @@ -22,7 +24,8 @@ class ProjectsController < ApplicationController menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") && @project.forge? menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") && @project.forge? menu.append(menu_hash_by_name("activity")) - menu.append(menu_hash_by_name("settings")) if (current_user.admin? || @project.manager?(current_user)) && @project.forge? + menu.append(menu_hash_by_name("settings")) if user_is_admin && @project.forge? + menu.append(menu_hash_by_name("quit")) if !user_is_admin && @project.member(current_user.id) && @project.forge? render json: menu end @@ -177,6 +180,22 @@ class ProjectsController < ApplicationController tip_exception(e.message) end + def quit + user_is_admin = current_user.admin? || @project.manager?(current_user) + if !user_is_admin && @project.member(current_user.id) && @project.forge? + ActiveRecord::Base.transaction do + Projects::DeleteMemberInteractor.call(@project.owner, @project, current_user) + SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, current_user.id, @project.id) if Site.has_notice_menu? + render_ok + end + else + render_forbidden('你不能退出该仓库') + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end + def watch_users watchers = @project.watchers.includes(:user).order("watchers.created_at desc").distinct @watchers_count = watchers.size diff --git a/config/routes.rb b/config/routes.rb index da63dab64..01ff4fa3c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -436,6 +436,7 @@ Rails.application.routes.draw do get :stargazers, to: 'projects#praise_users' get :forks, to: 'projects#fork_users' match :about, :via => [:get, :put, :post] + post :quit end end