Repository: fossasia/open-event-server

Issue:
Admin should be allowed to change the boolean values is_sales_admin and is_marketer in users model
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
The admin should be allowed to change the attributes is_sales_admin and is_marketer for the edit functionality of the users.


**Additional details (please complete the following information):**
 - OS: Ubuntu

**Additional context**
![image](https://user-images.githubusercontent.com/22127980/43049491-4e53d572-8e16-11e8-96e2-fa2d9479fb67.png)
After a successful patch request
![image](https://user-images.githubusercontent.com/22127980/43049493-5b212c78-8e16-11e8-94c0-70ef19c772df.png)




Discussion:

Resolving patch:
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -186,6 +186,12 @@ def before_update_object(self, user, data, view_kwargs):
         if has_access('is_super_admin') and data.get('is_admin') != user.is_admin:
             user.is_admin = not user.is_admin
 
+        if has_access('is_admin') and data.get('is_sales_admin') != user.is_sales_admin:
+            user.is_sales_admin = not user.is_sales_admin
+
+        if has_access('is_admin') and data.get('is_marketer') != user.is_marketer:
+            user.is_marketer = not user.is_marketer
+
     def after_update_object(self, user, data, view_kwargs):
         """
         method to mail user about email change
diff --git a/app/models/user.py b/app/models/user.py
--- a/app/models/user.py
+++ b/app/models/user.py
@@ -72,6 +72,8 @@ class User(SoftDeletionModel):
     icon_image_url = db.Column(db.String)
     is_super_admin = db.Column(db.Boolean, default=False)
     is_admin = db.Column(db.Boolean, default=False)
+    is_sales_admin = db.Column(db.Boolean, default=False)
+    is_marketer = db.Column(db.Boolean, default=False)
     is_verified = db.Column(db.Boolean, default=False)
     last_accessed_at = db.Column(db.DateTime(timezone=True))
     created_at = db.Column(db.DateTime(timezone=True), default=datetime.now(pytz.utc))
@@ -174,27 +176,6 @@ def has_role(self, event_id):
         else:
             return True
 
-    def _is_system_role(self, role_name):
-        """
-        Checks if a user has a particular Role.
-        """
-        role = CustomSysRole.query.filter_by(name=role_name).first()
-        ucsr = UserSystemRole.query.filter_by(user=self,
-                                              role=role).first()
-        if not ucsr:
-            return False
-        else:
-            return True
-
-    @hybrid_property
-    def is_marketer(self):
-        # type: (object) -> object
-        return self._is_system_role(MARKETER)
-
-    @hybrid_property
-    def is_sales_admin(self):
-        return self._is_system_role(SALES_ADMIN)
-
     def _is_role(self, role_name, event_id=None):
         """
         Checks if a user has a particular Role at an Event.
diff --git a/migrations/versions/4fe385f78f53_.py b/migrations/versions/4fe385f78f53_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/4fe385f78f53_.py
@@ -0,0 +1,30 @@
+"""empty message
+
+Revision ID: 4fe385f78f53
+Revises: 4caf2c473e6a
+Create Date: 2018-07-23 10:35:57.960005
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+# revision identifiers, used by Alembic.
+revision = '4fe385f78f53'
+down_revision = '4caf2c473e6a'
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('users', sa.Column('is_marketer', sa.Boolean(), nullable=True))
+    op.add_column('users', sa.Column('is_sales_admin', sa.Boolean(), nullable=True))
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('users', 'is_sales_admin')
+    op.drop_column('users', 'is_marketer')
+    # ### end Alembic commands ###


Test patch: