diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index c5e9960d5..bbca99f1b 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -32,11 +32,12 @@ class AccountsController < ApplicationController username = params[:username]&.gsub(/\s+/, "") tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.check_exists?(username) email = params[:email]&.gsub(/\s+/, "") + phone = params[:phone]&.gsub(/\s+/, "") password = params[:password] platform = (params[:platform] || 'forge')&.gsub(/\s+/, "") ActiveRecord::Base.transaction do - result = autologin_register(username, email, password, platform) + result = autologin_register(username, email, password, platform, phone) if result[:message].blank? render_ok({user: result[:user]}) else @@ -144,7 +145,7 @@ class AccountsController < ApplicationController user = Users::RegisterService.call(register_params) user.mail = "#{user.login}@example.org" if user.mail.blank? - password = decrypt(register_params[:password]) rescue "" + password = decrypt(register_params[:password]) rescue register_params[:password].to_s password = password.strip # gitea用户注册, email, username, password @@ -195,7 +196,7 @@ class AccountsController < ApplicationController # 用户登录 def login - password = decrypt(login_params[:password]) rescue login_params[:password] + password = decrypt(login_params[:password]) rescue login_params[:password].to_s Users::LoginForm.new(login_params.merge!({password: password})).validate! @user = User.try_to_login(params[:login], password) @@ -225,9 +226,9 @@ class AccountsController < ApplicationController end def change_password - password = decrypt(params[:password]) rescue params[:password] - new_password_repeat = decrypt(params[:new_password_repeat]) rescue params[:new_password_repeat] - old_password = decrypt(params[:old_password]) rescue "" + password = decrypt(params[:password]) rescue params[:password].to_s + new_password_repeat = decrypt(params[:new_password_repeat]) rescue params[:new_password_repeat].to_s + old_password = decrypt(params[:old_password]) rescue params[:old_password] return render_error("两次输入的密码不一致") if password.to_s != new_password_repeat.to_s @user = User.find_by(login: params[:login]) return render_forbidden unless User.current.login == @user&.login diff --git a/app/controllers/api/pm/dashboards_controller.rb b/app/controllers/api/pm/dashboards_controller.rb index 36e361079..574d084a1 100644 --- a/app/controllers/api/pm/dashboards_controller.rb +++ b/app/controllers/api/pm/dashboards_controller.rb @@ -19,7 +19,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController pm_project_ids = params[:pm_project_ids].split(",") rescue [] pm_issue_types = params[:pm_issue_types].split(",") rescue [] @all_issues = Issue.where(pm_project_id: pm_project_ids, pm_issue_type: pm_issue_types) - @issues = @all_issues.joins(:issue_participants).where(issue_participants: {participant_id: current_user.id}) + @issues = @all_issues.joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}) @issues = @issues.where.not(status_id: 5) if params[:category] == "opened" @issues = kaminari_paginate(@issues.distinct.pm_includes) diff --git a/app/controllers/api/pm/pipelines_controller.rb b/app/controllers/api/pm/pipelines_controller.rb new file mode 100644 index 000000000..933417ff2 --- /dev/null +++ b/app/controllers/api/pm/pipelines_controller.rb @@ -0,0 +1,77 @@ +class Api::Pm::PipelinesController < Api::Pm::BaseController + include RepositoriesHelper + + def index + @owner = Owner.find_by(login: params[:owner_id].to_s) || Owner.find_by(id: params[:owner_id].to_s) + tip_exception('组织未找到') if @owner.blank? + unless @owner.is_a?(Organization) && @owner.is_member?(current_user.id) + tip_exception('没有查看组织的权限') + end + @project_ids = @owner.projects.ids + project_gpids = @owner.projects.pluck(:gpid) + action_runs = Gitea::ActionRun.where(owner_id: @owner.gitea_uid) + group_data = action_runs.where(status: [1,2]).group(:workflow_id, :status).count + pipelines = Action::Pipeline.where(project_id: @project_ids).order(updated_at: :desc) + run_files = Gitea::ActionRun.select(:workflow_id, :repo_id).where(owner_id: @owner.gitea_uid).group(:workflow_id, :repo_id) + db_files = pipelines.pluck(:file_name) + @run_result = [] + run_files.each do |file_info| + file = file_info.workflow_id + project = Project.find_by(gpid: file_info.repo_id) + next if project.blank? + unless db_files.include?(".gitea/workflows/#{file}") + pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), + file_name: ".gitea/workflows/#{file}", + branch: project.default_branch, + is_graphic_design: false, + disable: false, + project_id: project.id) + interactor = Repositories::EntriesInteractor.call(@owner, project.identifier, ".gitea/workflows/#{file}", ref: project.default_branch) + if interactor.success? + pipeline.yaml = decode64_content(interactor.result, @owner, project.repository, project.default_branch, nil) + end + pipeline.user_id = current_user.id + pipeline.save + # 导入的流水线统一先禁用 + $gitea_hat_client.post_repos_actions_disable(project&.owner&.login, project&.identifier, {query: {workflow: file}}) rescue nil + end + last_action_run = action_runs.where(repo_id: project.gpid).where(workflow_id: file).order(updated: :desc).first + last_action_run_json = last_action_run.present? ? { + id: last_action_run.id, + schedule: last_action_run.schedule_id > 0, + title: last_action_run.title, + index: last_action_run.index, + status: last_action_run.status, + started: last_action_run.started, + stopped: last_action_run.stopped, + length: last_action_run.stopped-last_action_run.started, + created: last_action_run.created, + updated: last_action_run.updated, + } : {} + + total = 0 + success = 0 + failure = 0 + group_data.each do |k,v| + total += v if k[0] == file + success += v if k[0] == file && k[1] == 1 + failure += v if k[0] == file && k[1] == 2 + end + @run_result << { + repo_id: last_action_run.repo_id, + filename: ".gitea/workflows/#{file}", + total: total, + success: success, + failure: failure + }.merge(last_action_run_json) + end + # Rails.logger.info("@run_result======#{@run_result}") + @disabled_workflows = Gitea::RepoUnit.where(repo_id: project_gpids, type: 10).where("config is not null") + @pipelines = Action::Pipeline.select("distinct project_id,max(updated_at) as updated_at") + .where(project_id: @project_ids).group(:project_id).order("updated_at desc") + @pipelines = @pipelines.where("pipeline_name like ?", "%#{params[:pipeline_name]}%") if params[:pipeline_name].present? + @pipelines = @pipelines.where(pipeline_type: params[:pipeline_type]) if params[:pipeline_type].present? + @pipelines = kaminari_paginate(@pipelines) + end + +end diff --git a/app/controllers/api/v1/projects/actions/runs_controller.rb b/app/controllers/api/v1/projects/actions/runs_controller.rb index cdde508a1..3e9e2024c 100644 --- a/app/controllers/api/v1/projects/actions/runs_controller.rb +++ b/app/controllers/api/v1/projects/actions/runs_controller.rb @@ -1,9 +1,12 @@ class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController def index - @result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token) - @begin_num = (page.to_i - 1) * limit.to_i - # puts @result_object + @files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue [] + @has_file = @files.select { |i| i['name'] == params[:workflow] }.present? + if @has_file + @result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token) + @begin_num = (page.to_i - 1) * limit.to_i + end end def create diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 5aa62caab..305cc974f 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -11,13 +11,11 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @run_result = [] @files.map { |i| i['name'] }.each do |file| unless db_files.include?(".gitea/workflows/#{file}") - disabled_config = Gitea::RepoUnit.where(repo_id: @project.gpid, type: 10)&.first&.config - disabled_workflows = disabled_config.present? ? JSON.parse(disabled_config)["DisabledWorkflows"] : [] - pipeline = Action::Pipeline.new(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), + pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), file_name: ".gitea/workflows/#{file}", branch: @project.default_branch, is_graphic_design: false, - disable: disabled_workflows.include?(file.to_s), + disable: false, project_id: @project.id) interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, ".gitea/workflows/#{file}", ref: @project.default_branch) if interactor.success? @@ -25,6 +23,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end pipeline.user_id = current_user.id pipeline.save + # 导入的流水线统一先禁用 + $gitea_hat_client.post_repos_actions_disable(@project&.owner&.login, @project&.identifier, {query: {workflow: file}}) rescue nil end last_action_run = @action_runs.where(workflow_id: file).order(updated: :desc).first last_action_run_json = last_action_run.present? ? { @@ -55,9 +55,11 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController failure: failure }.merge(last_action_run_json) end - Rails.logger.info("@run_result======#{@run_result}") + # Rails.logger.info("@run_result======#{@run_result}") + disabled_config = Gitea::RepoUnit.where(repo_id: @project.gpid, type: 10)&.first&.config + @disabled_workflows = disabled_config.present? ? JSON.parse(disabled_config)["DisabledWorkflows"] : [] @pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) - @pipelines = paginate @pipelines + @pipelines = kaminari_paginate(@pipelines) end def test_yaml @@ -94,19 +96,21 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def save_yaml @pipeline = params[:id].present? ? Action::Pipeline.find(params[:id]) : Action::Pipeline.find_or_initialize_by(pipeline_name: params[:pipeline_name], project_id: @project.id) @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" - @pipeline.branch = params[:branch] || @project.default_branch + @pipeline.branch = params[:branch].to_json if params[:branch].present? @pipeline.json = params[:pipeline_json].to_json if params[:pipeline_json].present? - pipeline_yaml = params[:pipeline_yaml].present? ? params[:pipeline_yaml] : build_pipeline_yaml_new(params[:pipeline_name], params[:pipeline_json]) + @pipeline.pipeline_name = params[:pipeline_name] if params[:pipeline_name].present? + pipeline_yaml = params[:pipeline_yaml].present? ? params[:pipeline_yaml] : build_pipeline_yaml_new(@pipeline.pipeline_name, params[:pipeline_json]) tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml - Rails.logger.info "pipeline_yaml base64=========================#{Base64.encode64(@pipeline.yaml).gsub(/\n/, '')}" + #Rails.logger.info "pipeline_yaml base64=========================#{Base64.encode64(@pipeline.yaml).gsub(/\n/, '')}" sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + #Rails.logger.info "content_params=========#{content_params("create")}" interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? file = interactor.result @pipeline.pipeline_type = @pipeline.json.present? ? 2 : 1 @pipeline.save - render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] }) + render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: @pipeline.pipeline_name, file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] }) end def build_yaml @@ -144,6 +148,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, del_content_params(sha).merge(identifier: @project.identifier)) tip_exception(interactor.error) unless interactor.success? end + Gitea::ActionRun.where(repo_id: @pipeline.project.gpid).destroy_all @pipeline.destroy! end render_ok @@ -175,6 +180,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def show @pipeline = Action::Pipeline.find_by(id: params[:id]) + disabled_config = Gitea::RepoUnit.where(repo_id: @project.gpid, type: 10)&.first&.config + @disabled_workflows = disabled_config.present? ? JSON.parse(disabled_config)["DisabledWorkflows"] : [] # @pipeline = Action::Pipeline.new(id: 0, pipeline_name: "test-ss", yaml: build_test_yaml) if @pipeline.blank? end diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 394ac1b70..336b66191 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -54,7 +54,7 @@ class Api::V1::UsersController < Api::V1::BaseController end def check_password - password = decrypt(params[:password]) rescue params[:password] + password = decrypt(params[:password]) rescue params[:password].to_s return tip_exception(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD return tip_exception(-5, "密码错误") unless @observe_user.check_password?(password) render_ok @@ -127,7 +127,7 @@ class Api::V1::UsersController < Api::V1::BaseController def destroy - password = decrypt(params[:password]) rescue params[:password] + password = decrypt(params[:password]) rescue params[:password].to_s return tip_exception(-1, "密码不正确.") unless @observe_user.check_password?(password) org_ids = TeamUser.where(user_id: @observe_user.id).pluck(:organization_id) | OrganizationUser.where(user_id: @observe_user.id).pluck(:organization_id) org_count = TeamUser.where(organization_id: org_ids).where(user_id: @observe_user.id).joins(:team).where(teams: {authorize: %w(owner)}).count diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 000000000..39e5750d0 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,17 @@ +class HomeController < ApplicationController + + def index + @user_count = Rails.cache.fetch("homecontroller:user_count", expires_in: 1.hours) do + User.count + end + @project_count = Rails.cache.fetch("homecontroller:project_count", expires_in: 1.hours) do + Project.count + end + @project_dataset_count = Rails.cache.fetch("homecontroller:project_dataset_count", expires_in: 1.hours) do + ProjectDataset.count + end + @commit_count = Rails.cache.fetch("homecontroller:commit_count", expires_in: 1.hours) do + CommitLog.count + end + end +end \ No newline at end of file diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index fe5ad0178..f61320638 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -140,7 +140,7 @@ class Organizations::OrganizationsController < Organizations::BaseController end def password - decrypt(params[:password]) rescue params[:password] + decrypt(params[:password]) rescue params[:password].to_s end def load_organization diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d29d41ac0..f5130e30c 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -37,6 +37,10 @@ class RepositoriesController < ApplicationController @fork_project = Project.find_by(id: @project_fork_id) @fork_project_user = @fork_project.owner end + # 修正默认分支 + if @result[:repo].present? && @result[:repo]['default_branch'].present? && @result[:repo]['default_branch'] != @project.default_branch + @project.update_column('default_branch', @result[:repo]['default_branch']) + end rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) diff --git a/app/controllers/users/messages_controller.rb b/app/controllers/users/messages_controller.rb index 4feb4a98e..4d101a8f3 100644 --- a/app/controllers/users/messages_controller.rb +++ b/app/controllers/users/messages_controller.rb @@ -10,6 +10,8 @@ class Users::MessagesController < Users::BaseController result = Notice::Read::ListService.call(observed_user.id, message_type, message_status, page, limit) return render_error if result.nil? @data = result[2] + rescue + render_ok end def create diff --git a/app/forms/base_form.rb b/app/forms/base_form.rb index 330881dd8..0459919dc 100644 --- a/app/forms/base_form.rb +++ b/app/forms/base_form.rb @@ -54,14 +54,14 @@ class BaseForm end def check_password(password) - password = decrypt(password) rescue "" + password = decrypt(password) rescue password password = strip(password) raise PasswordFormatError, "密码8~16位密码,支持字母数字和符号" unless password =~ CustomRegexp::PASSWORD end def check_password_confirmation(password, password_confirmation) - password = decrypt(password) rescue "" - password_confirmation = decrypt(password_confirmation) rescue "" + password = decrypt(password) rescue password + password_confirmation = decrypt(password_confirmation) rescue password_confirmation password = strip(password) password_confirmation = strip(password_confirmation) diff --git a/app/services/accounts/reset_password_service.rb b/app/services/accounts/reset_password_service.rb index d7d6aa1dc..f05a2fe5c 100644 --- a/app/services/accounts/reset_password_service.rb +++ b/app/services/accounts/reset_password_service.rb @@ -4,8 +4,8 @@ module Accounts # login、code、password、password_confirmation def initialize(user, params) @user = user - @password = decrypt(params[:password]) rescue params[:password] - @password_confirmation = decrypt(params[:password_confirmation]) rescue "" + @password = decrypt(params[:password]) rescue params[:password].to_s + @password_confirmation = decrypt(params[:password_confirmation]) rescue params[:password_confirmation].to_s end def call diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index f522927a1..4134bc676 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -11,7 +11,7 @@ class Api::V1::Users::UpdateEmailService < ApplicationService def initialize(user, params, token =nil) @user = user @token = token - @password = decrypt(params[:password]) rescue params[:password] + @password = decrypt(params[:password]) rescue params[:password].to_s @mail = params[:email] @old_mail = user.mail @code = params[:code] diff --git a/app/services/api/v1/users/update_phone_service.rb b/app/services/api/v1/users/update_phone_service.rb index b51e433c4..33c518e79 100644 --- a/app/services/api/v1/users/update_phone_service.rb +++ b/app/services/api/v1/users/update_phone_service.rb @@ -9,7 +9,7 @@ class Api::V1::Users::UpdatePhoneService < ApplicationService def initialize(user, params) @user = user - @password = decrypt(params[:password]) rescue params[:password] + @password = decrypt(params[:password]) rescue params[:password].to_s @phone = params[:phone] @code = params[:code] @verify_code = VerificationCode.where(phone: @phone, code_type: 4).last diff --git a/app/services/users/register_service.rb b/app/services/users/register_service.rb index 5cd174a69..296a26a02 100644 --- a/app/services/users/register_service.rb +++ b/app/services/users/register_service.rb @@ -4,7 +4,7 @@ class Users::RegisterService < ApplicationService def initialize(params) @login = params[:login] @namespace = params[:namespace] - @password = decrypt(params[:password]) rescue params[:password] + @password = decrypt(params[:password]) rescue params[:password].to_s @code = params[:code] end diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index d48db392d..0c9b9c495 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -51,7 +51,7 @@