diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9d6efdcb6..7bf88abc5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/organizations/base_controller.rb b/app/controllers/organizations/base_controller.rb index d0b9594dc..346f996e7 100644 --- a/app/controllers/organizations/base_controller.rb +++ b/app/controllers/organizations/base_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index 16079bcc5..ccdb68ecc 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -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 diff --git a/app/services/organizations/create_service.rb b/app/services/organizations/create_service.rb index c0fceeb02..f09b9f833 100644 --- a/app/services/organizations/create_service.rb +++ b/app/services/organizations/create_service.rb @@ -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 \ No newline at end of file diff --git a/app/views/organizations/organizations/show.json.jbuilder b/app/views/organizations/organizations/show.json.jbuilder new file mode 100644 index 000000000..55de73daf --- /dev/null +++ b/app/views/organizations/organizations/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "detail", organization: @organization \ No newline at end of file