[ADD]search is_member is_admin
This commit is contained in:
parent
c6269f44ee
commit
152e301bf3
|
@ -4,6 +4,8 @@ class Organizations::OrganizationUsersController < Organizations::BaseController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@organization_users = @organization.organization_users.includes(:user)
|
@organization_users = @organization.organization_users.includes(:user)
|
||||||
|
search = params[:search].to_s.downcase
|
||||||
|
@organization_users = @organization_users.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
||||||
|
|
||||||
@organization_users = kaminari_paginate(@organization_users)
|
@organization_users = kaminari_paginate(@organization_users)
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,8 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@is_admin = can_edit_org?
|
||||||
|
@is_member = @organization.is_member?(current_user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -14,6 +14,19 @@ class Organizations::ProjectsController < Organizations::BaseController
|
||||||
@projects = paginate(@projects)
|
@projects = paginate(@projects)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search
|
||||||
|
tip_exception("请输入搜索关键词") if params[:search].nil?
|
||||||
|
public_projects_sql = @organization.projects.where(is_public: true).to_sql
|
||||||
|
private_projects_sql = @organization.projects
|
||||||
|
.where(is_public: false)
|
||||||
|
.joins(team_projects: {team: :team_users})
|
||||||
|
.where(team_users: {user_id: current_user.id}).to_sql
|
||||||
|
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
|
||||||
|
|
||||||
|
@projects = @projects.ransack(name_or_identifier_cont: params[:search]).result
|
||||||
|
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_organization
|
def load_organization
|
||||||
|
|
|
@ -7,6 +7,9 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
def index
|
def index
|
||||||
@team_users = @team.team_users
|
@team_users = @team.team_users
|
||||||
|
|
||||||
|
search = params[:search].to_s.downcase
|
||||||
|
@team_users = @team_users.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
||||||
|
|
||||||
@team_users = kaminari_paginate(@team_users)
|
@team_users = kaminari_paginate(@team_users)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ class Organizations::TeamsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@is_admin = can_edit_org?
|
||||||
|
@is_member = @team.is_member?(current_user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -78,6 +78,10 @@ class Organization < Owner
|
||||||
self.create!(login: name, gitea_token: gitea_token)
|
self.create!(login: name, gitea_token: gitea_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_member?(user_id)
|
||||||
|
organization_users.where(user_id: user_id).present?
|
||||||
|
end
|
||||||
|
|
||||||
def is_owner?(user_id)
|
def is_owner?(user_id)
|
||||||
team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(owner)}).present?
|
team_users.joins(:team).where(user_id: user_id, teams: {authorize: %w(owner)}).present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,4 +47,8 @@ class Team < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_member?(user_id)
|
||||||
|
team_users.where(user_id: user_id).present?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
json.partial! "detail", organization: @organization
|
json.partial! "detail", organization: @organization
|
||||||
|
json.is_admin @is_admin
|
||||||
|
json.is_member @is_member
|
|
@ -0,0 +1,9 @@
|
||||||
|
json.total_count @projects.size
|
||||||
|
json.projects @projects.each do |project|
|
||||||
|
json.(project, :id, :name, :identifier, :description, :forked_count, :praises_count, :forked_from_project_id)
|
||||||
|
json.mirror_url project.repository&.mirror_url
|
||||||
|
json.type project.numerical_for_project_type
|
||||||
|
json.praised project.praised_by?(current_user)
|
||||||
|
json.last_update_time render_unix_time(project.updated_on)
|
||||||
|
json.time_ago time_from_now(project.updated_on)
|
||||||
|
end
|
|
@ -1,6 +1,7 @@
|
||||||
json.id team_project.id
|
json.id team_project.id
|
||||||
json.project do
|
json.project do
|
||||||
json.owner_name team_project&.project&.owner&.login
|
json.owner_name team_project&.project&.owner&.login
|
||||||
|
json.owner_image_url url_to_avatar(team_project&.project&.owner)
|
||||||
json.name team_project&.project&.name
|
json.name team_project&.project&.name
|
||||||
json.identifier team_project&.project&.identifier
|
json.identifier team_project&.project&.identifier
|
||||||
end
|
end
|
|
@ -1 +1,3 @@
|
||||||
json.partial! "detail", team: @team, organization: @organization
|
json.partial! "detail", team: @team, organization: @organization
|
||||||
|
json.is_admin @is_admin
|
||||||
|
json.is_member @is_member
|
|
@ -120,7 +120,11 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :team_projects, only: [:index, :create, :destroy] do ;end
|
resources :team_projects, only: [:index, :create, :destroy] do ;end
|
||||||
end
|
end
|
||||||
resources :projects, only: [:index]
|
resources :projects, only: [:index] do
|
||||||
|
collection do
|
||||||
|
get :search
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue