| @@ -86,3 +86,4 @@ redis_data/ | |||||
| Dockerfile | Dockerfile | ||||
| dump.rdb | dump.rdb | ||||
| .tags* | .tags* | ||||
| ceshi_user.xlsx | |||||
| @@ -775,7 +775,8 @@ class ApplicationController < ActionController::Base | |||||
| end | end | ||||
| def convert_image! | def convert_image! | ||||
| @image = params[:image] || user_params[:image] | |||||
| @image = params[:image] | |||||
| @image = @image.nil? && params[:user].present? ? params[:user][:image] : @image | |||||
| return unless @image.present? | return unless @image.present? | ||||
| max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M | max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M | ||||
| if @image.class == ActionDispatch::Http::UploadedFile | if @image.class == ActionDispatch::Http::UploadedFile | ||||
| @@ -302,9 +302,11 @@ class IssuesController < ApplicationController | |||||
| # update_hash = params[:issue] | # update_hash = params[:issue] | ||||
| issue_ids = params[:ids] | issue_ids = params[:ids] | ||||
| if issue_ids.present? | if issue_ids.present? | ||||
| issues = Issue.where(id: issue_ids) | |||||
| if update_hash.blank? | if update_hash.blank? | ||||
| normal_status(-1, "请选择批量更新内容") | normal_status(-1, "请选择批量更新内容") | ||||
| elsif Issue.where(id: issue_ids)&.update(update_hash) | |||||
| elsif issues&.update(update_hash) | |||||
| issues.map{|i| i.create_journal_detail(false, [], [], current_user&.id) if i.previous_changes.present?} | |||||
| normal_status(0, "批量更新成功") | normal_status(0, "批量更新成功") | ||||
| else | else | ||||
| normal_status(-1, "批量更新失败") | normal_status(-1, "批量更新失败") | ||||
| @@ -16,6 +16,7 @@ class ProjectsController < ApplicationController | |||||
| menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code") | 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") | menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues") | ||||
| menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") | menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") | ||||
| menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") | |||||
| menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops") | menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops") | ||||
| menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions") | menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions") | ||||
| menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") | menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") | ||||
| @@ -34,11 +34,12 @@ module ProjectsHelper | |||||
| end | end | ||||
| def json_response(project, user) | def json_response(project, user) | ||||
| repo = Repository.includes(:mirror).select(:id, :mirror_url, :source_clone_url).find_by(project: project) | |||||
| repo = Repository.includes(:mirror).select(:id, :is_mirror, :mirror_url, :source_clone_url).find_by(project: project) | |||||
| tmp_json = {} | tmp_json = {} | ||||
| unless project.common? | unless project.common? | ||||
| tmp_json = tmp_json.merge({ | tmp_json = tmp_json.merge({ | ||||
| is_mirror: repo.is_mirror ? true : false, | |||||
| mirror_status: repo.mirror_status, | mirror_status: repo.mirror_status, | ||||
| mirror_num: repo.mirror_num, | mirror_num: repo.mirror_num, | ||||
| mirror_url: repo.remote_mirror_url, | mirror_url: repo.remote_mirror_url, | ||||
| @@ -54,7 +55,11 @@ module ProjectsHelper | |||||
| repo_id: repo.id, | repo_id: repo.id, | ||||
| open_devops: (user.blank? || user.is_a?(AnonymousUser)) ? false : project.open_devops?, | open_devops: (user.blank? || user.is_a?(AnonymousUser)) ? false : project.open_devops?, | ||||
| type: project.numerical_for_project_type, | type: project.numerical_for_project_type, | ||||
| author: render_owner(project) | |||||
| author: render_owner(project), | |||||
| project_category_id: project.project_category_id, | |||||
| project_language_id: project.project_language_id, | |||||
| license_id: project.license_id, | |||||
| ignore_id: project.ignore_id | |||||
| }).compact | }).compact | ||||
| render json: tmp_json | render json: tmp_json | ||||
| @@ -8,10 +8,13 @@ class MigrateRemoteRepositoryJob < ApplicationJob | |||||
| puts "############ MigrateRemoteRepositoryJob starting ... ############" | puts "############ MigrateRemoteRepositoryJob starting ... ############" | ||||
| gitea_repository = Gitea::Repository::MigrateService.new(token, params).call | gitea_repository = Gitea::Repository::MigrateService.new(token, params).call | ||||
| if gitea_repository | |||||
| repo&.project&.update_columns(gpid: gitea_repository["id"]) | |||||
| puts "#gitea_repository#{gitea_repository}" | |||||
| if gitea_repository[0]==201 | |||||
| repo&.project&.update_columns(gpid: gitea_repository[2]["id"]) | |||||
| repo&.mirror&.succeeded! | repo&.mirror&.succeeded! | ||||
| puts "############ mirror status: #{repo.mirror.status} ############" | puts "############ mirror status: #{repo.mirror.status} ############" | ||||
| else | |||||
| repo&.mirror&.failed! | |||||
| end | end | ||||
| end | end | ||||
| end | end | ||||
| @@ -16,7 +16,7 @@ | |||||
| class ProjectUnit < ApplicationRecord | class ProjectUnit < ApplicationRecord | ||||
| belongs_to :project | belongs_to :project | ||||
| enum unit_type: {code: 1, issues: 2, pulls: 3, devops: 4, versions: 5, resources: 6} | |||||
| enum unit_type: {code: 1, issues: 2, pulls: 3, wiki:4, devops: 5, versions: 6, resources: 7} | |||||
| validates :unit_type, uniqueness: { scope: :project_id} | validates :unit_type, uniqueness: { scope: :project_id} | ||||
| @@ -33,7 +33,7 @@ class Gitea::Repository::MigrateService < Gitea::ClientService | |||||
| def call | def call | ||||
| response = post(url, request_params) | response = post(url, request_params) | ||||
| render_201_response(response) | |||||
| render_response(response) | |||||
| end | end | ||||
| private | private | ||||
| @@ -8,7 +8,7 @@ json.user_login @version.version_user.try(:login) | |||||
| json.created_at format_time(@version.created_on) | json.created_at format_time(@version.created_on) | ||||
| json.updated_at format_time(@version.updated_on) | json.updated_at format_time(@version.updated_on) | ||||
| json.search_count @version_issues_size | json.search_count @version_issues_size | ||||
| json.percent @version.percent*100 | |||||
| json.percent @version_close_issues_size.to_f/@version_issues_size*100#@version.percent*100 | |||||
| json.extract! @version, :id,:name,:project_id,:description, :effective_date, :status, :sharing,:wiki_page_title | json.extract! @version, :id,:name,:project_id,:description, :effective_date, :status, :sharing,:wiki_page_title | ||||
| json.issues do | json.issues do | ||||
| @@ -0,0 +1,61 @@ | |||||
| namespace :produce_and_export_ceshi_user do | |||||
| desc "Produce ceshi user and Export to excel" | |||||
| task call: :environment do | |||||
| puts "=======Begin=======" | |||||
| DCODES = %W(1 2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) | |||||
| username = DCODES.sample(8).join | |||||
| email = username + '@forge.com' | |||||
| password = SecureRandom.base64[8..-1] | |||||
| p = Axlsx::Package.new | |||||
| p.workbook.add_worksheet(:name => '测试用户') do |sheet| | |||||
| sheet.add_row ["用户名", "邮箱", "密码", "GiteaToken", "测试仓库", "测试仓库克隆地址"] | |||||
| (1..100).to_a.each do |i| | |||||
| while (User.find_by(login: username).present? || User.find_by(mail: email).present?) do | |||||
| username = DCODES.sample(8).join | |||||
| email = username + '@forge.com' | |||||
| password = SecureRandom.base64[8..-1] | |||||
| end | |||||
| puts "=======Generate:[#{i}] Username: #{username}, Password: #{password}, Email: #{email}=======" | |||||
| puts "=======Create User Begin====== " | |||||
| user = User.new(admin: false, login: username, mail: email, type: "User") | |||||
| user.password = password | |||||
| user.platform = 'forge' | |||||
| user.activate | |||||
| next unless user.valid? | |||||
| interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password}) | |||||
| if interactor.success? | |||||
| gitea_user = interactor.result | |||||
| result = Gitea::User::GenerateTokenService.call(username, password) | |||||
| user.gitea_token = result['sha1'] | |||||
| user.gitea_uid = gitea_user[:body]['id'] | |||||
| if user.save! | |||||
| UserExtension.create!(user_id: user.id) | |||||
| end | |||||
| end | |||||
| puts "=======Create User End====== " | |||||
| code = DCODES.sample(8).join | |||||
| project_params = { | |||||
| user_id: user.id, | |||||
| name: code, | |||||
| repository_name: code, | |||||
| project_category_id: ProjectCategory.pluck(:id).sample, | |||||
| project_language_id: ProjectLanguage.pluck(:id).sample, | |||||
| license_id: License.pluck(:id).sample, | |||||
| ignore_id: Ignore.pluck(:id).sample, | |||||
| private: true | |||||
| } | |||||
| project = Projects::CreateService.new(user, project_params).call | |||||
| puts project.as_json | |||||
| sheet.add_row [username, email, password, user.gitea_token, "#{username}/#{code}", project&.repository.url] | |||||
| end | |||||
| end | |||||
| p.use_shared_strings = true | |||||
| p.serialize('ceshi_user.xlsx') | |||||
| puts "=======END=======" | |||||
| end | |||||
| end | |||||