mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
[FIX]
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user