易修权限、用户更改昵称、fork项目修改项目私有性

This commit is contained in:
yystopf 2021-07-09 13:55:22 +08:00
commit 7c23b40661
5 changed files with 117 additions and 82 deletions

View File

@ -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?

View File

@ -116,10 +116,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,
@ -144,6 +145,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

View File

@ -100,10 +100,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

View File

@ -186,7 +186,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
@ -791,6 +791,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

View File

@ -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