#31266: Implement `user.is_member(group)` to easily check whether a user 
belongs to
a group or not
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  martinzugnoni
  martinzugnoni                      |
                   Type:  New        |         Status:  assigned
  feature                            |
              Component:             |        Version:  3.0
  contrib.auth                       |
               Severity:  Normal     |       Keywords:  auth, groups, users
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 While checking if a user is member of certain group, there's no easy way
 to check it other than going through the "groups" M2M relationship
 manually, like this.

 {{{
 #!python
 > user.groups.filter(name="some-group").exists()
 True
 }}}

 I propose to extend the `django.contrib.auth.models.PermissionsMixin`
 class, with a `is_member(group)` method, that returns True/False checking
 whether the user belongs to the group or not. Similar to the
 `user.has_perm("some-permission")`, but for groups.

 The same operation using this new method would look like this:

 {{{
 #!python
 > user.is_member("some-group")
 True
 }}}

 I'm open to suggestions.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31266>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.6030d94490ea34e9c613afbb77e2c490%40djangoproject.com.

Reply via email to