Exemple #1
0
    def get(self, image=None):
        response = {}
        if image:
            groups = Group.objects(image=None)
        else:
            groups = Group.objects(image__ne=None)

        for group in groups:
            response[group.name] = {
                'full_name': group.full_name,
                'image': str(group.image.grid_id) if group.image.grid_id else None
                }

        return response
Exemple #2
0
    def put(self, name=None):
        if not name:
            abort(404, message="A group name is required.")

        args = parser.parse_args()
        group = Group.objects(name__iexact=name).first()

        if not group:
            abort(404, message="A group with that name does not exist.")

        group.full_name=args['full_name']

        if args['image'] and validate_file(args['image'].filename):
            if group.image:
                group.image.replace(args['image'], content_type=args['image'].content_type)
            else:
                group.image.put(args['image'], content_type=args['image'].content_type)

        response = {
            'name': group.name,
            'full_name': group.full_name,
            'image': str(group.image.grid_id) if group.image.grid_id else None
        }

        group.save()

        return response
Exemple #3
0
    def post(self):
        args = auth_parser.parse_args()
        name = args['username']
        password = args['password']

        group = Group.objects(name__iexact=name).first()

        if group:
            if bcrypt.check_password_hash(group.password, password):
                return {'Success': 'Group has been successfully authenticated.'}

        return {'Error': 'Invalid username or password.'}, 401
Exemple #4
0
    def get(self, fullname=None):
        group = Group.objects(full_name__iexact=fullname).first()

        if not group:
            abort(404, message="A group with that name does not exist.")

        response = {
            'name': group.name,
            'full_name': group.full_name,
            'image': str(group.image.grid_id) if group.image.grid_id else None
        }

        return response
Exemple #5
0
    def delete(self, name=None):
        if not name:
            abort(404, message="A group name is required.")
        group = Group.objects(name__iexact=name).first()

        if not group:
            abort(404, message="A group with that name does not exist.")

        if group.image:
            group.image.delete()

        group.delete()

        return {'success': "Group successfully deleted."}
Exemple #6
0
    def get(self, name=None):
        response = {}
        if name:
            group = Group.objects(name__iexact=name).first()

            if not group:
                abort(404, message="A group with that name does not exist.")

            response = {
                'name': group.name,
                'full_name': group.full_name,
                'image': str(group.image.grid_id) if group.image.grid_id else None
            }
        else:
            groups = Group.objects()

            for group in groups:
                response[group.name] = {
                    'full_name': group.full_name,
                    'image': str(group.image.grid_id) if group.image.grid_id else None

                }

        return response
Exemple #7
0
    def get(self, name=None):
        if not name:
            abort(404, message="A group name is required.")

        group = Group.objects(name__iexact=name).first()

        if not group:
            abort(404, message="A group with that name does not exist.")

        response = {'members': {}}
        if group.members:
            for member in group.members:
                response['members'][member.id_no] = {
                    'name': member.name,
                }

        return response
Exemple #8
0
    def post(self):
        args = parser.parse_args()
        group = Group.objects(name__iexact=args['name']).first()
        if group:
            abort(409, message="A group with that name already exist.")

        group = Group(name=args['name'], full_name=args['full_name'])
        group.password = bcrypt.generate_password_hash(args['password'])

        if args['image'] and validate_file(args['image'].filename):
            group.image.put(args['image'], content_type=args['image'].content_type)

        group.save()

        response = {
            'name': group.name,
            'full_name': group.full_name,
            'image': str(group.image.grid_id) if group.image.grid_id else None
        }

        return response, 201
Exemple #9
0
def group_member_processes(process, member_id_no=None, group_name=None):
    if not member_id_no:
        abort(404, message="An id number is required.")

    if not group_name:
        abort(404, message="A group name is required.")

    individual = Individual.objects(id_no=member_id_no).first()
    group = Group.objects(name__iexact=group_name).first()

    if not individual:
        abort(404, message="An individual with that id number does not exist.")

    if not group:
        abort(404, message="A group with that name does not exist.")

    if process == 'insert':
        individual.update(add_to_set__groups=[group])
        group.update(add_to_set__members=[individual])
    elif process == 'delete':
        individual.update(pull__groups=group)
        group.update(pull__members=individual)