From ff83c217c82788d784f7c7b213e73471d8fd7a28 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 5 Apr 2022 12:28:22 +0200 Subject: [PATCH] Database: revoke role method --- src/db_models.rb | 6 +++++- src/lib/database.rb | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/db_models.rb b/src/db_models.rb index 1fa9982..0bb4296 100644 --- a/src/db_models.rb +++ b/src/db_models.rb @@ -251,7 +251,11 @@ class User_Role_relation < EntityModel end def self.revoke_role(user_id, role_id) - # TODO: revoke role + user = User.find_by_id user_id + + if user.role_ids.include?(role_id) then + self.delete "role_id = ? AND user_id = ?", role_id, user_id + end end def self.get_user_roles_ids(user_id) diff --git a/src/lib/database.rb b/src/lib/database.rb index 14b9b45..c77931c 100644 --- a/src/lib/database.rb +++ b/src/lib/database.rb @@ -86,8 +86,8 @@ class EntityModel return newid, resp end - def self.delete(id) - self.query "DELETE FROM #{self.name} WHERE id = ?", id + def self.delete(filter="", *args) + self.query "DELETE FROM #{self.name} #{self.apply_filter(filter)}", *args end def self.set(attr, data, filter="") # slower but more lazy