Skip to content

Commit f2db055

Browse files
committed
Simplify people ciontroller by leaning on resource controller authorization
1 parent 90e287d commit f2db055

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

app/controllers/better_together/people_controller.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
module BetterTogether
44
class PeopleController < FriendlyResourceController # rubocop:todo Style/Documentation
55
before_action :set_person, only: %i[show edit update destroy]
6-
before_action :authorize_person, only: %i[show edit update destroy]
7-
after_action :verify_authorized, except: :index
86

97
# GET /people
108
def index
11-
authorize resource_class
12-
@people = policy_scope(resource_class.with_translations)
9+
@people = resource_collection
1310
end
1411

1512
# GET /people/1
@@ -57,12 +54,7 @@ def destroy
5754
redirect_to people_url, notice: 'Person was successfully deleted.', status: :see_other
5855
end
5956

60-
private
61-
62-
# Adds a policy check for the person
63-
def authorize_person
64-
authorize @person
65-
end
57+
protected
6658

6759
def id_param
6860
params[:id] || params[:person_id]
@@ -97,7 +89,7 @@ def resource_class
9789
end
9890

9991
def resource_collection # rubocop:todo Metrics/MethodLength
100-
resource_class.with_translations.with_attached_profile_image.with_attached_cover_image.includes(
92+
policy_scope(resource_class.with_translations.with_attached_profile_image.with_attached_cover_image.includes(
10193
contact_detail: %i[phone_numbers email_addresses website_links addresses social_media_accounts],
10294
person_platform_memberships: {
10395
joinable: [:string_translations, { profile_image_attachment: :blob }],
@@ -107,7 +99,7 @@ def resource_collection # rubocop:todo Metrics/MethodLength
10799
joinable: [:string_translations, { profile_image_attachment: :blob }],
108100
role: [:string_translations]
109101
}
110-
)
102+
))
111103
end
112104
end
113105
end

app/controllers/better_together/resource_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ResourceController < ApplicationController
66
before_action :set_resource_instance, only: %i[show edit update destroy]
77
before_action :authorize_resource, only: %i[show edit update destroy]
88
before_action :authorize_resource_class, only: %i[index]
9+
after_action :verify_authorized, except: :index
910

1011
helper_method :resource_class
1112
helper_method :resource_collection

0 commit comments

Comments
 (0)