From 2aae7358414ac0daca2b068c05f260c612adf96b Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 24 Apr 2019 10:07:06 +0200 Subject: [PATCH 2/5] adapters: add a separate method to remove superuser flags So that we can override it somewhere else. --- mellon/adapters.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mellon/adapters.py b/mellon/adapters.py index 460d1a6..2aacdf1 100644 --- a/mellon/adapters.py +++ b/mellon/adapters.py @@ -185,7 +185,6 @@ class DefaultAdapter(object): superuser_mapping = utils.get_setting(idp, 'SUPERUSER_MAPPING') if not superuser_mapping: return - attribute_set = False for key, values in superuser_mapping.items(): if key in saml_attributes: if not isinstance(values, (tuple, list)): @@ -199,16 +198,17 @@ class DefaultAdapter(object): if not (user.is_staff and user.is_superuser): user.is_staff = True user.is_superuser = True - attribute_set = True + user.save() self.logger.info('flag is_staff and is_superuser added to user %s', user) break else: - if user.is_superuser or user.is_staff: - user.is_staff = False - user.is_superuser = False - self.logger.info('flag is_staff and is_superuser removed from user %s', user) - attribute_set = True - if attribute_set: + self.remove_superuser(user) + + def remove_superuser(self, user): + if user.is_superuser or user.is_staff: + user.is_staff = False + user.is_superuser = False + self.logger.info('flag is_staff and is_superuser removed from user %s', user) user.save() def provision_groups(self, user, idp, saml_attributes): -- 2.20.1