Beispiel #1
0
    def dump(self, groupname=None, role_type=None):
        if not groupname:
            stmt = select(
                [
                    People.privacy, People.username, People.email,
                    People.human_name, "'user'", 's.sponsored'
                ],
                from_obj=PeopleTable.outerjoin(
                    select([
                        PersonRoles.sponsor_id,
                        func.count(PersonRoles.sponsor_id).label('sponsored')
                    ]).group_by(PersonRoles.sponsor_id).correlate().alias(
                        's'))).order_by(People.username)
        else:
            stmt = select(
                [
                    People.privacy, People.username, People.email,
                    People.human_name, PersonRoles.role_type, 's.sponsored'
                ],
                from_obj=GroupsTable.join(PersonRolesTable).join(
                    PeopleTable,
                    onclause=PeopleTable.c.id == PersonRolesTable.c.person_id).
                outerjoin(
                    select([
                        PersonRoles.sponsor_id,
                        func.count(PersonRoles.sponsor_id).label('sponsored')
                    ]).where(
                        and_(PersonRoles.group_id == Groups.id,
                             Groups.name == groupname)).group_by(
                                 PersonRoles.sponsor_id).correlate().alias('s')
                )).where(
                    and_(Groups.name == groupname,
                         PersonRoles.role_status == 'approved')).order_by(
                             People.username)

        people = []
        if identity.in_any_group(config.get('admingroup', 'accounts'),
                                 config.get('systemgroup', 'fas-system')):
            user = '******'
        elif identity.current.anonymous:
            user = '******'
        else:
            user = '******'
            username = identity.current.user_name

        for row in stmt.execute():
            person = list(row[1:])
            if not row['sponsored']:
                person[-1] = 0
            if row['privacy'] and user != 'admin' \
                    and username != row['username']:
                # filter private data
                person[2] = u''
            people.append(person)
        return dict(people=people)
Beispiel #2
0
    def dump(self, groupname=None, role_type=None):
        if not groupname:
            stmt = select([People.privacy, People.username, People.email,
                People.human_name, "'user'", 's.sponsored'],
                from_obj=PeopleTable.outerjoin(select([PersonRoles.sponsor_id,
                        func.count(PersonRoles.sponsor_id).label('sponsored')]
                        ).group_by(PersonRoles.sponsor_id
                            ).correlate().alias('s')
                )).order_by(People.username)
        else:
            stmt = select([People.privacy, People.username, People.email,
                People.human_name, PersonRoles.role_type, 's.sponsored'],
                from_obj=GroupsTable.join(PersonRolesTable).join(PeopleTable,
                    onclause=PeopleTable.c.id==PersonRolesTable.c.person_id
                    ).outerjoin(select([PersonRoles.sponsor_id,
                        func.count(PersonRoles.sponsor_id).label('sponsored')]
                        ).where(and_(
                            PersonRoles.group_id==Groups.id,
                            Groups.name==groupname)).group_by(
                                PersonRoles.sponsor_id).correlate().alias('s')
                            )).where(and_(Groups.name==groupname,
                                PersonRoles.role_status=='approved')
                                ).order_by(People.username)

        people = []
        if identity.in_any_group(config.get('admingroup', 'accounts'),
                config.get('systemgroup', 'fas-system')):
            user = '******'
        elif identity.current.anonymous:
            user = '******'
        else:
            user = '******'
            username = identity.current.user_name

        for row in stmt.execute():
            person = list(row[1:])
            if not row['sponsored']:
                person[-1] = 0
            if row['privacy'] and user != 'admin' \
                    and username != row['username']:
                # filter private data
                person[2] = u''
            people.append(person)
        return dict(people=people)
