IIT-BHU-InstiApp / lite-hai-backend

https://lite-hai.copsiitbhu.co.in/
13 stars 20 forks source link

Some issues found while testing #39

Closed nishantwrp closed 4 years ago

nishantwrp commented 4 years ago

Now here in clubs we have council again. Doesn't it seem weird?

/cc @krashish8

krashish8 commented 4 years ago

The tags can be created only for the club in which the user is a Workshop Contact. Are you trying to create a tag for another club? @nishantwrp

nishantwrp commented 4 years ago

No for the same club

krashish8 commented 4 years ago

And since this is created due to serializers.ValidationError, it return a 400 error. We can either make changes in permissions.py file, or can replace serializers.ValidationError with PermissionDenied in the required line. Which one would you prefer? @nishantwrp

krashish8 commented 4 years ago

No for the same club

Oh. Let me check.

krashish8 commented 4 years ago

What was the exact error message?

krashish8 commented 4 years ago
  • POST /tags/create/ - It is mentioned that any workshop contact can create a tag. But I got a 400 error. Can you confirm that this is a bug or intentional? And if the user is not authenticated there should be a 403 error not 400. Maybe we should move this endpoint to /clubs/{id}/tags/create/.

/cc @krashish8

Yes! I was also thinking to move this to /clubs/{id}/tags/create/. The endpoint /workshops/create/ can also be moved to /clubs/{id}/workshops/create/. What's your opinion? @nishantwrp

nishantwrp commented 4 years ago

Yup, I'm in favour of this.

nishantwrp commented 4 years ago

What was the exact error message?

"You are not allowed to create tag for this club"

krashish8 commented 4 years ago

Now here in clubs we have council again. Doesn't it seem weird?

Yes, we can change this. Do you know a better way to remove certain fields from a nested serializer, without creating another serializer? Here, we need to remove the council field from the ClubSerializer in the CouncilDetailSerializer class. @nishantwrp

krashish8 commented 4 years ago

What was the exact error message?

"You are not allowed to create tag for this club"

Found the error! In Line 220, club not in profile.get_workshop_privileges().values_list('club', flat=True)): should be changed to club.id not in profile.get_workshop_privileges().values_list('club', flat=True)):

krashish8 commented 4 years ago

Also, this line raise serializers.ValidationError("You are not allowed to create tag for this club") will return a 400 Error. Shall we change it to 403 here, and in similar places? But as a good practice, 403 error should not be raised in serializers, but in permissions. Any suggestions on how to do that?

nishantwrp commented 4 years ago

Ok, I think this can be done when we refactor the endpoint. Can you create a different issue for things that can be refactored like

Ans so, on.

nishantwrp commented 4 years ago

Now here in clubs we have council again. Doesn't it seem weird?

Yes, we can change this. Do you know a better way to remove certain fields from a nested serializer, without creating another serializer? Here, we need to remove the council field from the ClubSerializer in the CouncilDetailSerializer class. @nishantwrp

Nope. I don't. @shivanshs9 Do you?

nishantwrp commented 4 years ago

@krashish8 Also if we decide to make a new serializer, thinks may go complicated. How about creating directory serializers and files like clubs.py where we can have all serializers related to clubs and so on?

krashish8 commented 4 years ago

@krashish8 Also if we decide to make a new serializer, thinks may go complicated. How about creating directory serializers and files like clubs.py where we can have all serializers related to clubs and so on?

Hmm... this can be done.

shivanshs9 commented 4 years ago

Now here in clubs we have council again. Doesn't it seem weird?

Yes, we can change this. Do you know a better way to remove certain fields from a nested serializer, without creating another serializer? Here, we need to remove the council field from the ClubSerializer in the CouncilDetailSerializer class. @nishantwrp

Nope. I don't. @shivanshs9 Do you?

Yup, it can be done. Here's the mixin base class which I use for this purpose:

class DynamicFieldExclude(object):
    """
    Inherit from this class in any sub-class of ModelSerializer to
    support dynamic fields exclusion in any serializer when creating
    serializer object.
    """

    def __init__(self, *args, **kwargs):
        exclude_fields = kwargs.pop('exclude', None)
        super(DynamicFieldExclude, self).__init__(*args, **kwargs)

        if exclude_fields:
            for field_name in exclude_fields:
                self.fields.pop(field_name, None)