mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-16 10:04:07 -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
|
return session.get('current_session_id') != self.current_session_id
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
if self.state == 'pending':
|
if self.is_pending:
|
||||||
user_data = user_api_client.activate_user(self.id)
|
user_data = user_api_client.activate_user(self.id)
|
||||||
return self.__class__(user_data['data'])
|
return self.__class__(user_data['data'])
|
||||||
else:
|
else:
|
||||||
@@ -192,6 +192,10 @@ class User(JSONModel, UserMixin):
|
|||||||
def is_active(self):
|
def is_active(self):
|
||||||
return self.state == 'active'
|
return self.state == 'active'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_pending(self):
|
||||||
|
return self.state == 'pending'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_gov_user(self):
|
def is_gov_user(self):
|
||||||
return is_gov_user(self.email_address)
|
return is_gov_user(self.email_address)
|
||||||
@@ -443,7 +447,7 @@ class User(JSONModel, UserMixin):
|
|||||||
def is_editable_by(self, other_user):
|
def is_editable_by(self, other_user):
|
||||||
if other_user == self:
|
if other_user == self:
|
||||||
return False
|
return False
|
||||||
if self.state == 'active':
|
if self.is_active:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user