django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

Modify `AND` and `OR` permission operands to have the ability to use custom messages

Open samitnuk opened this issue 6 years ago • 11 comments

refs #6427

  • AND - If failed permission has a message, it will be returned.
  • OR - If both permissions will be failed: a) if both permissions have messages - will be returned one message combined from two messages; b) if only one permission (from both failed) has a message - this message will be returned (I suppose this is better then return the default one).
  • NOT - If failed permission has a message_inverted attribute, it will be returned. (@iproha94 thanks for this suggestion).

samitnuk avatar Mar 09 '19 18:03 samitnuk

@ozandogrultan Many thanks for your comments. I have updated this PR.

samitnuk avatar Dec 07 '19 10:12 samitnuk

@samitnuk wrote

NOT - untouched here since in any case, we cannot use the message from "inverted" permission.

I think for this case, we should add the inverted_message property to the custom permission class, so

class MyCustomPermission(permissions.BasePermission):
    message = _("you are not active")
    inverted_message = _("you are active")

and use it for rest_framework/permissions.py:

class NOT:
    def __init__(self, op1):
        self.op1 = op1
        self.message = getattr(self.op1, 'inverted_message', None)

but this is incorrect for double negative.

iproha94 avatar Mar 26 '20 11:03 iproha94

Hi, @iproha94. Thank you for your review. I will check your comments and make updates asap.

samitnuk avatar Mar 27 '20 09:03 samitnuk

@ozandogrultan, @auvipy, @iproha94 please review the updated PR. Many thanks.

samitnuk avatar Apr 13 '20 15:04 samitnuk

Is this being merged?

DrJfrost avatar Apr 23 '20 23:04 DrJfrost

Any plans to to get this merged??

tony-garcia avatar Dec 11 '20 14:12 tony-garcia

I am running into this issue currently. Is this in the roadmap to get merged?

Riccardo-Maio avatar Feb 17 '22 14:02 Riccardo-Maio

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 18 '22 14:04 stale[bot]

Same issue here. I like the solution and would be happy to see this merged.

MartinSchmidt123 avatar Mar 14 '23 15:03 MartinSchmidt123

let see how it works on current CI

auvipy avatar Mar 14 '23 18:03 auvipy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 11 '23 16:06 stale[bot]