Skip to content

Commit 320289b

Browse files
committed
Allow admins to see whitelisted organizations
1 parent 775b09c commit 320289b

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

app/controllers/api/v8/organizations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class OrganizationsController < Api::V8::BaseController
4848
def index
4949
orgs = Organization
5050
.visible_organizations
51-
.select { |org| org.visibility_allowed?(request) }
51+
.select { |org| org.visibility_allowed?(request, current_user) }
5252
.map { |o| { name: o.name, information: o.information, slug: o.slug, logo_path: o.logo.url, pinned: o.pinned } }
5353
authorize! :read, orgs
5454
present(orgs)

app/controllers/courses_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def assign_show_view_vars
205205

206206
def set_organization
207207
@organization = Organization.find_by!(slug: params[:organization_id])
208-
unauthorized! unless @organization.visibility_allowed?(request)
208+
unauthorized! unless @organization.visibility_allowed?(request, current_user)
209209
end
210210

211211
def set_course

app/controllers/organizations_controller.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ def index
1010
@organizations = Organization
1111
.accepted_organizations
1212
.order(ordering)
13-
.reject { |org| org.hidden? && !can?(:view_hidden_organizations, nil) || !org.visibility_allowed?(request) }
14-
@my_organizations = Organization.taught_organizations(current_user).select { |org| org.visibility_allowed?(request) }
15-
@my_organizations |= Organization.assisted_organizations(current_user).select { |org| org.visibility_allowed?(request) }
16-
@my_organizations |= Organization.participated_organizations(current_user).select { |org| org.visibility_allowed?(request) }
13+
.reject { |org| org.hidden? && !can?(:view_hidden_organizations, nil) || !org.visibility_allowed?(request, current_user) }
14+
@my_organizations = Organization.taught_organizations(current_user).select { |org| org.visibility_allowed?(request, current_user) }
15+
@my_organizations |= Organization.assisted_organizations(current_user).select { |org| org.visibility_allowed?(request, current_user) }
16+
@my_organizations |= Organization.participated_organizations(current_user).select { |org| org.visibility_allowed?(request, current_user) }
1717
@my_organizations.natsort_by!(&:name)
1818
@courses_under_initial_refresh = Course.where(initial_refresh_ready: false)
1919
@pinned_organizations = Organization
2020
.accepted_organizations
2121
.where(pinned: true)
2222
.order(ordering)
23-
.select { |org| org.visibility_allowed?(request) }
23+
.select { |org| org.visibility_allowed?(request, current_user) }
2424
.reject { |org| org.hidden? && !can?(:view_hidden_organizations, nil)}
2525
render layout: 'landing'
2626
end
@@ -100,7 +100,7 @@ def percent_completed_hash(courses, user)
100100

101101
def set_organization
102102
@organization = Organization.find_by(slug: params[:id])
103-
unauthorized! unless @organization.visibility_allowed?(request)
103+
unauthorized! unless @organization.visibility_allowed?(request, current_user)
104104
raise ActiveRecord::RecordNotFound, 'Invalid organization id' if @organization.nil?
105105
end
106106

app/models/organization.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def find_by_slug(slug)
7171
Organization.where(slug: slug)
7272
end
7373

74-
def visibility_allowed?(request)
74+
def visibility_allowed?(request, user)
75+
return true if current.user.administrator?
7576
return true unless whitelisted_ips
7677
whitelisted_ips.include?(request.remote_ip)
7778
end

0 commit comments

Comments
 (0)