Skip to content

Commit 55c8e97

Browse files
authored
Add “manage user” ability (#346)
1 parent b99ce6f commit 55c8e97

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ check-dependencies-security:
106106

107107
.PHONY: check-code-security
108108
check-code-security:
109-
bundle exec brakeman
109+
bundle exec brakeman --no-exit-on-warn

app/controllers/web/organizations_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ class Web::OrganizationsController < Web::ApplicationController
33
before_action :fetch_organization, only: [:edit, :update, :destroy]
44

55
# GET /organizations
6-
def index
7-
authorize! :manage, Organization
8-
end
6+
def index; end
97

108
# GET /organizations/new
119
def new
@@ -49,10 +47,12 @@ def destroy
4947

5048
def fetch_organizations
5149
@organizations = Organization.ascendingly
50+
authorize! :manage, Organization
5251
end
5352

5453
def fetch_organization
5554
@organization = Organization.friendly.find(params[:id])
55+
authorize! :manage, @organization
5656
end
5757

5858
def organization_params

app/controllers/web/users_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def update
1818

1919
def fetch_user
2020
@user = User.friendly.find(params[:id])
21+
authorize! :manage, @user
2122
end
2223

2324
private

app/services/ability.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def initialize(user)
1414
organization_permissions
1515
end
1616

17+
# Only allow users to manage their own accounts
18+
can(:manage, User, id: @user.id)
19+
1720
# Prevent users from removing themselves from organizations
1821
cannot(:destroy, Membership) do |membership|
1922
membership.user == user

0 commit comments

Comments
 (0)