From 87820da7d0aba6ba7b47299626cfad2809d05bd2 Mon Sep 17 00:00:00 2001 From: kakwa Date: Sat, 16 May 2015 20:03:34 +0200 Subject: [PATCH] implementing various methods: * get_groups (get_groups of a role) * is_admin (determine if ldapcherry admin) * get_backends (get list of role backends) --- ldapcherry/roles.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ldapcherry/roles.py b/ldapcherry/roles.py index 47c99a7..438fcd5 100644 --- a/ldapcherry/roles.py +++ b/ldapcherry/roles.py @@ -82,10 +82,11 @@ class Roles: for backend in role['backends']: self.backends.add(backend) - #if 'LC_admins' in role and role['LC_admins']: - # self.admin_roles.append(roleid) + # Create the list of roles which are ldapcherry admins + if 'LC_admins' in role and role['LC_admins']: + self.admin_roles.append(roleid) - # Create the nested groups + # Create the nested groups for roleid in self.roles_raw: role = self.roles_raw[roleid] @@ -185,6 +186,17 @@ class Roles: ret['unusedgroups'] = unusedgroups return ret - def get_groups(self, roles): - """get the list of groups from roles""" - pass + def get_groups(self, role): + """get the list of groups from role""" + return self.roles_raw[role]['backends'] + + def is_admin(self, roles): + """determine from a list of roles if is ldapcherry administrator""" + for r in roles: + if r in self.admin_roles: + return True + return False + + def get_backends(self): + """return the list of backends in roles file""" + return self.backends