From f0a00d02d30509b3b56026e9e4d119bce3a82d99 Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 6 Oct 2020 00:24:41 +0200 Subject: Add instance methods The Agency class can `grant` and `revoke` roles for a given Agent and User. Since it is primarily used in context of both an Agent and User, we add convenience methods so that one can grant or revoke a role simply by passing the desired role to the instance. --- app/models/agency.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/models/agency.rb b/app/models/agency.rb index fe81687..03e6e5a 100644 --- a/app/models/agency.rb +++ b/app/models/agency.rb @@ -19,4 +19,14 @@ class Agency < ApplicationRecord r&.public_send("#{role}=", false) && r&.save end end + + # Grant role to current user in current agent + def grant(role) + self.class.grant(agent, user, role) + end + + # Revoke role from current user in current agent + def revoke(role) + self.class.revoke(agent, user, role) + end end -- cgit v1.2.3