Repository: fossasia/open-event-server

Issue:
Show System Roles and Events Role for a user
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
Currently, when we go to `/admin/users/all` route at frontend it is missing the System Role and Event role associated with a user.

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->
Modifying the API of users by adding Boolean attributes like 
`is_user_super_admin`
`is_user_admin`
`is_user_coorganizer`
`is_user_attendee`
`is_user_track_organizer`
`is_user_moderator`
etc

**Describe alternatives you've considered**
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->

![users tab roles](https://user-images.githubusercontent.com/22936570/41501401-5dadc986-71c1-11e8-9ebe-2b09656667bb.png)

@niranjan94 @SaptakS @iamareebjamal @poush 
Thoughts please can I go with this proposed approach ??


Discussion:
You can but you need to be very careful with permissions then. The permissions for GET list should be visible only to the admins and not everyone.

Resolving patch:
diff --git a/app/api/schema/users.py b/app/api/schema/users.py
--- a/app/api/schema/users.py
+++ b/app/api/schema/users.py
@@ -49,6 +49,12 @@ class Meta:
     password = fields.Str(required=True, load_only=True)
     is_super_admin = fields.Boolean(dump_only=True)
     is_admin = fields.Boolean(dump_only=True)
+    is_user_organizer = fields.Boolean(dump_only=True)
+    is_user_coorganizer = fields.Boolean(dump_only=True)
+    is_user_track_organizer = fields.Boolean(dump_only=True)
+    is_user_moderator = fields.Boolean(dump_only=True)
+    is_user_registrar = fields.Boolean(dump_only=True)
+    is_user_attendee = fields.Boolean(dump_only=True)
     is_verified = fields.Boolean(dump_only=True)
     last_accessed_at = fields.DateTime(dump_only=True)
     created_at = fields.DateTime(dump_only=True)
diff --git a/app/models/user.py b/app/models/user.py
--- a/app/models/user.py
+++ b/app/models/user.py
@@ -154,14 +154,18 @@ def has_role(self, event_id):
         else:
             return True
 
-    def _is_role(self, role_name, event_id):
+    def _is_role(self, role_name, event_id=None):
         """
         Checks if a user has a particular Role at an Event.
         """
         role = Role.query.filter_by(name=role_name).first()
-        uer = UER.query.filter_by(user=self,
-                                  event_id=event_id,
-                                  role=role).first()
+        if event_id:
+            uer = UER.query.filter_by(user=self,
+                                      event_id=event_id,
+                                      role=role).first()
+        else:
+            uer = UER.query.filter_by(user=self,
+                                      role=role).first()
         if not uer:
             return False
         else:
@@ -186,6 +190,31 @@ def is_registrar(self, event_id):
     def is_attendee(self, event_id):
         return self._is_role(ATTENDEE, event_id)
 
+    @hybrid_property
+    def is_user_organizer(self):
+        # type: (object) -> object
+        return self._is_role(ORGANIZER)
+
+    @hybrid_property
+    def is_user_coorganizer(self):
+        return self._is_role(COORGANIZER)
+
+    @hybrid_property
+    def is_user_track_organizer(self):
+        return self._is_role(TRACK_ORGANIZER)
+
+    @hybrid_property
+    def is_user_moderator(self):
+        return self._is_role(MODERATOR)
+
+    @hybrid_property
+    def is_user_registrar(self):
+        return self._is_role(REGISTRAR)
+
+    @hybrid_property
+    def is_user_attendee(self):
+        return self._is_role(ATTENDEE)
+
     def _has_perm(self, operation, service_class, event_id):
         # Operation names and their corresponding permission in `Permissions`
         operations = {


Test patch: