[ADD]组织、组织团队

This commit is contained in:
viletyy 2021-01-15 14:55:52 +08:00
parent 0c58447afb
commit 289d1877d6
7 changed files with 21 additions and 32 deletions

View File

@ -32,12 +32,19 @@ class Organizations::BaseController < ApplicationController
params[:repo_name] || params[:id] params[:repo_name] || params[:id]
end end
private def org_limited_condition
def limited_condition
@organization.organization_extension.limited? && !current_user.logged? @organization.organization_extension.limited? && !current_user.logged?
end end
def privacy_condition def org_privacy_condition
@organization.organization_extension.privacy? && @organization.organization_users.where(user_id: current_user.id).blank? @organization.organization_extension.privacy? && @organization.organization_users.where(user_id: current_user.id).blank?
end end
def team_not_found_condition
@team.team_users.where(user_id: current_user.id).blank? && !@organization.is_owner?(current_user)
end
def user_mark
params[:username] || params[:id]
end
end end

View File

@ -11,7 +11,6 @@ class Organizations::OrganizationsController < Organizations::BaseController
@organizations = Organization.from("( #{ logged_organizations_sql } UNION #{ privacy_organizations_sql } ) AS users") @organizations = Organization.from("( #{ logged_organizations_sql } UNION #{ privacy_organizations_sql } ) AS users")
else else
@organizations = Organization.with_visibility("common") @organizations = Organization.with_visibility("common")
kaminari_paginate(@organizations)
end end
@organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present? @organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present?
@organizations = @organizations.includes(:organization_extension).order("organization_extensions.#{sort_by} #{sort_direction}") @organizations = @organizations.includes(:organization_extension).order("organization_extensions.#{sort_by} #{sort_direction}")
@ -32,6 +31,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
end end
def update def update
tip_exception("您没有权限进行该操作") unless @organization.is_owner?(current_user)
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
login = @organization.login login = @organization.login
@organization.update!(login: organization_params[:name]) if organization_params[:name].present? @organization.update!(login: organization_params[:name]) if organization_params[:name].present?

View File

@ -31,4 +31,8 @@ class OrganizationUser < ApplicationRecord
def teams def teams
organization.teams.joins(:team_users).where(team_users: {user_id: user_id}) organization.teams.joins(:team_users).where(team_users: {user_id: user_id})
end end
def teams
organization.teams.joins(:team_users).where(team_users: {user_id: user_id})
end
end end

View File

@ -11,30 +11,16 @@ class Organizations::CreateService < ApplicationService
Rails.logger.info("######Organization create_service begin######") Rails.logger.info("######Organization create_service begin######")
Rails.logger.info("######params #{params}######") Rails.logger.info("######params #{params}######")
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
<<<<<<< HEAD
create_org_and_extension create_org_and_extension
create_owner_info create_owner_info
create_gitea_org create_gitea_org
sync_owner_team_gtid sync_owner_team_gtid
=======
@organization = Organization.build(params[:name])
org_extension = OrganizationExtension.build(@organization.id, description, website,
location, repo_admin_change_team_access,
visibility, max_repo_creation)
team = Team.build_owner(@organization.id)
TeamUnit.build_owner(@organization.id, team.id)
OrganizationUser.build(@organization.id, user.id, true)
TeamUser.build(@organization.id, user.id, team.id)
Gitea::Organization::CreateService.call(user.gitea_token, @organization)
>>>>>>> 38887e6... [FIX]
Rails.logger.info("######Organization create_service end######") Rails.logger.info("######Organization create_service end######")
end end
@organization @organization
end end
<<<<<<< HEAD
private private
def description def description
params[:description] params[:description]
@ -44,20 +30,8 @@ class Organizations::CreateService < ApplicationService
params[:website] params[:website]
end end
def location
params[:location]
=======
def description
params[:description].present? ? params[:description] : nil
end
def website
params[:website].present? ? params[:website] : nil
end
def location def location
params[:location].present? ? params[:location] : nil params[:location].present? ? params[:location] : nil
>>>>>>> 38887e6... [FIX]
end end
def repo_admin_change_team_access def repo_admin_change_team_access

View File

@ -65,7 +65,11 @@ class Organizations::Teams::CreateService < ApplicationService
end end
def create_gitea_team def create_gitea_team
<<<<<<< HEAD
@gitea_team = Gitea::Organization::Team::CreateService.call(org.gitea_token, org, team) @gitea_team = Gitea::Organization::Team::CreateService.call(org.gitea_token, org, team)
=======
@gitea_team = Gitea::Organization::Team::CreateService.call(user.gitea_token, org, team)
>>>>>>> 4a50873... [ADD]
end end
def sync_team_gtid def sync_team_gtid

View File

@ -4,4 +4,4 @@ json.user do
end end
json.team_names org_user.teams.pluck(:name) json.team_names org_user.teams.pluck(:name)
json.created_at org_user.created_at.strftime("%Y-%m-%d") json.created_at org_user.created_at.strftime("%Y-%m-%d")

View File

@ -2,4 +2,4 @@ json.id team_user.id
json.user do json.user do
json.partial! "organizations/user_detail", user: team_user.user json.partial! "organizations/user_detail", user: team_user.user
end end
json.created_at team_user.created_at.strftime("%Y-%m-%d") json.created_at team_user.created_at.strftime("%Y-%m-%d")