| @@ -3,7 +3,7 @@ class IssuesController < ApplicationController | |||
| before_action :load_project | |||
| before_action :set_user | |||
| before_action :check_issue_permission | |||
| before_action :operate_issue_permission, only:[:create, :update, :destroy, :clean, :series_update] | |||
| before_action :operate_issue_permission, only:[:create, :update, :destroy, :clean, :series_update, :copy] | |||
| before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue] | |||
| before_action :set_issue, only: [:edit, :update, :destroy, :show, :copy, :close_issue, :lock_issue] | |||
| @@ -231,7 +231,7 @@ class IssuesController < ApplicationController | |||
| end | |||
| def show | |||
| @user_permission = current_user.present? && current_user.logged? && (!@issue.is_lock || @project.member?(current_user) || current_user.admin? || @issue.user == current_user) | |||
| @user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) | |||
| @issue_attachments = @issue.attachments | |||
| @issue_user = @issue.user | |||
| @issue_assign_to = @issue.get_assign_user | |||
| @@ -316,6 +316,7 @@ class IssuesController < ApplicationController | |||
| def copy | |||
| @new_issue = @issue.dup | |||
| @new_issue.author_id = current_user.id | |||
| if @new_issue.save | |||
| issue_tags = @issue.issue_tags.pluck(:id) | |||
| if issue_tags.present? | |||
| @@ -416,7 +417,7 @@ class IssuesController < ApplicationController | |||
| def operate_issue_permission | |||
| return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.member?(current_user) | |||
| end | |||
| def export_issues(issues) | |||
| @table_columns = %w(ID 类型 标题 描述 状态 指派给 优先级 标签 发布人 创建时间 里程碑 开始时间 截止时间 完成度 分类 金额 属于) | |||
| @export_issues = [] | |||
| @@ -123,10 +123,11 @@ class ProjectsController < ApplicationController | |||
| Projects::UpdateForm.new(validate_params).validate! | |||
| private = params[:private] || false | |||
| private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false | |||
| new_project_params = project_params.except(:private).merge(is_public: !private) | |||
| @project.update_attributes!(new_project_params) | |||
| @project.forked_projects.update_all(is_public: @project.is_public) | |||
| gitea_params = { | |||
| private: private, | |||
| default_branch: @project.default_branch, | |||
| @@ -151,6 +152,7 @@ class ProjectsController < ApplicationController | |||
| ActiveRecord::Base.transaction do | |||
| Gitea::Repository::DeleteService.new(@project.owner, @project.identifier).call | |||
| @project.destroy! | |||
| @project.forked_projects.update_all(forked_from_project_id: nil) | |||
| render_ok | |||
| end | |||
| else | |||
| @@ -23,13 +23,17 @@ module Gitea | |||
| def run | |||
| Gitea::UserForm.new(params).validate! | |||
| response = Gitea::User::RegisterService.call(params.merge(token: token)) | |||
| render_result(response) | |||
| if response[:status] == :success | |||
| @result = response | |||
| else | |||
| fail!(response[:message]) | |||
| end | |||
| rescue Exception => exception | |||
| Rails.logger.info "Exception ===========> #{exception.message}" | |||
| fail!(exception.message) | |||
| end | |||
| private | |||
| attr_reader :params | |||
| @@ -38,10 +42,6 @@ module Gitea | |||
| @error = error | |||
| end | |||
| def render_result(response) | |||
| @result = response | |||
| end | |||
| def token | |||
| { | |||
| username: Gitea.gitea_config[:access_key_id], | |||
| @@ -65,7 +65,7 @@ module ProjectOperable | |||
| if owner.is_a?(User) | |||
| managers.exists?(user_id: user.id) | |||
| elsif owner.is_a?(Organization) | |||
| managers.exists?(user_id: user.id) || owner.is_only_admin?(user.id) | |||
| managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || owner.is_only_admin?(user.id) | |||
| else | |||
| false | |||
| end | |||
| @@ -76,8 +76,6 @@ | |||
| # | |||
| class Project < ApplicationRecord | |||
| include Matchable | |||
| include Publicable | |||
| @@ -100,10 +98,12 @@ class Project < ApplicationRecord | |||
| belongs_to :organization_extension, foreign_key: :user_id, primary_key: :organization_id, optional: true, counter_cache: :num_projects | |||
| belongs_to :project_category, optional: true , :counter_cache => true | |||
| belongs_to :project_language, optional: true , :counter_cache => true | |||
| belongs_to :forked_from_project, class_name: 'Project', optional: true, foreign_key: :forked_from_project_id | |||
| has_many :project_trends, dependent: :destroy | |||
| has_many :watchers, as: :watchable, dependent: :destroy | |||
| has_many :fork_users, dependent: :destroy | |||
| has_many :forked_users, class_name: 'ForkUser', foreign_key: :fork_project_id, dependent: :destroy | |||
| has_many :forked_projects, class_name: 'Project', foreign_key: :forked_from_project_id | |||
| has_one :project_educoder, dependent: :destroy | |||
| has_one :project_score, dependent: :destroy | |||
| @@ -1,3 +1,14 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: project_infos | |||
| # | |||
| # id :integer not null, primary key | |||
| # project_id :integer | |||
| # user_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| class ProjectInfo < ActiveRecord::Base | |||
| belongs_to :project | |||
| @@ -3,8 +3,8 @@ | |||
| # Table name: pull_requests | |||
| # | |||
| # id :integer not null, primary key | |||
| # pull_request_id :integer | |||
| # gpid :integer | |||
| # gitea_id :integer | |||
| # gitea_number :integer | |||
| # user_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| @@ -185,7 +185,7 @@ class User < Owner | |||
| :show_email, :show_location, :show_department, | |||
| :technical_title, :province, :city, :custom_department, to: :user_extension, allow_nil: true | |||
| before_save :update_hashed_password | |||
| before_save :update_hashed_password, :set_lastname | |||
| after_create do | |||
| SyncTrustieJob.perform_later("user", 1) if allow_sync_to_trustie? | |||
| end | |||
| @@ -778,6 +778,10 @@ class User < Owner | |||
| self.laboratory = Laboratory.current if laboratory_id.blank? | |||
| end | |||
| def set_lastname | |||
| self.lastname = self.nickname if changes[:nickname].present? | |||
| end | |||
| end | |||
| @@ -10,8 +10,7 @@ class Gitea::User::RegisterService < Gitea::ClientService | |||
| params = Hash.new.merge(data: user_params, token: @token) | |||
| response = post(API_REST, params) | |||
| status, message, body = render_response(response) | |||
| json_format(status, message, body) | |||
| response_payload(response) | |||
| end | |||
| private | |||
| @@ -35,4 +34,31 @@ class Gitea::User::RegisterService < Gitea::ClientService | |||
| end | |||
| end | |||
| def response_payload(response) | |||
| status = response.status | |||
| body = response&.body | |||
| log_error(status, body) | |||
| status_payload(status, body) | |||
| end | |||
| def status_payload(status, body) | |||
| case status | |||
| when 201 then success(body) | |||
| when 403 then error("你没有权限操作!") | |||
| when 400 then error("服务器开小差了") | |||
| when 422 | |||
| body = json_parse!(body) | |||
| message = body['message'] | |||
| puts "422 。。。。。 #{body}" | |||
| puts "body messge : 00000000000 #{body['message']}" | |||
| if message.include?('email') | |||
| error("邮箱#{email}已被注册") | |||
| elsif message.include?('name') | |||
| error("用户名#{username}已被注册") | |||
| end | |||
| else error("系统错误!") | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,26 @@ | |||
| namespace :sync_projects_by_forked_project do | |||
| desc "sync projects is_public by forked project" | |||
| task is_public: :environment do | |||
| count = 0 | |||
| Project.where.not(forked_from_project_id: nil).group(:forked_from_project_id).count.each do |k, _| | |||
| project = Project.find_by_id(k) | |||
| need_update_forked_projects = Project.where(forked_from_project_id: k) | |||
| need_update_forked_projects.update_all(is_public: project&.is_public) | |||
| need_update_forked_repositories = Repository.where(project_id: need_update_forked_projects.ids) | |||
| need_update_forked_repositories.update_all(hidden: !project&.is_public) | |||
| count +=need_update_forked_projects.size | |||
| end | |||
| puts "共同步了#{count}个项目" | |||
| end | |||
| task destroy: :environment do | |||
| count = 0 | |||
| Project.where.not(forked_from_project_id: nil).find_each do |project| | |||
| if project.forked_from_project.nil? | |||
| project.update(forked_from_project_id: nil) | |||
| count +=1 | |||
| end | |||
| end | |||
| puts "共同步了#{count}个项目" | |||
| end | |||
| end | |||