From 9c11cd79e8e1a8516a420052d853a5b67a25f020 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 10 Oct 2022 19:06:47 +0800 Subject: [PATCH 01/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=A8=A1=E7=89=88=E6=97=A0=E6=B3=95=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AD=90=E7=B1=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/message_template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/message_template.rb b/app/models/message_template.rb index bc6c5a714..d9ba3eb76 100644 --- a/app/models/message_template.rb +++ b/app/models/message_template.rb @@ -13,7 +13,7 @@ # class MessageTemplate < ApplicationRecord - self.inheritance_column = nil + # self.inheritance_column = nil PLATFORM = 'GitLink' def self.build_init_data From 83f1263f8500e5ead4edbe101bc15285ecd2bd40 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 14 Oct 2022 14:52:25 +0800 Subject: [PATCH 02/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E6=9F=A5=E8=AF=A2=E9=A1=B9=E7=9B=AE=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8dacc7bb9..5714c520b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -709,9 +709,15 @@ class ApplicationController < ActionController::Base # @project = nil if !@project.is_public? # render_forbidden and return else - logger.info "###########:project not found" - @project = nil - render_not_found and return + if @project.present? + logger.info "###########: has project and but can't read project" + @project = nil + render_forbidden and return + else + logger.info "###########:project not found" + @project = nil + render_not_found and return + end end @project end From 6383384287334d6973fc3edc83f6e1ab01218384 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 14 Oct 2022 15:31:20 +0800 Subject: [PATCH 03/38] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86=E7=94=A8=E6=88=B7=E7=9C=9F=E5=AE=9E?= =?UTF-8?q?=E5=A7=93=E5=90=8D=E6=94=B9=E4=B8=BA=E6=98=B5=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/users/shared/_user_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admins/users/shared/_user_list.html.erb b/app/views/admins/users/shared/_user_list.html.erb index ae4657b5e..16cd403de 100644 --- a/app/views/admins/users/shared/_user_list.html.erb +++ b/app/views/admins/users/shared/_user_list.html.erb @@ -2,7 +2,7 @@ 序号 - 真实姓名 + 昵称 邮件地址 手机号码 角色 From 630a7aadeb8f8681155b316ff8575627f9ac1098 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 15 Oct 2022 11:29:23 +0800 Subject: [PATCH 04/38] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E6=95=B0=E6=8D=AE=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/team.rb | 11 +++++++++++ lib/tasks/sync_data_to_gitea.rake | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/app/models/team.rb b/app/models/team.rb index b831cd069..eacb96a0d 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -70,4 +70,15 @@ class Team < ApplicationRecord end end + + def to_gitea_hash + { + can_create_org_repo: self.can_create_org_project, + description: self.description || "", + includes_all_repositories: self.includes_all_project, + name: self.name, + permission: self.authorize, + units: self.team_units.pluck(:unit_type).map{|i| "repo.#{i}"} + } + end end diff --git a/lib/tasks/sync_data_to_gitea.rake b/lib/tasks/sync_data_to_gitea.rake index 85df9c69a..8b8dd0ab0 100644 --- a/lib/tasks/sync_data_to_gitea.rake +++ b/lib/tasks/sync_data_to_gitea.rake @@ -4,6 +4,35 @@ desc "初始化数据同步到gitea平台" # 再同步项目及项目成员 namespace :sync_data_to_gitea do + desc "同步组织数据" + # 同步组织成员,并仅保留最高权限 + task organizations: :environment do + Organization.includes(:organization_users, teams: [:team_users, :team_projects]).find_each do |org| + ActiveRecord::Base.transaction do + org.teams.each do |team| + if team.gtid.blank? + gteam = $gitea_client.post_orgs_teams_by_org(org.login, {body: team.to_gitea_hash.to_json}) rescue nil + team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil? + end + team.team_users.each do |teamuser| + userlogin = teamuser&.user&.login + next if ($gitea_client.get_teams_members_by_id_username(team.gtid, userlogin) rescue nil) + tu_result = $gitea_client.put_teams_members_by_id_username(team.gtid, userlogin) rescue nil + raise ActiveRecord::Rollback if tu_result.nil? + end + team.team_projects.each do |teamp| + tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, org.login, teamp&.project.identifier) rescue nil + raise ActiveRecord::Rollback if tp_result.nil? + end + end + org.organization_users.each do |user| + next if ($gitea_client.get_orgs_members_by_org_username(org.login, user.login) rescue nil) + user.destroy! + end + end + end + end + desc "同步用户" task users: :environment do users = User.where.not(mail: [nil, ""], type: 'Anonymous').or(User.where.not(login: [nil, ""])).distinct From 620ddff9bb66854f1dfca9c35d75f0bc521da693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Mon, 17 Oct 2022 10:13:30 +0800 Subject: [PATCH 05/38] =?UTF-8?q?fixed=20issue=E8=AF=84=E8=AE=BA=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 522 +++++++++++----------- 1 file changed, 261 insertions(+), 261 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 79047b516..22af22831 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -1,261 +1,261 @@ -#coding=utf-8 -# -# 文件上传 -class AttachmentsController < ApplicationController - before_action :require_login, :check_auth, except: [:show, :preview_attachment, :get_file] - before_action :find_file, only: %i[show destroy] - before_action :attachment_candown, only: [:show] - skip_before_action :check_sign, only: [:show, :create] - - include ApplicationHelper - - def show - # 1. 优先跳到cdn - # 2. 如果没有cdn,send_file - if @file.cloud_url.present? - update_downloads(@file) - redirect_to @file.cloud_url and return - end - - type_attachment = params[:disposition] || "attachment" - if type_attachment == "inline" - send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf' - elsif type_attachment == "MP4" - send_file_with_range absolute_path(local_path(@file)), disposition: 'inline', type: "video/mp4", range: true - else - send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream') - end - update_downloads(@file) - end - - - def get_file - normal_status(-1, "参数缺失") if params[:download_url].blank? - url = URI.encode(params[:download_url].to_s.gsub("http:", "https:")) - if url.starts_with?(base_url) - domain = GiteaService.gitea_config[:domain] - api_url = GiteaService.gitea_config[:base_url] - url = url.split(base_url)[1].gsub("api", "repos").gsub('?filepath=', '/').gsub('&', '?') - request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join - response = Faraday.get(request_url) - filename = url.to_s.split("/").pop() - else - response = Faraday.get(url) - filename = params[:download_url].to_s.split("/").pop() - end - send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment') - end - - def create - # 1. 本地存储 - # 2. 上传到云 - begin - upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称 - uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}") - raise "未上传文件" unless upload_file - - folder = file_storage_directory - raise "存储目录未定义" unless folder.present? - - month_folder = current_month_folder - save_path = File.join(folder, month_folder) - - ext = file_ext(upload_file.original_filename) - - local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) - - content_type = upload_file.content_type.presence || 'application/octet-stream' - - # remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) - remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端 - - logger.info "local_path: #{local_path}" - logger.info "remote_path: #{remote_path}" - - - disk_filename = local_path[save_path.size + 1, local_path.size] - #存数据库 - # - @attachment = Attachment.where(disk_filename: disk_filename, - author_id: current_user.id, - cloud_url: remote_path).first - if @attachment.blank? - @attachment = Attachment.new - @attachment.filename = upload_file.original_filename - @attachment.disk_filename = local_path[save_path.size + 1, local_path.size] - @attachment.filesize = upload_file.tempfile.size - @attachment.content_type = content_type - @attachment.digest = digest - @attachment.author_id = current_user.id - @attachment.disk_directory = month_folder - @attachment.cloud_url = remote_path - @attachment.save! - else - logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" - end - - render_json - rescue => e - uid_logger_error(e.message) - tip_exception(e.message) - end - end - - def destroy - begin - @file_path = absolute_path(local_path(@file)) - #return normal_status(403, "") unless @file.author == current_user - @file.destroy! - - delete_file(@file_path) - normal_status("删除成功") - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end - - # 附件为视频时,点击播放 - def preview_attachment - attachment = Attachment.find_by(id: params[:id]) - dir_path = "#{Rails.root}/public/preview" - Dir.mkdir(dir_path) unless Dir.exist?(dir_path) - if params[:status] == "preview" - if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/") - render json: {status: 1, url: "/preview/#{attachment.disk_filename}"} - else - normal_status(-1, "出现错误,请稍后重试") - end - else - if system("rm -rf #{dir_path}/#{attachment.disk_filename}") - normal_status(1, "操作成功") - else - normal_status(-1, "出现错误,请稍后重试") - end - end - end - - private - def find_file - @file = - if params[:type] == 'history' - AttachmentHistory.find params[:id] - else - Attachment.find params[:id] - end - end - - def delete_file(file_path) - File.delete(file_path) if File.exist?(file_path) - end - - def current_month_folder - date = Time.now - "#{date.year}/#{date.month.to_s.rjust(2, '0')}" - end - - def file_ext(file_name) - ext = '' - exts = file_name.split(".") - if exts.size > 1 - ext = ".#{exts.last}" - end - ext - end - - def file_save_to_local(save_path, temp_file, ext) - unless Dir.exists?(save_path) - FileUtils.mkdir_p(save_path) ##不成功这里会抛异常 - end - - digest = md5_file(temp_file) - digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}" - local_file_path = File.join(save_path, digest) + ext - save_temp_file(temp_file, local_file_path) - - [local_file_path, digest] - end - - def save_temp_file(temp_file, save_file_path) - File.open(save_file_path, 'wb') do |f| - temp_file.rewind - while (buffer = temp_file.read(8192)) - f.write(buffer) - end - end - end - - def md5_file(temp_file) - md5 = Digest::MD5.new - temp_file.rewind - while (buffer = temp_file.read(8192)) - md5.update(buffer) - end - md5.hexdigest - end - - def file_save_to_ucloud(path, file, content_type) - ufile = Gitlink::Ufile.new( - ucloud_public_key: edu_setting('public_key'), - ucloud_private_key: edu_setting('private_key'), - ucloud_public_read: true, - ucloud_public_bucket: edu_setting('public_bucket'), - ucloud_public_bucket_host: edu_setting('public_bucket_host'), - ucloud_public_cdn_host: edu_setting('public_cdn_host'), - ) - File.open(file) do |f| - ufile.put(path, f, 'Content-Type' => content_type) - end - edu_setting('public_cdn_host') + "/" + path - end - - def attachment_candown - unless current_user.admin? || current_user.business? - candown = true - unless params[:type] == 'history' - if @file.container && current_user.logged? - if @file.container.is_a?(Issue) - course = @file.container.project - candown = course.member?(current_user) || course.is_public - elsif @file.container.is_a?(Journal) - course = @file.container.issue.project - candown = course.member?(current_user) - else - course = nil - end - tip_exception(403, "您没有权限进入") if course.present? && !candown - tip_exception(403, "您没有权限进入") if @file.container.is_a?(ApplyUserAuthentication) - end - end - end - end - - def send_file_with_range(path, options = {}) - logger.info("########request.headers: #{request.headers}") - logger.info("########request.headers: #{File.exist?(path)}") - - if File.exist?(path) - size = File.size(path) - logger.info("########request.headers: #{request.headers}") - if !request.headers["Range"] - status_code = 200 # 200 OK - offset = 0 - length = File.size(path) - else - status_code = 206 # 206 Partial Content - bytes = Rack::Utils.byte_ranges(request.headers, size)[0] - offset = bytes.begin - length = bytes.end - bytes.begin - end - response.header["Accept-Ranges"] = "bytes" - response.header["Content-Range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}" if bytes - response.header["status"] = status_code - - send_data IO.binread(path, length, offset), options - else - raise ActionController::MissingFile, "Cannot read file #{path}." - end - end - -end +#coding=utf-8 +# +# 文件上传 +class AttachmentsController < ApplicationController + before_action :require_login, :check_auth, except: [:show, :preview_attachment, :get_file] + before_action :find_file, only: %i[show destroy] + before_action :attachment_candown, only: [:show] + skip_before_action :check_sign, only: [:show, :create] + + include ApplicationHelper + + def show + # 1. 优先跳到cdn + # 2. 如果没有cdn,send_file + if @file.cloud_url.present? + update_downloads(@file) + redirect_to @file.cloud_url and return + end + + type_attachment = params[:disposition] || "attachment" + if type_attachment == "inline" + send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf' + elsif type_attachment == "MP4" + send_file_with_range absolute_path(local_path(@file)), disposition: 'inline', type: "video/mp4", range: true + else + send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream') + end + update_downloads(@file) + end + + + def get_file + normal_status(-1, "参数缺失") if params[:download_url].blank? + url = URI.encode(params[:download_url].to_s.gsub("http:", "https:")) + if url.starts_with?(base_url) + domain = GiteaService.gitea_config[:domain] + api_url = GiteaService.gitea_config[:base_url] + url = url.split(base_url)[1].gsub("api", "repos").gsub('?filepath=', '/').gsub('&', '?') + request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join + response = Faraday.get(request_url) + filename = url.to_s.split("/").pop() + else + response = Faraday.get(url) + filename = params[:download_url].to_s.split("/").pop() + end + send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment') + end + + def create + # 1. 本地存储 + # 2. 上传到云 + begin + upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称 + uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}") + raise "未上传文件" unless upload_file + + folder = file_storage_directory + raise "存储目录未定义" unless folder.present? + + month_folder = current_month_folder + save_path = File.join(folder, month_folder) + + ext = file_ext(upload_file.original_filename) + + local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) + + content_type = upload_file.content_type.presence || 'application/octet-stream' + + # remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) + remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端 + + logger.info "local_path: #{local_path}" + logger.info "remote_path: #{remote_path}" + + + disk_filename = local_path[save_path.size + 1, local_path.size] + #存数据库 + # + @attachment = Attachment.where(disk_filename: disk_filename, + author_id: current_user.id, + cloud_url: remote_path).first + if @attachment.blank? + @attachment = Attachment.new + @attachment.filename = upload_file.original_filename + @attachment.disk_filename = local_path[save_path.size + 1, local_path.size] + @attachment.filesize = upload_file.tempfile.size + @attachment.content_type = content_type + @attachment.digest = digest + @attachment.author_id = current_user.id + @attachment.disk_directory = month_folder + @attachment.cloud_url = remote_path + @attachment.save! + else + logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" + end + + render_json + rescue => e + uid_logger_error(e.message) + tip_exception(e.message) + end + end + + def destroy + begin + @file_path = absolute_path(local_path(@file)) + #return normal_status(403, "") unless @file.author == current_user + @file.destroy! + + delete_file(@file_path) + normal_status("删除成功") + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback + end + end + + # 附件为视频时,点击播放 + def preview_attachment + attachment = Attachment.find_by(id: params[:id]) + dir_path = "#{Rails.root}/public/preview" + Dir.mkdir(dir_path) unless Dir.exist?(dir_path) + if params[:status] == "preview" + if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/") + render json: {status: 1, url: "/preview/#{attachment.disk_filename}"} + else + normal_status(-1, "出现错误,请稍后重试") + end + else + if system("rm -rf #{dir_path}/#{attachment.disk_filename}") + normal_status(1, "操作成功") + else + normal_status(-1, "出现错误,请稍后重试") + end + end + end + + private + def find_file + @file = + if params[:type] == 'history' + AttachmentHistory.find params[:id] + else + Attachment.find params[:id] + end + end + + def delete_file(file_path) + File.delete(file_path) if File.exist?(file_path) + end + + def current_month_folder + date = Time.now + "#{date.year}/#{date.month.to_s.rjust(2, '0')}" + end + + def file_ext(file_name) + ext = '' + exts = file_name.split(".") + if exts.size > 1 + ext = ".#{exts.last}" + end + ext + end + + def file_save_to_local(save_path, temp_file, ext) + unless Dir.exists?(save_path) + FileUtils.mkdir_p(save_path) ##不成功这里会抛异常 + end + + digest = md5_file(temp_file) + digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}" + local_file_path = File.join(save_path, digest) + ext + save_temp_file(temp_file, local_file_path) + + [local_file_path, digest] + end + + def save_temp_file(temp_file, save_file_path) + File.open(save_file_path, 'wb') do |f| + temp_file.rewind + while (buffer = temp_file.read(8192)) + f.write(buffer) + end + end + end + + def md5_file(temp_file) + md5 = Digest::MD5.new + temp_file.rewind + while (buffer = temp_file.read(8192)) + md5.update(buffer) + end + md5.hexdigest + end + + def file_save_to_ucloud(path, file, content_type) + ufile = Gitlink::Ufile.new( + ucloud_public_key: edu_setting('public_key'), + ucloud_private_key: edu_setting('private_key'), + ucloud_public_read: true, + ucloud_public_bucket: edu_setting('public_bucket'), + ucloud_public_bucket_host: edu_setting('public_bucket_host'), + ucloud_public_cdn_host: edu_setting('public_cdn_host'), + ) + File.open(file) do |f| + ufile.put(path, f, 'Content-Type' => content_type) + end + edu_setting('public_cdn_host') + "/" + path + end + + def attachment_candown + unless current_user.admin? || current_user.business? + candown = true + unless params[:type] == 'history' + if @file.container && current_user.logged? + if @file.container.is_a?(Issue) + course = @file.container.project + candown = course.member?(current_user) || course.is_public + elsif @file.container.is_a?(Journal) + course = @file.container.issue.project + candown = course.member?(current_user) || course.is_public + else + course = nil + end + tip_exception(403, "您没有权限进入") if course.present? && !candown + tip_exception(403, "您没有权限进入") if @file.container.is_a?(ApplyUserAuthentication) + end + end + end + end + + def send_file_with_range(path, options = {}) + logger.info("########request.headers: #{request.headers}") + logger.info("########request.headers: #{File.exist?(path)}") + + if File.exist?(path) + size = File.size(path) + logger.info("########request.headers: #{request.headers}") + if !request.headers["Range"] + status_code = 200 # 200 OK + offset = 0 + length = File.size(path) + else + status_code = 206 # 206 Partial Content + bytes = Rack::Utils.byte_ranges(request.headers, size)[0] + offset = bytes.begin + length = bytes.end - bytes.begin + end + response.header["Accept-Ranges"] = "bytes" + response.header["Content-Range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}" if bytes + response.header["status"] = status_code + + send_data IO.binread(path, length, offset), options + else + raise ActionController::MissingFile, "Cannot read file #{path}." + end + end + +end From 53fe554d1e0547e77e67712295b69ae70955e5bb Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Oct 2022 10:25:17 +0800 Subject: [PATCH 06/38] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86=E8=A1=A8=E5=A4=B4=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/stylesheets/admin.scss | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index bae77fb29..b52f93702 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -204,4 +204,10 @@ input.form-control { color: #23272B; font-size: 1rem; } +} + +.table th, .table td { + padding: 0.75rem 0.1rem; + vertical-align: top; + border-top: 1px solid #dee2e6; } \ No newline at end of file From 8d41c270448856034ae0591c5356268a36026189 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Oct 2022 10:42:40 +0800 Subject: [PATCH 07/38] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=88=90=E5=91=98=E6=B7=BB=E5=8A=A0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/members_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 5c8ed963e..92eb68f35 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -65,13 +65,13 @@ class MembersController < ApplicationController def check_member_exists! @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take - return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) + return render_error("#{@user&.nickname}已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) end def check_member_not_exists! @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take return render_error("用户为组织成员,请到组织下操作!") if (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) && !member_exists? - return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists? + return render_error("#{@user&.nickname}还不是项目成员") unless member_exists? end def check_user_profile_completed From 8807be6e4d1e1c4e238467a8bb29996d9dd5d76f Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Oct 2022 10:52:57 +0800 Subject: [PATCH 08/38] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=AF=AD=E8=A8=80=E6=96=B0=E5=A2=9E=E5=94=AF=E4=B8=80?= =?UTF-8?q?=E6=80=A7=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/project_languages_controller.rb | 7 ++++--- app/models/project_language.rb | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/admins/project_languages_controller.rb b/app/controllers/admins/project_languages_controller.rb index 0f26f25bb..69594eb50 100644 --- a/app/controllers/admins/project_languages_controller.rb +++ b/app/controllers/admins/project_languages_controller.rb @@ -27,17 +27,18 @@ class Admins::ProjectLanguagesController < Admins::BaseController flash[:success] = '创建成功' else redirect_to admins_project_languages_path - flash[:danger] = '创建失败' + flash[:danger] = @project_language.errors.full_messages.join(",") end end def update - if @project_language.update_attribute(:name, @name) + @project_language.attributes = {name: @name} + if @project_language.save redirect_to admins_project_languages_path flash[:success] = '更新成功' else redirect_to admins_project_languages_path - flash[:success] = '更新失败' + flash[:danger] = @project_language.errors.full_messages.join(",") end end diff --git a/app/models/project_language.rb b/app/models/project_language.rb index ced6c5f9e..09b0b80f2 100644 --- a/app/models/project_language.rb +++ b/app/models/project_language.rb @@ -12,4 +12,6 @@ class ProjectLanguage < ApplicationRecord include Projectable + + validates :name, uniqueness: true end From dd1af6712ccc435f389cd27630be59db54413158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Mon, 17 Oct 2022 11:08:54 +0800 Subject: [PATCH 09/38] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AE=E6=88=90?= =?UTF-8?q?=E5=91=98=E6=8F=90=E7=A4=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/members_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 5c8ed963e..378f1ae93 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -65,13 +65,13 @@ class MembersController < ApplicationController def check_member_exists! @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take - return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) + return render_error("#{User.find_by(id: params[:user_id]).try(:login)}已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) end def check_member_not_exists! @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take return render_error("用户为组织成员,请到组织下操作!") if (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) && !member_exists? - return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists? + return render_error("#{User.find_by(id: params[:user_id]).try(:login)}还不是项目成员") unless member_exists? end def check_user_profile_completed From 5196f33f24137dc5c21e947a43a3c5c621427aa0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Oct 2022 12:57:24 +0800 Subject: [PATCH 10/38] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=AE=B8=E5=8F=AF=E8=AF=81=E6=96=B0=E5=A2=9E=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/project_licenses_controller.rb | 50 +++++++++---------- app/models/license.rb | 4 ++ config/locales/zh-CN.yml | 3 ++ 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/app/controllers/admins/project_licenses_controller.rb b/app/controllers/admins/project_licenses_controller.rb index 5c16a884b..44ae75118 100644 --- a/app/controllers/admins/project_licenses_controller.rb +++ b/app/controllers/admins/project_licenses_controller.rb @@ -1,6 +1,6 @@ class Admins::ProjectLicensesController < Admins::BaseController before_action :set_license, only: [:edit,:update, :destroy,:show] - before_action :validate_params, only: [:create, :update] + # before_action :validate_params, only: [:create, :update] def index sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' @@ -30,13 +30,12 @@ class Admins::ProjectLicensesController < Admins::BaseController # position: max_position # } @project_license = License.new(license_params) - - if @project_license.save! + if @project_license.save redirect_to admins_project_licenses_path flash[:success] = "创建成功" else - render :new - flash[:danger] = "创建失败" + redirect_to admins_project_licenses_path + flash[:danger] = @project_license.errors.full_messages.join(",") end end @@ -54,12 +53,13 @@ class Admins::ProjectLicensesController < Admins::BaseController # permissions: permissions.to_s, # limitations: limitations.to_s # } - if @project_license.update_attributes(license_params) + @project_license.attributes = license_params + if @project_license.save redirect_to admins_project_licenses_path flash[:success] = "更新成功" else - render :edit - flash[:danger] = "更新失败" + render admins_project_licenses_path + flash[:danger] = @project_license.errors.full_messages.join(",") end end @@ -98,23 +98,23 @@ class Admins::ProjectLicensesController < Admins::BaseController params.require(:license).permit(:name,:content) end - def validate_params - name = params[:license][:name] - if name.blank? - flash[:danger] = "名称不允许为空" - redirect_to admins_project_licenses_path - elsif check_license_present?(name) && @project_license.blank? - flash[:danger] = "创建失败:名称已存在" - redirect_to admins_project_licenses_path - end - end + # def validate_params + # name = params[:license][:name] + # if name.blank? + # flash[:danger] = "名称不允许为空" + # redirect_to admins_project_licenses_path + # elsif check_license_present?(name) && @project_license.blank? + # flash[:danger] = "创建失败:名称已存在" + # redirect_to admins_project_licenses_path + # end + # end - def check_license_present?(name) - return true if name.blank? - name_downcase = name.downcase - name_upcase = name.upcase - name_first_big = name.capitalize - License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big) - end + # def check_license_present?(name) + # return true if name.blank? + # name_downcase = name.downcase + # name_upcase = name.upcase + # name_first_big = name.capitalize + # License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big) + # end end diff --git a/app/models/license.rb b/app/models/license.rb index 0a14fb85e..676254717 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -11,4 +11,8 @@ class License < ApplicationRecord include Projectable + + validates :content, presence: true + validates :name, uniqueness: true, presence: true + end diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 62ea16966..95b7c429b 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -223,6 +223,9 @@ zh-CN: platform: '直播平台' live_time: '开播时间' duration: '直播时长' + license: + name: '许可证名称' + content: '许可证内容' close_pr: 合并请求 roles: Developer: 开发者 From dcc7ab6738bf69fef2afc5c41a1efe6124fe2906 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Oct 2022 13:01:08 +0800 Subject: [PATCH 11/38] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=86=E7=B1=BB=E5=8E=BB=E6=8E=89=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/project_categories/_form_modal.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/admins/project_categories/_form_modal.html.erb b/app/views/admins/project_categories/_form_modal.html.erb index fc58d3345..3ad6e044c 100644 --- a/app/views/admins/project_categories/_form_modal.html.erb +++ b/app/views/admins/project_categories/_form_modal.html.erb @@ -21,6 +21,7 @@ <%= p.number_field :pinned_index,class: "form-control input-lg",placeholder: "精选等级",required: true%> + <%if false%>
<% logo_img = @project_category.logo_url %>
@@ -34,6 +35,7 @@
尺寸:高度38px以内,宽等比例缩放
+ <% end %> @@ -25,7 +25,7 @@
- <%= f.text_area :content,class:"form-control", rows: "10", cols: "20",placeholer: "忽略文件的简要介绍,不得超过500字" %> + <%= f.text_area :content,class:"form-control", rows: "10", cols: "20",placeholer: "忽略文件的简要介绍,不得超过500字", required: true %>
diff --git a/app/views/admins/project_licenses/_form.html.erb b/app/views/admins/project_licenses/_form.html.erb index 115b67935..c6ec55504 100644 --- a/app/views/admins/project_licenses/_form.html.erb +++ b/app/views/admins/project_licenses/_form.html.erb @@ -13,7 +13,7 @@
- <%= f.text_field :name, class: "form-control input-lg", maxlength: "60", placeholder: "请输入开源许可证的全称" %> + <%= f.text_field :name, class: "form-control input-lg", maxlength: "60", placeholder: "请输入开源许可证的全称", required: true %>
@@ -25,7 +25,7 @@
- <%= f.text_area :content,class:"form-control", rows: "10", cols: "20",placeholer: "许可证的简要介绍,不得超过500字" %> + <%= f.text_area :content,class:"form-control", rows: "10", cols: "20",placeholer: "许可证的简要介绍,不得超过500字", required: true %>
From 35965f542ab1b7bbf7bbbd73ca9a35129a5e29aa Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 18 Oct 2022 13:31:12 +0800 Subject: [PATCH 15/38] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E5=AD=97=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/tags/list_name_service.rb | 23 +++++++++++++++++++ app/views/repositories/tags.json.jbuilder | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/services/gitea/repository/tags/list_name_service.rb diff --git a/app/services/gitea/repository/tags/list_name_service.rb b/app/services/gitea/repository/tags/list_name_service.rb new file mode 100644 index 000000000..0857ca11c --- /dev/null +++ b/app/services/gitea/repository/tags/list_name_service.rb @@ -0,0 +1,23 @@ +class Gitea::Repository::Tags::ListNameService < Gitea::ClientService + attr_reader :user, :repo, :name + + def initialize(user, repo, name=nil) + @user = user + @repo = repo + @name = name + end + + def call + response = get(url, params) + render_200_response(response) + end + + private + def params + Hash.new.merge(token: user.gitea_token, name: name) + end + + def url + "/repos/#{user.login}/#{repo}/tag_name_set".freeze + end +end diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index eaf11058e..b6fa1c491 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -1,5 +1,5 @@ json.array! @tags do |tag| - if tag.present? + if tag.present? && tag.is_a?(Hash) json.name tag['name'] json.id tag['id'] json.zipball_url render_zip_url(@owner, @repository, tag['name']) @@ -22,6 +22,8 @@ json.array! @tags do |tag| json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] end end + else + json.name tag end end From e25231738a0b48b47aa72d449427daa4c21a7212 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 18 Oct 2022 13:32:57 +0800 Subject: [PATCH 16/38] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E5=AD=97=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 5ee1fdde3..9f43d1ace 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -147,9 +147,15 @@ class RepositoriesController < ApplicationController end def tags - result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}) + if params[:only_name].present? + result = Gitea::Repository::Tags::ListNameService.call(@owner, @project.identifier, params[:name]) - @tags = result.is_a?(Hash) && result.key?(:status) ? [] : result + @tags = result.is_a?(Hash) && result.key?(:status) ? [] : result + else + result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}) + + @tags = result.is_a?(Hash) && result.key?(:status) ? [] : result + end end def contributors From 58a43a8b805990e57b46a70810a0db6c94a38c9c Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 18 Oct 2022 13:43:16 +0800 Subject: [PATCH 17/38] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E5=92=8Cissue=E4=BB=85=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=BC=80=E5=90=AF=E4=B8=AD=E7=9A=84=E9=87=8C=E7=A8=8B?= =?UTF-8?q?=E7=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 2 +- app/helpers/tag_chosen_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index c16431461..a9e6ee6a1 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -268,7 +268,7 @@ class PullRequestsController < ApplicationController def get_relatived @project_tags = @project.issue_tags&.select(:id,:name, :color).as_json - @project_versions = @project.versions&.select(:id,:name, :status).as_json + @project_versions = @project.versions.opening&.select(:id,:name, :status).as_json @project_members = @project.all_developers @project_priories = IssuePriority&.select(:id,:name, :position).as_json end diff --git a/app/helpers/tag_chosen_helper.rb b/app/helpers/tag_chosen_helper.rb index dcf3c457c..520b868fa 100644 --- a/app/helpers/tag_chosen_helper.rb +++ b/app/helpers/tag_chosen_helper.rb @@ -123,7 +123,7 @@ module TagChosenHelper cache_key = "project-#{project.id}/all_milestones/size-#{project.versions.size}/#{project.versions.maximum('updated_on')}" Rails.cache.fetch(cache_key) do - project.versions.select(:id, :name, :status).collect do |event| + project.versions.opening.select(:id, :name, :status).collect do |event| { id: event.id, name: event.name, From 3b15dd84fc7fc96d22b31c9caec00f9ccb07fb2d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 18 Oct 2022 14:52:15 +0800 Subject: [PATCH 18/38] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E6=80=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 4 ++++ app/views/repositories/tags.json.jbuilder | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9f43d1ace..e32b31017 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -152,6 +152,10 @@ class RepositoriesController < ApplicationController @tags = result.is_a?(Hash) && result.key?(:status) ? [] : result else + name_result = Gitea::Repository::Tags::ListNameService.call(@owner, @project.identifier, params[:name]) + + @tag_names = result.is_a?(Hash) && result.key?(:status) ? [] : name_result + result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}) @tags = result.is_a?(Hash) && result.key?(:status) ? [] : result diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index b6fa1c491..4f5bb4330 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -1,4 +1,5 @@ -json.array! @tags do |tag| +json.total_count @tag_names.present? ? @tag_names.count : @tags.count +json.tags @tags do |tag| if tag.present? && tag.is_a?(Hash) json.name tag['name'] json.id tag['id'] From cad7e242995c0701a40f3faf794f29e35fc087f4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 18 Oct 2022 15:53:37 +0800 Subject: [PATCH 19/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E8=A1=A8=E5=A4=B4=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/stylesheets/admin.scss | 4 ++++ app/views/admins/projects/shared/_list.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index b52f93702..8719d767e 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -210,4 +210,8 @@ input.form-control { padding: 0.75rem 0.1rem; vertical-align: top; border-top: 1px solid #dee2e6; +} + +.table .thead-light th{ + white-space: nowrap; } \ No newline at end of file diff --git a/app/views/admins/projects/shared/_list.html.erb b/app/views/admins/projects/shared/_list.html.erb index c2d300c2d..720b08dac 100644 --- a/app/views/admins/projects/shared/_list.html.erb +++ b/app/views/admins/projects/shared/_list.html.erb @@ -14,7 +14,7 @@ 成员 管理员 <%= sort_tag('创建时间', name: 'created_on', path: admins_projects_path) %> - 操作 + 操作 From 64d9c334ce8ad8de842e237f84f92193666ead09 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 19 Oct 2022 15:18:15 +0800 Subject: [PATCH 20/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=AF=AD=E8=A8=80=E9=AA=8C=E8=AF=81=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project_language.rb | 2 +- config/locales/zh-CN.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/project_language.rb b/app/models/project_language.rb index 09b0b80f2..0770a1efa 100644 --- a/app/models/project_language.rb +++ b/app/models/project_language.rb @@ -13,5 +13,5 @@ class ProjectLanguage < ApplicationRecord include Projectable - validates :name, uniqueness: true + validates :name, uniqueness: { message: "已存在" } end diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index d1023ce2a..623a4d1c9 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -223,6 +223,8 @@ zh-CN: platform: '直播平台' live_time: '开播时间' duration: '直播时长' + project_language: + name: '项目语言' license: name: '许可证名称' content: '许可证内容' From e9b23d65774773aa91301e35887e470de317bf16 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 19 Oct 2022 16:17:44 +0800 Subject: [PATCH 21/38] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E4=BB=A3=E7=A0=81=E5=86=B2=E7=AA=81?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=AF=AD=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/pull_requests/merge_service.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/services/pull_requests/merge_service.rb b/app/services/pull_requests/merge_service.rb index 463412120..cffaebd8b 100644 --- a/app/services/pull_requests/merge_service.rb +++ b/app/services/pull_requests/merge_service.rb @@ -24,6 +24,9 @@ class PullRequests::MergeService < ApplicationService result = Gitea::PullRequest::MergeService.call(@current_user.gitea_token, @owner.login, @repo.identifier, @pull.gitea_number, gitea_merge_pull_params) @status, @message = result + if @status.to_i == 409 + @message = "代码冲突,请重新提交合并请求" + end end def gitea_merge_pull_params From 0a5dd2f1ee0278f9a219d838d76501a1234c3e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Fri, 21 Oct 2022 09:42:21 +0800 Subject: [PATCH 22/38] =?UTF-8?q?ssh=E5=85=AC=E9=92=A5=E5=85=81=E8=AE=B8to?= =?UTF-8?q?ken=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 8 ++++++++ app/controllers/public_keys_controller.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 22895b114..7619a39e1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -173,6 +173,14 @@ class ApplicationController < ActionController::Base tip_exception(401, "请登录后再操作") unless User.current.logged? end + def require_login_or_token + if params[:token].present? + user = User.try_to_autologin(params[:token]) + User.current = user + end + tip_exception(401, "请登录后再操作") unless User.current.logged? + end + def require_profile_completed tip_exception(411, "请完善资料后再操作") unless User.current.profile_is_completed? end diff --git a/app/controllers/public_keys_controller.rb b/app/controllers/public_keys_controller.rb index 327e719cc..0e18e3e09 100644 --- a/app/controllers/public_keys_controller.rb +++ b/app/controllers/public_keys_controller.rb @@ -1,5 +1,5 @@ class PublicKeysController < ApplicationController - before_action :require_login + before_action :require_login_or_token before_action :find_public_key, only: [:destroy] def index From 9ee4c85b7c4b8366faae5a84ddf8afe233ff6273 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Oct 2022 14:31:32 +0800 Subject: [PATCH 23/38] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=BF=94=E5=9B=9Estatus=E4=BB=A5=E5=8F=8A=E4=B8=87?= =?UTF-8?q?=E8=83=BD=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects_controller.rb | 1 - app/controllers/api/v1/users_controller.rb | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index bc51362ae..810c40171 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -15,6 +15,5 @@ class Api::V1::ProjectsController < Api::V1::BaseController def blame @result_object = Api::V1::Projects::BlameService.call(@project, params[:sha], params[:filepath], current_user&.gitea_token) - puts @result_object end end \ No newline at end of file diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 37a41ff75..ad8e790da 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -16,9 +16,9 @@ class Api::V1::UsersController < Api::V1::BaseController # 60s内不能重复发送 send_email_limit_cache_key = "send_email_60_second_limit:#{mail}" - tip_exception(-1, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key) + tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key) send_email_control = LimitForbidControl::SendEmailCode.new(mail) - tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid? + tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid? begin UserMailer.update_email(mail, verification_code).deliver_now @@ -39,17 +39,17 @@ class Api::V1::UsersController < Api::V1::BaseController def check_password password = params[:password] - return render_error("8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD - return render_error("密码错误") unless @observe_user.check_password?(password) + return render_error(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD + return render_error(-5, "密码错误") unless @observe_user.check_password?(password) render_ok end def check_email mail = strip(params[:email]) - return render_error("邮件格式有误") unless mail =~ CustomRegexp::EMAIL + return render_error(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL exist_owner = Owner.find_by(mail: mail) - return render_error('邮箱已被使用') if exist_owner + return render_error(-2, '邮箱已被使用') if exist_owner render_ok end @@ -58,12 +58,13 @@ class Api::V1::UsersController < Api::V1::BaseController mail = strip(params[:email]) code_type = params[:code_type] - return render_error("邮件格式有误") unless mail =~ CustomRegexp::EMAIL + return render_error(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL verifi_code = VerificationCode.where(email: mail, code: code, code_type: code_type).last + return render_ok if code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试 - return render_error("验证码不正确") if verifi_code&.code != code - return render_error("验证码已失效") if !verifi_code&.effective? + return render_error(-6, "验证码不正确") if verifi_code&.code != code + return render_error(-6, "验证码已失效") if !verifi_code&.effective? render_ok end From 8a33ea6707a366893f2c81b8ed3ffb717173ac7a Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Oct 2022 14:40:43 +0800 Subject: [PATCH 24/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/users/update_email_service.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index e11dd2f61..2d7631cc2 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -20,8 +20,10 @@ class Api::V1::Users::UpdateEmailService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? raise Error, "密码不正确." unless @user.check_password?(@password) - raise Error, "验证码不正确." if @verify_code&.code != @code - raise Error, "验证码已失效." if !@verify_code&.effective? + if !(code == "123123" && EduSetting.get("code_debug")) # 万能验证码,用于测试 # TODO 万能验证码,用于测试 + raise Error, "验证码不正确." if @verify_code&.code != @code + raise Error, "验证码已失效." if !@verify_code&.effective? + end # begin ActiveRecord::Base.transaction do From c2ef23b746a2f45618d94e87a6009b407657fcaa Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Oct 2022 14:42:51 +0800 Subject: [PATCH 25/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/users/update_email_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index 2d7631cc2..d53928341 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -20,7 +20,7 @@ class Api::V1::Users::UpdateEmailService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? raise Error, "密码不正确." unless @user.check_password?(@password) - if !(code == "123123" && EduSetting.get("code_debug")) # 万能验证码,用于测试 # TODO 万能验证码,用于测试 + if !(@verify_code == "123123" && EduSetting.get("code_debug")) # 万能验证码,用于测试 # TODO 万能验证码,用于测试 raise Error, "验证码不正确." if @verify_code&.code != @code raise Error, "验证码已失效." if !@verify_code&.effective? end From b80b89e81dfa8c833908edda0f0a48bc8fd167b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Fri, 21 Oct 2022 14:48:33 +0800 Subject: [PATCH 26/38] =?UTF-8?q?fixed=20=E6=94=AF=E6=8C=81refresh=5Ftoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/doorkeeper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index b11b32dea..2a2355c6d 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -361,7 +361,7 @@ Doorkeeper.configure do # https://datatracker.ietf.org/doc/html/rfc6819#section-4.4.3 # # - grant_flows %w[authorization_code client_credentials password] + grant_flows %w[authorization_code client_credentials password refresh_token] # Allows to customize OAuth grant flows that +each+ application support. # You can configure a custom block (or use a class respond to `#call`) that must From 9b880e32099e7c13ef2ea568965b2e1ad20876b7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Oct 2022 15:04:26 +0800 Subject: [PATCH 27/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users_controller.rb | 14 +++++++------- app/services/api/v1/users/update_email_service.rb | 7 +++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index ad8e790da..1babd9bca 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -39,17 +39,17 @@ class Api::V1::UsersController < Api::V1::BaseController def check_password password = params[:password] - return render_error(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD - return render_error(-5, "密码错误") unless @observe_user.check_password?(password) + return tip_exception(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD + return tip_exception(-5, "密码错误") unless @observe_user.check_password?(password) render_ok end def check_email mail = strip(params[:email]) - return render_error(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL + return tip_exception(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL exist_owner = Owner.find_by(mail: mail) - return render_error(-2, '邮箱已被使用') if exist_owner + return tip_exception(-2, '邮箱已被使用') if exist_owner render_ok end @@ -58,13 +58,13 @@ class Api::V1::UsersController < Api::V1::BaseController mail = strip(params[:email]) code_type = params[:code_type] - return render_error(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL + return tip_exception(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL verifi_code = VerificationCode.where(email: mail, code: code, code_type: code_type).last return render_ok if code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试 - return render_error(-6, "验证码不正确") if verifi_code&.code != code - return render_error(-6, "验证码已失效") if !verifi_code&.effective? + return tip_exception(-6, "验证码不正确") if verifi_code&.code != code + return tip_exception(-6, "验证码已失效") if !verifi_code&.effective? render_ok end diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index d53928341..5324ce699 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -20,10 +20,9 @@ class Api::V1::Users::UpdateEmailService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? raise Error, "密码不正确." unless @user.check_password?(@password) - if !(@verify_code == "123123" && EduSetting.get("code_debug")) # 万能验证码,用于测试 # TODO 万能验证码,用于测试 - raise Error, "验证码不正确." if @verify_code&.code != @code - raise Error, "验证码已失效." if !@verify_code&.effective? - end + is_debug = @code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试 + raise Error, "验证码不正确." if @verify_code&.code != @code && !is_debug + raise Error, "验证码已失效." if !@verify_code&.effective? && !is_debug # begin ActiveRecord::Base.transaction do From cfdbc5a68229fd0ec578b7833258e16441462c55 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Oct 2022 15:07:31 +0800 Subject: [PATCH 28/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/users/update_email_service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index 5324ce699..99f990631 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -20,6 +20,8 @@ class Api::V1::Users::UpdateEmailService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? raise Error, "密码不正确." unless @user.check_password?(@password) + exist_owner = Owner.find_by(mail: @mail) + raise Error, "邮箱已被使用." if exist_owner is_debug = @code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试 raise Error, "验证码不正确." if @verify_code&.code != @code && !is_debug raise Error, "验证码已失效." if !@verify_code&.effective? && !is_debug From 3f7366fbcd16a532179f84096aac34bf60330302 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Oct 2022 15:28:48 +0800 Subject: [PATCH 29/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E6=88=B7=E9=80=9A=E7=9F=A5=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E8=87=AA=E5=B7=B1=E6=94=B9=E8=87=AA=E5=B7=B1?= =?UTF-8?q?=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/users/update_email_service.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index 99f990631..d17f101fd 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -26,7 +26,7 @@ class Api::V1::Users::UpdateEmailService < ApplicationService raise Error, "验证码不正确." if @verify_code&.code != @code && !is_debug raise Error, "验证码已失效." if !@verify_code&.effective? && !is_debug - # begin + begin ActiveRecord::Base.transaction do change_user_email excute_data_to_gitea @@ -35,15 +35,15 @@ class Api::V1::Users::UpdateEmailService < ApplicationService return gitea_data - # rescue - # raise Error, "服务器错误,请联系系统管理员!" - # end + rescue + raise Error, "服务器错误,请联系系统管理员!" + end end private def request_params { - access_token: token + access_token: @user.gitea_token } end From 969cbcfe60eaa35bb8a6e614d4cb9420cb251de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Fri, 21 Oct 2022 17:44:02 +0800 Subject: [PATCH 30/38] =?UTF-8?q?fixed=20users/me=E8=BF=94=E5=9B=9Eemail,?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E4=B8=89=E6=96=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/me.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/me.json.jbuilder b/app/views/users/me.json.jbuilder index 925c32e5e..e2d3693ae 100644 --- a/app/views/users/me.json.jbuilder +++ b/app/views/users/me.json.jbuilder @@ -3,3 +3,4 @@ json.login @user.login json.user_id @user.id json.image_url url_to_avatar(@user) json.admin @user.admin +json.email @user.mail From a4c892ec0a1ce4c8b48dfa1e85cbe4ed4d96814b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Tue, 25 Oct 2022 11:19:59 +0800 Subject: [PATCH 31/38] =?UTF-8?q?fixed=20cloudIDE=20saas=E5=AE=9A=E5=88=B6?= =?UTF-8?q?api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 11 +++++++++++ app/controllers/public_keys_controller.rb | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cfff09c2e..eaffdeca0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -181,6 +181,17 @@ class ApplicationController < ActionController::Base tip_exception(401, "请登录后再操作") unless User.current.logged? end + def require_login_cloud_ide_saas + if params[:sign].present? && params[:email].present? + sign = Digest::MD5.hexdigest("#{OPENKEY}#{params[:email]}") + if params[:sign].to_s == sign + user = User.find_by(mail: params[:email]) + User.current = user + end + end + tip_exception(401, "请登录后再操作") unless User.current.logged? + end + def require_profile_completed tip_exception(411, "请完善资料后再操作") unless User.current.profile_is_completed? end diff --git a/app/controllers/public_keys_controller.rb b/app/controllers/public_keys_controller.rb index 0e18e3e09..fa6601178 100644 --- a/app/controllers/public_keys_controller.rb +++ b/app/controllers/public_keys_controller.rb @@ -1,5 +1,5 @@ class PublicKeysController < ApplicationController - before_action :require_login_or_token + before_action :require_login_cloud_ide_saas before_action :find_public_key, only: [:destroy] def index @@ -61,4 +61,6 @@ class PublicKeysController < ApplicationController def find_public_key @public_key = current_user.public_keys.find_by_id(params[:id]) end + + end \ No newline at end of file From 8b14ee3c72b6c810b480792485b771d24b5ad12c Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 26 Oct 2022 14:49:40 +0800 Subject: [PATCH 32/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E7=BB=84=E7=BB=87=E4=B8=8B=E9=A1=B9=E7=9B=AE=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=90=8C=E6=97=B6=E6=9B=B4=E6=94=B9=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E4=B8=8B=E6=9D=83=E9=99=90=E5=90=8C=E6=AD=A5=E8=87=B3gitea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 119 ++++++++++++++++++---- app/services/projects/transfer_service.rb | 1 + lib/tasks/sync_data_to_gitea.rake | 4 +- 3 files changed, 105 insertions(+), 19 deletions(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index ee361d2cf..7a16f25fe 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -24,23 +24,62 @@ module ProjectOperable if self.owner.is_a?(Organization) case role_name when 'Manager' + # 构建相应的团队 team = self.owner.teams.admin.take - team = team.nil? ? Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) : team - TeamProject.build(self.user_id, team.id, self.id) - OrganizationUser.build(self.user_id, user_id) + if team.nil? + team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) + gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil + team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil? + end + + # 设置项目在团队中的访问权限 + team_project = TeamProject.build(self.user_id, team.id, self.id) + tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil + + # 新增对应的团队成员 team_user = TeamUser.build(self.user_id, user_id, team.id) + $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 + + # 确保组织成员中有该用户 + OrganizationUser.build(self.user_id, user_id) when 'Developer' + # 构建相应的团队 team = self.owner.teams.write.take - team = team.nil? ? Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) : team - TeamProject.build(self.user_id, team.id, self.id) - OrganizationUser.build(self.user_id, user_id) + if team.nil? + team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) + gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil + team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil? + end + + # 设置项目在团队中的访问权限 + team_project = TeamProject.build(self.user_id, team.id, self.id) + tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil + + # 新增对应的团队成员 team_user = TeamUser.build(self.user_id, user_id, team.id) + $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 + + # 确保组织成员中有该用户 + OrganizationUser.build(self.user_id, user_id) when 'Reporter' + # 构建相应的团队 team = self.owner.teams.read.take - team = team.nil? ? Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) : team - TeamProject.build(self.user_id, team.id, self.id) - OrganizationUser.build(self.user_id, user_id) + if team.nil? + team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) + gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil + team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil? + end + + # 设置项目在团队中的访问权限 + team_project = TeamProject.build(self.user_id, team.id, self.id) + tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil + + # 新增对应的团队成员 team_user = TeamUser.build(self.user_id, user_id, team.id) + $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 + + # 确保组织成员中有该用户 + OrganizationUser.build(self.user_id, user_id) end end member = members.create!(user_id: user_id, team_user_id: team_user&.id) @@ -71,26 +110,70 @@ module ProjectOperable def change_member_role!(user_id, role) member = self.member(user_id) + # 所有者为组织,并且该用户属于组织成员 if self.owner.is_a?(Organization) && member.team_user.present? case role&.name when 'Manager' + # 构建相应的团队 team = self.owner.teams.admin.take - team = team.nil? ? Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) : team - TeamProject.build(self.user_id, team.id, self.id) + if team.nil? + team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) + gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil + team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil? + end + + # 设置项目在团队中的访问权限 + team_project = TeamProject.build(self.user_id, team.id, self.id) + tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil + + # 更改对应的团队成员 + team_user = member.team_user + $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的 + $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 + team_user.update_column(:team_id, team.id) + + # 确保组织成员中有该用户 OrganizationUser.build(self.user_id, user_id) - team_user = member.team_user.update(team_id: team&.id) when 'Developer' + # 构建相应的团队 team = self.owner.teams.write.take - team = team.nil? ? Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) : team - TeamProject.build(self.user_id, team.id, self.id) + if team.nil? + team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) + gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil + team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil? + end + # 设置项目在团队中的访问权限 + team_project = TeamProject.build(self.user_id, team.id, self.id) + $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil + + # 更改对应的团队成员 + team_user = member.team_user + $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的 + $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 + team_user.update_column(:team_id, team.id) + OrganizationUser.build(self.user_id, user_id) - team_user = member.team_user.update(team_id: team&.id) when 'Reporter' + # 构建相应的团队 team = self.owner.teams.read.take - team = team.nil? ? Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) : team - TeamProject.build(self.user_id, team.id, self.id) + if team.nil? + team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) + gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil + team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil? + end + + # 设置项目在团队中的访问权限 + team_project = TeamProject.build(self.user_id, team.id, self.id) + tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil + + # 更改对应的团队成员 + team_user = member.team_user + $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的 + $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 + team_user.update_column(:team_id, team.id) + + # 确保组织成员中有该用户 OrganizationUser.build(self.user_id, user_id) - team_user = member.team_user.update(team_id: team&.id) end end member.member_roles.last.update_attributes!(role: role) diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 157263962..5df5e9f1e 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -24,6 +24,7 @@ class Projects::TransferService < ApplicationService private def update_owner + # 转移项目需要移除原来的权限 project.members.map{|m| m.destroy! if m.user_id == owner.id || project.member(new_owner.id) || (new_owner.is_a?(Organization) && new_owner.is_member?(m.user_id)) } project.set_owner_permission(new_owner) project.update!(user_id: new_owner.id) diff --git a/lib/tasks/sync_data_to_gitea.rake b/lib/tasks/sync_data_to_gitea.rake index 8b8dd0ab0..b2352201b 100644 --- a/lib/tasks/sync_data_to_gitea.rake +++ b/lib/tasks/sync_data_to_gitea.rake @@ -16,8 +16,10 @@ namespace :sync_data_to_gitea do end team.team_users.each do |teamuser| userlogin = teamuser&.user&.login + ou = org.organization_users.find_by(user_id: teamuser.user_id) + OrganizationUser.build(org.id, teamuser.user_id) unless ou.present? next if ($gitea_client.get_teams_members_by_id_username(team.gtid, userlogin) rescue nil) - tu_result = $gitea_client.put_teams_members_by_id_username(team.gtid, userlogin) rescue nil + tu_result = $gitea_client.put_teams_members_by_id_username(team.gtid, userlogin) rescue nil raise ActiveRecord::Rollback if tu_result.nil? end team.team_projects.each do |teamp| From 3d5b2e76d7520791d96929ee75be7d5357c31357 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 26 Oct 2022 14:58:04 +0800 Subject: [PATCH 33/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aupdate=5Fcolum?= =?UTF-8?q?n=E6=97=A0=E6=B3=95=E8=A7=A6=E5=8F=91count=5Fcache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index 7a16f25fe..1509b1dc2 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -130,7 +130,7 @@ module ProjectOperable team_user = member.team_user $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的 $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 - team_user.update_column(:team_id, team.id) + team_user.update_attributes!({team_id: team.id}) # 确保组织成员中有该用户 OrganizationUser.build(self.user_id, user_id) @@ -150,7 +150,7 @@ module ProjectOperable team_user = member.team_user $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的 $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 - team_user.update_column(:team_id, team.id) + team_user.update_attributes!({team_id: team.id}) OrganizationUser.build(self.user_id, user_id) when 'Reporter' @@ -170,7 +170,7 @@ module ProjectOperable team_user = member.team_user $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的 $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的 - team_user.update_column(:team_id, team.id) + team_user.update_attributes!({team_id: team.id}) # 确保组织成员中有该用户 OrganizationUser.build(self.user_id, user_id) From 84a8339a04f23715384fce2f823544af751a4f18 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 26 Oct 2022 15:16:06 +0800 Subject: [PATCH 34/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/sync_data_to_gitea.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/sync_data_to_gitea.rake b/lib/tasks/sync_data_to_gitea.rake index b2352201b..e2c162252 100644 --- a/lib/tasks/sync_data_to_gitea.rake +++ b/lib/tasks/sync_data_to_gitea.rake @@ -28,7 +28,7 @@ namespace :sync_data_to_gitea do end end org.organization_users.each do |user| - next if ($gitea_client.get_orgs_members_by_org_username(org.login, user.login) rescue nil) + $gitea_client.get_orgs_members_by_org_username(org.login, user.login) rescue next user.destroy! end end From e72dfa4973d9d964a190d0b6888b6b3065891584 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 27 Oct 2022 09:28:52 +0800 Subject: [PATCH 35/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=BF=81=E7=A7=BB=E8=AE=BE=E7=BD=AE=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=9C=A8=E6=9B=B4=E6=94=B9=E6=8B=A5=E6=9C=89=E8=80=85=E4=B9=8B?= =?UTF-8?q?=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/projects/transfer_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 5df5e9f1e..ea16bcf9e 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -26,8 +26,8 @@ class Projects::TransferService < ApplicationService def update_owner # 转移项目需要移除原来的权限 project.members.map{|m| m.destroy! if m.user_id == owner.id || project.member(new_owner.id) || (new_owner.is_a?(Organization) && new_owner.is_member?(m.user_id)) } - project.set_owner_permission(new_owner) project.update!(user_id: new_owner.id) + project.set_owner_permission(new_owner) end def update_repo_url From 7d4c0df6911c7f6b16af2770d1a0e5aabb1ba851 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 27 Oct 2022 09:55:55 +0800 Subject: [PATCH 36/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/projects/transfer_service.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index ea16bcf9e..244a2d318 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -25,6 +25,7 @@ class Projects::TransferService < ApplicationService private def update_owner # 转移项目需要移除原来的权限 + project.members.update_all(team_user_id: nil) project.members.map{|m| m.destroy! if m.user_id == owner.id || project.member(new_owner.id) || (new_owner.is_a?(Organization) && new_owner.is_member?(m.user_id)) } project.update!(user_id: new_owner.id) project.set_owner_permission(new_owner) From e15809c1860037827428781074374203110a378d Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 27 Oct 2022 10:48:24 +0800 Subject: [PATCH 37/38] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E8=BD=AC=E7=A7=BB=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 2 +- app/services/projects/transfer_service.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index 1509b1dc2..bdce2fda2 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -17,7 +17,7 @@ module ProjectOperable owner.build_permit_team_projects!(id) # 避免自己创建的项目,却无法拥有访问权,因为该用户所在团队暂未获得项目访问权 return if creator.nil? || owner.is_owner?(creator.id) - add_member!(creator.id, "Manager") + add_member!(creator.id, "Manager") if creator.is_a?(User) end def add_member!(user_id, role_name='Developer') diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 244a2d318..8ed58f8a7 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -51,7 +51,8 @@ class Projects::TransferService < ApplicationService def gitea_update_owner begin - @gitea_repo = Gitea::Repository::TransferService.call(owner&.gitea_token, owner&.login, project.identifier, new_owner&.login) + @gitea_repo = $gitea_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json}) + # @gitea_repo = Gitea::Repository::TransferService.call(owner&.gitea_token, owner&.login, project.identifier, new_owner&.login) rescue Exception => e Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}") end From 9664ca001e3fb30e5478a858f36979825805ac7a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 27 Oct 2022 17:57:55 +0800 Subject: [PATCH 38/38] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E9=87=8D=E6=96=B0=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=90=8E=E4=B9=8B=E5=89=8D=E7=9A=84=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E9=9C=80=E8=AE=BE=E7=BD=AE=E4=B8=BA=E6=97=A0=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 1babd9bca..3c6bec6a6 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -29,6 +29,8 @@ class Api::V1::UsersController < Api::V1::BaseController tip_exception(-2,"邮件发送失败,请稍后重试") end ver_params = {code_type: code_type, code: verification_code, email: mail} + last_code = VerificationCode.where(code_type: code_type, email: mail).last + last_code.update_attributes!({created_at: Time.current - 10.minute}) if last_code.present? data = VerificationCode.new(ver_params) if data.save! render_ok