mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 20:55:46 +08:00
新增: 更新文档
This commit is contained in:
@@ -4,8 +4,8 @@ class Api::V1::Users::Projects::ListService < ApplicationService
|
||||
attr_reader :observe_user, :category, :is_public, :project_type, :sort_by, :sort_direction, :search, :current_user
|
||||
attr_accessor :queried_projects
|
||||
|
||||
validates :category, inclusion: {in: %w(all join created watched forked), message: "请输入正确的Category"}
|
||||
validates :is_public, inclusion: {in: [true, false], message: '请输入正确的IsPublic'}
|
||||
validates :category, inclusion: {in: %w(all join created manage watched forked), message: "请输入正确的Category"}
|
||||
validates :is_public, inclusion: {in: [true, false], message: '请输入正确的IsPublic'}, allow_nil: true
|
||||
validates :project_type, inclusion: {in: %w(common mirror sync_mirror), message: '请输入正确的ProjectType'}, allow_nil: true
|
||||
validates :sort_by, inclusion: {in: Project.column_names, message: '请输入正确的SortBy'}
|
||||
validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}
|
||||
@@ -13,7 +13,7 @@ class Api::V1::Users::Projects::ListService < ApplicationService
|
||||
def initialize(observe_user, params, current_user=nil)
|
||||
@observe_user = observe_user
|
||||
@category = params[:category] || 'all'
|
||||
@is_public = params[:is_public] || true
|
||||
@is_public = params[:is_public]
|
||||
@project_type = params[:project_type]
|
||||
@sort_by = params[:sort_by] || 'updated_on'
|
||||
@sort_direction = params[:sort_direction] || 'desc'
|
||||
@@ -47,6 +47,10 @@ class Api::V1::Users::Projects::ListService < ApplicationService
|
||||
projects = Project.from("( #{normal_projects} UNION #{org_projects} ) AS projects").distinct
|
||||
when 'created'
|
||||
projects = projects.where(user_id: observe_user.id)
|
||||
when 'manage'
|
||||
normal_projects = projects.joins(members: :roles).where(members: {user_id: observe_user.id}, roles: {name: 'Manager'}).to_sql
|
||||
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: observe_user.id}, teams: {authorize: %w(owner admin)}).to_sql
|
||||
projects = Project.from("( #{normal_projects} UNION #{org_projects} ) AS projects").distinct
|
||||
when 'watched'
|
||||
projects = projects.where.not(user_id: observe_user.id).joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observe_user.id})
|
||||
when 'forked'
|
||||
@@ -58,11 +62,14 @@ class Api::V1::Users::Projects::ListService < ApplicationService
|
||||
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
||||
end
|
||||
|
||||
if is_public
|
||||
projects = projects.visible
|
||||
else
|
||||
projects = projects.is_private
|
||||
unless is_public.nil?
|
||||
if is_public
|
||||
projects = projects.visible
|
||||
else
|
||||
projects = projects.is_private
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
projects = projects.with_project_type(project_type)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user