mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 20:55:46 +08:00
Merge pull request 'FIX bug' (#148) from develop into dev_trustie_server
This commit is contained in:
@@ -124,8 +124,8 @@ class Project < ApplicationRecord
|
||||
has_many :has_pinned_users, through: :pinned_projects, source: :user
|
||||
has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id
|
||||
|
||||
after_save :check_project_members, :reset_cache_data
|
||||
before_save :set_invite_code
|
||||
after_save :check_project_members
|
||||
before_save :set_invite_code, :reset_cache_data, :reset_unmember_followed
|
||||
after_destroy :reset_cache_data
|
||||
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
||||
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||
@@ -134,6 +134,18 @@ class Project < ApplicationRecord
|
||||
delegate :content, to: :project_detail, allow_nil: true
|
||||
delegate :name, to: :license, prefix: true, allow_nil: true
|
||||
|
||||
def self.all_visible(user_id=nil)
|
||||
user_projects_sql = Project.joins(:owner).where(users: {type: 'User'}).to_sql
|
||||
org_public_projects_sql = Project.joins(:owner).merge(Organization.joins(:organization_extension).where(organization_extensions: {visibility: 'common'})).to_sql
|
||||
if user_id.present?
|
||||
org_limit_projects_sql = Project.joins(:owner).merge(Organization.joins(:organization_extension).where(organization_extensions: {visibility: 'limited'})).to_sql
|
||||
org_privacy_projects_sql = Project.joins(:owner).merge(Organization.joins(:organization_extension, :organization_users).where(organization_extensions: {visibility: 'privacy'}, organization_users: {user_id: user_id})).to_sql
|
||||
return Project.from("( #{ user_projects_sql } UNION #{ org_public_projects_sql } UNION #{ org_limit_projects_sql } UNION #{org_privacy_projects_sql} ) AS projects").visible
|
||||
else
|
||||
return Project.from("( #{ user_projects_sql } UNION #{ org_public_projects_sql } ) AS projects").visible
|
||||
end
|
||||
end
|
||||
|
||||
def reset_cache_data
|
||||
if changes[:user_id].present?
|
||||
first_owner = Owner.find_by_id(changes[:user_id].first)
|
||||
@@ -143,6 +155,12 @@ class Project < ApplicationRecord
|
||||
self.reset_user_cache_async_job(self.owner)
|
||||
end
|
||||
|
||||
def reset_unmember_followed
|
||||
if changes[:is_public].present? && changes[:is_public] == [true, false]
|
||||
self.watchers.where.not(user_id: self.all_collaborators).destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
def set_invite_code
|
||||
if self.invite_code.nil?
|
||||
self.invite_code= self.generate_dcode('invite_code', 6)
|
||||
|
||||
Reference in New Issue
Block a user