mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-14 17:13:25 -05:00
Refactor to avoid direct string comparison
Direct string comparison in multiple places is prone to typos. It also means that a consumer of the class needs to know that whether a user is pending or active is held in the `state` property, which is an implementation detail.
This commit is contained in:
@@ -151,7 +151,7 @@ class User(JSONModel, UserMixin):
|
||||
return session.get('current_session_id') != self.current_session_id
|
||||
|
||||
def activate(self):
|
||||
if self.state == 'pending':
|
||||
if self.is_pending:
|
||||
user_data = user_api_client.activate_user(self.id)
|
||||
return self.__class__(user_data['data'])
|
||||
else:
|
||||
@@ -192,6 +192,10 @@ class User(JSONModel, UserMixin):
|
||||
def is_active(self):
|
||||
return self.state == 'active'
|
||||
|
||||
@property
|
||||
def is_pending(self):
|
||||
return self.state == 'pending'
|
||||
|
||||
@property
|
||||
def is_gov_user(self):
|
||||
return is_gov_user(self.email_address)
|
||||
@@ -443,7 +447,7 @@ class User(JSONModel, UserMixin):
|
||||
def is_editable_by(self, other_user):
|
||||
if other_user == self:
|
||||
return False
|
||||
if self.state == 'active':
|
||||
if self.is_active:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user