This commit is contained in:
viletyy 2021-01-13 15:43:30 +08:00
parent 2434ca9681
commit c278ed1863
5 changed files with 55 additions and 6 deletions

View File

@ -680,6 +680,14 @@ class ApplicationController < ActionController::Base
relation.page(page).per(limit)
end
def kaminary_array_paginate(relation)
limit = params[:limit] || params[:per_page]
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
Kaminari.paginate_array(relation).page(page).per(limit)
end
def strf_time(time)
time.blank? ? '' : time.strftime("%Y-%m-%d %H:%M:%S")
end

View File

@ -4,8 +4,19 @@ class Organizations::BaseController < ApplicationController
def load_organization
@organization = Organization.find_by(login: params[:id]) || Organization.find_by(id: params[:id])
@organization = nil if limited_condition || privacy_condition
render_not_found if @organization.nil?
@organization
end
private
def limited_condition
@organization.organization_extension.limited? && !current_user.logged?
end
def privacy_condition
@organization.organization_extension.privacy? && @organization.organization_users.where(user_id: current_user.id).blank?
end
end

View File

@ -1,16 +1,21 @@
class Organizations::OrganizationsController < Organizations::BaseController
before_action :require_login, except: [:index]
before_action :require_login, except: [:index, :show]
before_action :convert_base64_image!, only: [:create, :update]
before_action :load_organization, only: [:update, :destroy]
before_action :load_organization, only: [:show, :update, :destroy]
def index
if current_user.logged?
@organizations = Organization.with_visibility(%w(common limited)) +
Organization.with_visibility("privacy").joins(:organization_users).where(organization_users: {user_id: current_user.id})
kaminary_array_paginate(@organizations)
else
@organizations = Organization.with_visibility("common")
kaminari_paginate(@organizations)
end
kaminary_array_paginate(@organizations)
end
def show
end
def create

View File

@ -11,9 +11,9 @@ class Organizations::CreateService < ApplicationService
Rails.logger.info("######params #{params}######")
ActiveRecord::Base.transaction do
@organization = Organization.build(params[:name])
org_extension = OrganizationExtension.build(@organization.id, params[:description], params[:website],
params[:location], params[:repo_admin_change_team_access],
params[:visibility], params[:max_repo_creation])
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)
@ -25,4 +25,28 @@ class Organizations::CreateService < ApplicationService
end
@organization
end
def description
params[:description].present? ? params[:description] : nil
end
def website
params[:website].present? ? params[:website] : nil
end
def location
params[:location].present? ? params[:location] : nil
end
def repo_admin_change_team_access
params[:repo_admin_change_team_access].present? ? params[:repo_admin_change_team_access] : false
end
def visibility
params[:visibility].present? ? params[:visibility] : "common"
end
def max_repo_creation
params[:max_repo_creation].present? ? params[:max_repo_creation] : -1
end
end

View File

@ -0,0 +1 @@
json.partial! "detail", organization: @organization