Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission field validation in Create Group API #115

Open
anshsrtv opened this issue Jun 3, 2020 · 1 comment
Open

Permission field validation in Create Group API #115

anshsrtv opened this issue Jun 3, 2020 · 1 comment
Labels
available No one has claimed the issue (or) is working on it. enhancement New feature or request good first issue Good for newcomers

Comments

@anshsrtv
Copy link
Member

anshsrtv commented Jun 3, 2020

Is your feature request related to a problem? Please describe.

A field level validation for permission_array field in [post] /api/org/(org-id)/group/ API instead of using the CreateGroupSerializer.permissions_valid(). As asked in comment in #110

The function below has to be replaced and can be used as a reference:

def permissions_valid(self):
    self.perm = Permissions()
    try:
        self.perm.set_permissions(
            permissions_array=self.initial_data['permissions_array']
        )
    except PERMISSION_INT_INVALID as perm_int_invalid:
        self._errors["permissions_array"]=str(perm_int_invalid)
    else:
        self._errors = {}
    return not bool(self._errors)

Describe the solution you'd like

Instead of using CreateGroupSerializer.permissions_valid(), use Field-level validation to let serializer.is_valid() do the validation of permission_array.

Describe alternatives you've considered

Use the Permissions.set_permissions() of custom_model_field.py to validate the permission ints in the permission_array using try except else statement. Catch the PERMISSION_INT_INVALID exception in the except clause.

Additional context

The reference for the solution can be Field-level validation

@anshsrtv anshsrtv added available No one has claimed the issue (or) is working on it. enhancement New feature or request good first issue Good for newcomers labels Jun 3, 2020
@harshakhmk
Copy link

I would like to work on this issue @anshsrtv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
available No one has claimed the issue (or) is working on it. enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants