[FIX]
This commit is contained in:
parent
2434ca9681
commit
c278ed1863
|
@ -680,6 +680,14 @@ class ApplicationController < ActionController::Base
|
||||||
relation.page(page).per(limit)
|
relation.page(page).per(limit)
|
||||||
end
|
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)
|
def strf_time(time)
|
||||||
time.blank? ? '' : time.strftime("%Y-%m-%d %H:%M:%S")
|
time.blank? ? '' : time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,8 +4,19 @@ class Organizations::BaseController < ApplicationController
|
||||||
def load_organization
|
def load_organization
|
||||||
@organization = Organization.find_by(login: params[:id]) || Organization.find_by(id: params[:id])
|
@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?
|
render_not_found if @organization.nil?
|
||||||
|
|
||||||
@organization
|
@organization
|
||||||
end
|
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
|
end
|
|
@ -1,16 +1,21 @@
|
||||||
class Organizations::OrganizationsController < Organizations::BaseController
|
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 :convert_base64_image!, only: [:create, :update]
|
||||||
before_action :load_organization, only: [:update, :destroy]
|
before_action :load_organization, only: [:show, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if current_user.logged?
|
if current_user.logged?
|
||||||
@organizations = Organization.with_visibility(%w(common limited)) +
|
@organizations = Organization.with_visibility(%w(common limited)) +
|
||||||
Organization.with_visibility("privacy").joins(:organization_users).where(organization_users: {user_id: current_user.id})
|
Organization.with_visibility("privacy").joins(:organization_users).where(organization_users: {user_id: current_user.id})
|
||||||
|
kaminary_array_paginate(@organizations)
|
||||||
else
|
else
|
||||||
@organizations = Organization.with_visibility("common")
|
@organizations = Organization.with_visibility("common")
|
||||||
|
kaminari_paginate(@organizations)
|
||||||
end
|
end
|
||||||
kaminary_array_paginate(@organizations)
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -11,9 +11,9 @@ class Organizations::CreateService < ApplicationService
|
||||||
Rails.logger.info("######params #{params}######")
|
Rails.logger.info("######params #{params}######")
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@organization = Organization.build(params[:name])
|
@organization = Organization.build(params[:name])
|
||||||
org_extension = OrganizationExtension.build(@organization.id, params[:description], params[:website],
|
org_extension = OrganizationExtension.build(@organization.id, description, website,
|
||||||
params[:location], params[:repo_admin_change_team_access],
|
location, repo_admin_change_team_access,
|
||||||
params[:visibility], params[:max_repo_creation])
|
visibility, max_repo_creation)
|
||||||
team = Team.build_owner(@organization.id)
|
team = Team.build_owner(@organization.id)
|
||||||
TeamUnit.build_owner(@organization.id, team.id)
|
TeamUnit.build_owner(@organization.id, team.id)
|
||||||
OrganizationUser.build(@organization.id, user.id, true)
|
OrganizationUser.build(@organization.id, user.id, true)
|
||||||
|
@ -25,4 +25,28 @@ class Organizations::CreateService < ApplicationService
|
||||||
end
|
end
|
||||||
@organization
|
@organization
|
||||||
end
|
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
|
end
|
|
@ -0,0 +1 @@
|
||||||
|
json.partial! "detail", organization: @organization
|
Loading…
Reference in New Issue