mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
updating namings to stay coherent
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from typing import Union
|
from typing import Optional
|
||||||
from core.definition import MReputation
|
from core.definition import MReputation
|
||||||
from core.base import Base
|
from core.base import Base
|
||||||
|
|
||||||
@@ -13,11 +13,11 @@ class Reputation:
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def insert(self, newReputationUser: MReputation) -> bool:
|
def insert(self, new_reputation_user: MReputation) -> bool:
|
||||||
"""Insert a new Reputation User object
|
"""Insert a new Reputation User object
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
newReputationUser (MReputation): New Reputation Model object
|
new_reputation_user (MReputation): New Reputation Model object
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if inserted
|
bool: True if inserted
|
||||||
@@ -26,23 +26,23 @@ class Reputation:
|
|||||||
exist = False
|
exist = False
|
||||||
|
|
||||||
for record in self.UID_REPUTATION_DB:
|
for record in self.UID_REPUTATION_DB:
|
||||||
if record.uid == newReputationUser.uid:
|
if record.uid == new_reputation_user.uid:
|
||||||
# If the user exist then return False and do not go further
|
# If the user exist then return False and do not go further
|
||||||
exist = True
|
exist = True
|
||||||
self.Logs.debug(f'{record.uid} already exist')
|
self.Logs.debug(f'{record.uid} already exist')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if not exist:
|
if not exist:
|
||||||
self.UID_REPUTATION_DB.append(newReputationUser)
|
self.UID_REPUTATION_DB.append(new_reputation_user)
|
||||||
result = True
|
result = True
|
||||||
self.Logs.debug(f'New Reputation User Captured: ({newReputationUser})')
|
self.Logs.debug(f'New Reputation User Captured: ({new_reputation_user})')
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
self.Logs.critical(f'The Reputation User Object was not inserted {newReputationUser}')
|
self.Logs.critical(f'The Reputation User Object was not inserted {new_reputation_user}')
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update(self, uid: str, newNickname: str) -> bool:
|
def update(self, uid: str, new_nickname: str) -> bool:
|
||||||
"""Update the nickname starting from the UID
|
"""Update the nickname starting from the UID
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -53,12 +53,12 @@ class Reputation:
|
|||||||
bool: True if updated
|
bool: True if updated
|
||||||
"""
|
"""
|
||||||
|
|
||||||
reputationObj = self.get_Reputation(uid)
|
reputation_obj = self.get_Reputation(uid)
|
||||||
|
|
||||||
if reputationObj is None:
|
if reputation_obj is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
reputationObj.nickname = newNickname
|
reputation_obj.nickname = new_nickname
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ class Reputation:
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_Reputation(self, uidornickname: str) -> Union[MReputation, None]:
|
def get_Reputation(self, uidornickname: str) -> Optional[MReputation]:
|
||||||
"""Get The User Object model
|
"""Get The User Object model
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -98,16 +98,15 @@ class Reputation:
|
|||||||
Returns:
|
Returns:
|
||||||
UserModel|None: The UserModel Object | None
|
UserModel|None: The UserModel Object | None
|
||||||
"""
|
"""
|
||||||
User = None
|
|
||||||
for record in self.UID_REPUTATION_DB:
|
for record in self.UID_REPUTATION_DB:
|
||||||
if record.uid == uidornickname:
|
if record.uid == uidornickname:
|
||||||
User = record
|
return record
|
||||||
elif record.nickname == uidornickname:
|
elif record.nickname == uidornickname:
|
||||||
User = record
|
return record
|
||||||
|
|
||||||
return User
|
return None
|
||||||
|
|
||||||
def get_uid(self, uidornickname:str) -> Union[str, None]:
|
def get_uid(self, uidornickname: str) -> Optional[str]:
|
||||||
"""Get the UID of the user starting from the UID or the Nickname
|
"""Get the UID of the user starting from the UID or the Nickname
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -117,14 +116,14 @@ class Reputation:
|
|||||||
str|None: Return the UID
|
str|None: Return the UID
|
||||||
"""
|
"""
|
||||||
|
|
||||||
reputationObj = self.get_Reputation(uidornickname)
|
reputation_obj = self.get_Reputation(uidornickname)
|
||||||
|
|
||||||
if reputationObj is None:
|
if reputation_obj is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return reputationObj.uid
|
return reputation_obj.uid
|
||||||
|
|
||||||
def get_nickname(self, uidornickname:str) -> Union[str, None]:
|
def get_nickname(self, uidornickname: str) -> Optional[str]:
|
||||||
"""Get the Nickname starting from UID or the nickname
|
"""Get the Nickname starting from UID or the nickname
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -133,12 +132,12 @@ class Reputation:
|
|||||||
Returns:
|
Returns:
|
||||||
str|None: the nickname
|
str|None: the nickname
|
||||||
"""
|
"""
|
||||||
reputationObj = self.get_Reputation(uidornickname)
|
reputation_obj = self.get_Reputation(uidornickname)
|
||||||
|
|
||||||
if reputationObj is None:
|
if reputation_obj is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return reputationObj.nickname
|
return reputation_obj.nickname
|
||||||
|
|
||||||
def is_exist(self, uidornickname: str) -> bool:
|
def is_exist(self, uidornickname: str) -> bool:
|
||||||
"""Check if the UID or the nickname exist in the reputation DB
|
"""Check if the UID or the nickname exist in the reputation DB
|
||||||
@@ -150,9 +149,9 @@ class Reputation:
|
|||||||
bool: True if exist
|
bool: True if exist
|
||||||
"""
|
"""
|
||||||
|
|
||||||
reputationObj = self.get_Reputation(uidornickname)
|
reputation_obj = self.get_Reputation(uidornickname)
|
||||||
|
|
||||||
if reputationObj is None:
|
if isinstance(reputation_obj, MReputation):
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user