예제 #1
0
파일: group.py 프로젝트: unioslo/cerebrum
 def put(self, name, member_id):
     """ Add member to group. """
     group = find_group(name)
     member = find_entity(member_id)
     if not group.has_member(member.entity_id):
         group.add_member(member.entity_id)
     return {
         'member_type': member.entity_type,
         # id for the href builder, won't be shown in output
         'id': utils.get_entity_name(member) or member.entity_id,
         'member_id': member.entity_id,
         'member_name': utils.get_entity_name(member),
     }
예제 #2
0
파일: group.py 프로젝트: unioslo/cerebrum
 def get(self, name, member_id):
     """ Check if member exists in group. """
     group = find_group(name)
     member = find_entity(member_id)
     if not group.has_member(member.entity_id):
         abort(404, "No such member in group")
     return {
         'member_type': member.entity_type,
         # id for the href builder, won't be shown in output
         'id': utils.get_entity_name(member) or member.entity_id,
         'member_id': member.entity_id,
         'member_name': utils.get_entity_name(member),
     }
예제 #3
0
 def put(self, name, member_id):
     """ Add member to group. """
     name = name.encode(db.encoding)
     group = find_group(name)
     member = find_entity(member_id)
     if not group.has_member(member.entity_id):
         group.add_member(member.entity_id)
     return {
         'member_type': member.entity_type,
         # id for the href builder, won't be shown in output
         'id': utils.get_entity_name(member) or member.entity_id,
         'member_id': member.entity_id,
         'member_name': utils.get_entity_name(member),
     }
예제 #4
0
 def get(self, name, member_id):
     """ Check if member exists in group. """
     name = name.encode(db.encoding)
     group = find_group(name)
     member = find_entity(member_id)
     if not group.has_member(member.entity_id):
         abort(404, "No such member in group")
     return {
         'member_type': member.entity_type,
         # id for the href builder, won't be shown in output
         'id': utils.get_entity_name(member) or member.entity_id,
         'member_id': member.entity_id,
         'member_name': utils.get_entity_name(member),
     }
예제 #5
0
    def get(self, name):
        """Get account information."""
        ac = find_account(name)

        try:
            primary_email = ac.get_primary_mailaddress()
        except Errors.NotFoundError:
            primary_email = None
        owner_name = utils.get_entity_name(
            utils.get_entity(ac.owner_id, idtype='entity_id'))
        return {
            'name': ac.account_name,
            'id': ac.entity_id,
            'owner': {
                'id': ac.owner_id,
                'type': ac.owner_type,
                'name': owner_name,
                'href': utils.href_from_entity_type(entity_type=ac.owner_type,
                                                    entity_id=ac.owner_id,
                                                    entity_name=owner_name),
            },
            'created_at': ac.created_at,
            'expire_date': ac.expire_date,
            'contexts': [row['spread'] for row in ac.get_spread()],
            'primary_email': primary_email,
            'active': not (ac.is_expired() or ac.is_deleted()),
        }
예제 #6
0
 def put(self, name, member_id):
     """ Add member to group. """
     group = find_group(name)
     member = find_entity(member_id)
     if not group.has_member(member.entity_id):
         group.add_member(member.entity_id)
     name = utils.get_entity_name(member)
     return {
         'member_type':
         member.entity_type,
         # id for the href builder, won't be shown in output
         'id':
         utils.get_entity_name(member) or member.entity_id,
         'member_id':
         member.entity_id,
         'member_name':
         name,
         'href':
         utils.href_from_entity_type(entity_type=member.entity_type,
                                     entity_id=member.entity_id,
                                     entity_name=name),
     }
예제 #7
0
 def get(self, name, member_id):
     """ Check if member exists in group. """
     group = find_group(name)
     member = find_entity(member_id)
     if not group.has_member(member.entity_id):
         abort(404, "No such member in group")
     name = utils.get_entity_name(member)
     return {
         'member_type':
         member.entity_type,
         # id for the href builder, won't be shown in output
         'id':
         utils.get_entity_name(member) or member.entity_id,
         'member_id':
         member.entity_id,
         'member_name':
         name,
         'href':
         utils.href_from_entity_type(entity_type=member.entity_type,
                                     entity_id=member.entity_id,
                                     entity_name=name),
     }
예제 #8
0
파일: person.py 프로젝트: chrnux/cerebrum
    def get(self, id):
        """Get the accounts of a person."""
        pe = find_person(id)

        accounts = list()
        primary_account_id = pe.get_primary_account()
        for row in pe.get_accounts():
            account_name = utils.get_entity_name(row['account_id'])
            accounts.append({
                'href': url_for('.account', id=account_name),
                'id': account_name,
                'primary': (row['account_id'] == primary_account_id),
            })

        return {'accounts': accounts}
예제 #9
0
파일: person.py 프로젝트: unioslo/cerebrum
    def get(self, id):
        """Get the accounts of a person."""
        pe = find_person(id)

        accounts = list()
        primary_account_id = pe.get_primary_account()
        for row in pe.get_accounts():
            account_name = utils.get_entity_name(row['account_id'])
            accounts.append({
                'href': url_for('.account', name=account_name),
                'id': row['account_id'],
                'name': account_name,
                'primary': (row['account_id'] == primary_account_id),
            })

        return {'accounts': accounts}
예제 #10
0
파일: person.py 프로젝트: unioslo/cerebrum
    def get(self, id):
        """Get the accounts of a person."""
        pe = find_person(id)

        accounts = list()
        primary_account_id = pe.get_primary_account()
        for row in pe.get_accounts():
            account_name = utils.get_entity_name(row["account_id"])
            accounts.append(
                {
                    "href": url_for(".account", id=account_name),
                    "id": account_name,
                    "primary": (row["account_id"] == primary_account_id),
                }
            )

        return {"accounts": accounts}
예제 #11
0
 def get(self, name):
     """ Get admins for this group. """
     group = find_group(name)
     roles = GroupRoles(db.connection)
     moderators = []
     for admin in roles.search_admins(group_id=group.entity_id):
         admin_name = utils.get_entity_name(admin['admin_id'])
         moderators.append({
             'type':
             admin['admin_type'],
             'id':
             admin['admin_id'],
             'name':
             admin_name,
             'roles':
             'Group-admin',
             'href':
             utils.href_from_entity_type(admin['moderator_type'],
                                         admin['moderator_id'], admin_name)
         })
     return moderators
예제 #12
0
파일: account.py 프로젝트: unioslo/cerebrum
    def get(self, name):
        """Get account information."""
        ac = find_account(name)

        try:
            primary_email = ac.get_primary_mailaddress()
        except Errors.NotFoundError:
            primary_email = None
        return {
            'name': ac.account_name,
            'id': ac.entity_id,
            'owner': {
                'id': ac.owner_id,
                'type': ac.owner_type,
                'name': utils.get_entity_name(
                    utils.get_entity(ac.owner_id, idtype='entity_id')),
            },
            'created_at': ac.created_at,
            'expire_date': ac.expire_date,
            'contexts': [row['spread'] for row in ac.get_spread()],
            'primary_email': primary_email,
            'active': not (ac.is_expired() or ac.is_deleted()),
        }