Beispiel #3
0
    def fas_client(self, data=None, force_refresh=None):
        admin_group = config.get('admingroup', 'accounts')
        system_group = config.get('systemgroup', 'fas-system')
        thirdparty_group = config.get('thirdpartygroup', 'thirdparty')

        privs = {
            'admin': False,
            'system': False,
            'thirdparty': False,
        }

        if identity.in_group(admin_group):
            privs['admin'] = privs['system'] = privs['thirdparty'] = True
        elif identity.in_group(system_group):
            privs['system'] = privs['thirdparty'] = True
        elif identity.in_group(thirdparty_group):
            privs['thirdparty'] = True

        if data == 'group_data':
            groups = None
            if not force_refresh:
                groups = mc.get('group_data')
            if not groups:
                groups = {}
                groupjoin = [
                    GroupsTable.outerjoin(
                        PersonRolesTable,
                        PersonRolesTable.c.group_id == GroupsTable.c.id)
                ]

                group_query = select([
                    GroupsTable.c.id, GroupsTable.c.name,
                    GroupsTable.c.group_type, PersonRolesTable.c.person_id,
                    PersonRolesTable.c.role_status,
                    PersonRolesTable.c.role_type
                ],
                                     from_obj=groupjoin)

                results = group_query.execute()

                for id, name, group_type, person_id, role_status, role_type in results:
                    if name not in groups:
                        groups[name] = {
                            'id': id,
                            'administrators': [],
                            'sponsors': [],
                            'users': [],
                            'type': group_type
                        }

                    if role_status != 'approved':
                        continue

                    if role_type == 'administrator':
                        groups[name]['administrators'].append(person_id)
                    elif role_type == 'sponsor':
                        groups[name]['sponsors'].append(person_id)
                    elif role_type == 'user':
                        groups[name]['users'].append(person_id)

                # Save cache - valid for 15 minutes
                mc.set('group_data', groups, 900)

            return dict(success=True, data=groups)
        elif data == 'user_data':
            people = {}
            people_list = select([
                PeopleTable.c.id, PeopleTable.c.username,
                PeopleTable.c.password, PeopleTable.c.human_name,
                PeopleTable.c.ssh_key, PeopleTable.c.email,
                PeopleTable.c.privacy, PeopleTable.c.alias_enabled
            ], PeopleTable.c.status == 'active').execute()
            for id, username, password, human_name, ssh_key, email, privacy, alias_enabled in people_list:
                people[id] = {
                    'username': username,
                    'password': password,
                    'human_name': human_name,
                    'ssh_key': ssh_key,
                    'email': email,
                    'alias_enabled': alias_enabled
                }

                if privacy:
                    # If they have privacy enabled, set their human_name to
                    # their username
                    people[id]['human_name'] = username

                if not privs['system']:
                    people[id]['password'] = '******'
                if not privs['thirdparty']:
                    people[id]['ssh_key'] = ''
            return dict(success=True, data=people)
        return dict(success=False, data={})
Beispiel #4
0
    def fas_client(self, data=None, force_refresh=None):
        admin_group = config.get('admingroup', 'accounts')
        system_group = config.get('systemgroup', 'fas-system')
        thirdparty_group = config.get('thirdpartygroup', 'thirdparty')

        privs = {
            'admin': False,
            'system': False,
            'thirdparty': False,
        }

        if identity.in_group(admin_group):
            privs['admin'] = privs['system'] = privs['thirdparty'] = True
        elif identity.in_group(system_group):
            privs['system'] = privs['thirdparty'] = True
        elif identity.in_group(thirdparty_group):
            privs['thirdparty'] = True

        if data == 'group_data':
            groups = None
            if not force_refresh:
                groups = mc.get('group_data')
            if not groups:
                groups = {}
                groupjoin = [GroupsTable.outerjoin(PersonRolesTable,
                    PersonRolesTable.c.group_id == GroupsTable.c.id)]

                group_query = select([GroupsTable.c.id, GroupsTable.c.name,
                    GroupsTable.c.group_type, PersonRolesTable.c.person_id,
                    PersonRolesTable.c.role_status, PersonRolesTable.c.role_type],
                    from_obj=groupjoin)

                results = group_query.execute()

                for id, name, group_type, person_id, role_status, role_type in results:
                    if name not in groups:
                        groups[name] = {
                            'id': id,
                            'administrators': [],
                            'sponsors': [],
                            'users': [],
                            'type': group_type
                        }

                    if role_status != 'approved':
                        continue

                    if role_type == 'administrator':
                        groups[name]['administrators'].append(person_id)
                    elif role_type == 'sponsor':
                        groups[name]['sponsors'].append(person_id)
                    elif role_type == 'user':
                        groups[name]['users'].append(person_id)

                # Save cache - valid for 15 minutes
                mc.set('group_data', groups, 900)

            return dict(success=True, data=groups)
        elif data == 'user_data':
            people = {}
            people_list = select([
                PeopleTable.c.id,
                PeopleTable.c.username,
                PeopleTable.c.password,
                PeopleTable.c.human_name,
                PeopleTable.c.ssh_key,
                PeopleTable.c.email,
                PeopleTable.c.privacy,
                PeopleTable.c.alias_enabled
                ], PeopleTable.c.status == 'active').execute()
            for id, username, password, human_name, ssh_key, email, privacy, alias_enabled in people_list:
                people[id] = {
                    'username': username,
                    'password': password,
                    'human_name': human_name,
                    'ssh_key': ssh_key,
                    'email': email,
                    'alias_enabled': alias_enabled
                }

                if privacy:
                    # If they have privacy enabled, set their human_name to
                    # their username
                    people[id]['human_name'] = username

                if not privs['system']:
                    people[id]['password'] = '******'
                if not privs['thirdparty']:
                    people[id]['ssh_key'] = ''
            return dict(success=True, data=people)
        return dict(success=False, data={})