diff --git a/backend/actions/lib/acls/editor.py b/backend/actions/lib/acls/editor.py index eebb4d9..2cd1347 100644 --- a/backend/actions/lib/acls/editor.py +++ b/backend/actions/lib/acls/editor.py @@ -3,19 +3,65 @@ Module d'édition des acls """ from os.path import isdir +import shlex from pyeole.process import system_out +SYSTEM_THRESHOLD = 1000 + +def getent(db, sys_users=False): + """ + Return getent for user related db + :param db: getent db passwd or group + :type db: 'passwd' | 'group' + :param sys_users: wether to gather system users + :type sys_users: boolean + """ + db_list = [] + if db in ['passwd', 'group']: + cmd = shlex.split('getent {0}'.format(db)) + code, res, err = system_out(cmd) + if code == 0: + res = [r for r in res.split('\n') if r != ''] + if sys_users is True: + db_list.extend([r.split(':')[0] for r in res]) + else: + db_list.extend([r.split(':')[0] for r in res + if int(r.split(':')[2]) >= SYSTEM_THRESHOLD]) + return db_list + +def getent_groups(): + """ + Return local groups list + """ + return getent('group') + +def getent_users(): + """ + Return local users list + """ + return getent('passwd') + try: from horus.backend import get_groups as list_groups from horus.backend import get_users module = 'horus' except ImportError: - from scribe.eolegroup import Group - list_groups = Group().get_groups - from scribe.enseignants import Enseignant - from scribe.eleves import Eleve - from scribe.administratifs import Administratif - module = 'scribe' + try: + from scribe.eolegroup import Group + list_groups = Group().get_groups + from scribe.enseignants import Enseignant + from scribe.eleves import Eleve + from scribe.administratifs import Administratif + module = 'scribe' + except ImportError: + try: + from esbl.backend import get_groups as list_groups + from esbl.backend import get_users + module = 'horus' + except ImportError: + list_groups = getent_groups + get_users = getent_users + module = 'horus' from ead2.backend.actions.lib.widgets import main, form, ajax from ead2.backend.actions.lib.acls.filesystem import deformat_path_from_html, \