Beispiel #1
0
 def get_group_list(self):
     if self.auth.account.account_type == 'senior_admin':
         return ModelGroup.select()
     else:
         group_maps = ModelMap.select().where(
             ModelMap.account_id == self.auth.account.account_id)
         ids = []
         for group_map in group_maps:
             ids.append(group_map.group_id)
         return ModelGroup.select().where(ModelGroup.group_id << ids)
Beispiel #2
0
 def get_group_list(self):
     if self.auth.account.account_type == 'senior_admin':
         return ModelGroup.select()
     else:
         group_maps = ModelMap.select().where(
             ModelMap.account_id == self.auth.account.account_id
         )
         ids = []
         for group_map in group_maps:
             ids.append(group_map.group_id)
         return ModelGroup.select().where(ModelGroup.group_id << ids)
Beispiel #3
0
    def delete(self, member_id):
        try:
            map = self.get_map(member_id)
            account = self.get_account(map.account_id)
        except peewee.DoesNotExist:
            abort(404, message="groupmember does not exist")

        # make sure logged in user has perms
        if self.auth.account.account_type != 'senior_admin':
            # check they are a member and is_admin is 1
            try:
                mymap = ModelMap.get(
                    ModelMap.group_id == map.group_id,
                    ModelMap.account_id == self.auth.account.account_id)
                if mymap.is_admin != 1:
                    abort(403)
            except peewee.DoesNotExist:
                abort(403)

        try:
            # FIXME need to delete domain maps when in place
            map.delete_instance()

            # Log change
            group = ModelGroup.get(ModelGroup.group_id == map.group_id)
            self.dns_log(0, ("Removed " + account.first_name + " " +
                             account.last_name + " from group " + group.name))
        except:
            abort(400, message="unable to delete groupmember")
        return {'status': 'ok'}
Beispiel #4
0
    def get_group(self, group_id):
        if self.auth.account.account_type != 'senior_admin':
            # DoesNotExist will be raised if map doesn't exist
            group_map = ModelMap.get(
                ModelMap.account_id == self.auth.account.account_id,
                ModelMap.group_id == group_id)

        return ModelGroup.get(ModelGroup.group_id == group_id)
Beispiel #5
0
    def post(self):
        group_id = request.form.get('group_id')
        account_id = request.form.get('account_id')
        is_admin = request.form.get('is_admin', 0)

        # Handle params
        if group_id is None:
            abort(400, message="'group_id' parameter is required")
        if account_id is None:
            abort(400, message="'account_id' parameter is required")
        if str(is_admin) != "1" and str(is_admin) != "0":
            abort(400, message="'is_admin' must be 1 or 0")
        is_admin = int(is_admin)

        # Verify user
        try:
            account = self.get_account(account_id)
        except peewee.DoesNotExist:
            abort(400, message="Account does not exist")

        if account.status != "active":
            abort(400, message="Account is not active")

        # Make sure map doesn't exist
        try:
            map = self.get_map(account_id, group_id)
            abort(400, message="Account is already a group member")
        except peewee.DoesNotExist:
            pass

        # make sure logged in user has perms
        if self.auth.account.account_type != 'senior_admin':
            # check they are a member and is_admin is 1
            try:
                mymap = self.get_map(
                    self.auth.account.account_id,
                    group_id
                )
                if mymap.is_admin != 1:
                    abort(403)
            except peewee.DoesNotExist:
                abort(403)

        # Add map
        newmap = self.create_map(account_id, group_id, is_admin)
        formatted = newmap.format_member(newmap, account)

        # Log change
        group = ModelGroup.get(ModelGroup.group_id == group_id)
        self.dns_log(
            0,
            (
                "Added " + account.first_name + " " + account.last_name +
                " to group " + group.name
            )
        )

        return {'status': 'ok', 'groupmember': formatted}, 201
Beispiel #6
0
    def get_group(self, group_id):
        if self.auth.account.account_type != 'senior_admin':
            # DoesNotExist will be raised if map doesn't exist
            group_map = ModelMap.get(
                ModelMap.account_id == self.auth.account.account_id,
                ModelMap.group_id == group_id
            )

        return ModelGroup.get(ModelGroup.group_id == group_id)
    def test_format_map(self):
        domain = Domain()
        domain.domain_id = 252
        domain.domain = "example.com"

        group = Group()
        group.group_id = 252
        group.name = "Test Group 1"

        map = DomainGroupMap()
        map.map_id = 1
        map.group_id = group
        map.domain_id = domain
        map.permissions = 7

        formatted = map.format_map(map)
        self.assertTrue(formatted["can_read"])
        self.assertTrue(formatted["can_write"])
        self.assertTrue(formatted["can_delete"])
        self.assertEquals(formatted["map_id"], map.map_id)
        self.assertEquals(formatted["group"], map.group_id.to_clean_dict())
        self.assertEquals(formatted["domain"], map.domain_id.to_clean_dict())
Beispiel #8
0
 def get_group(self, group_id):
     return ModelGroup.get(
         ModelGroup.group_id == group_id
     )
Beispiel #9
0
    def create_group(self, name):
        group = ModelGroup()
        group.name = name
        group.save()

        return group
Beispiel #10
0
    def create_group(self, name):
        group = ModelGroup()
        group.name = name
        group.save()

        return group
Beispiel #11
0
 def get_group(self, group_id):
     return ModelGroup.get(ModelGroup.group_id == group_id)