def get_all_sent_shop_messages(username, shop_name): manager = StoreManagers.get_store_manager(username, shop_name) if manager is not False: if manager.permission_get_all_messages > 0: if Shops.search_shop(shop_name) is not False: return Messages.get_all_sent_shop_messages(shop_name) if Owners.get_owner(username, shop_name) is not False: if Shops.search_shop(shop_name) is not False: return Messages.get_all_sent_shop_messages(shop_name) return False
def create_shop(shop, username): if shop is not None and username is not None: if Shops.search_shop(shop.name) is False: if Shops.create_shop(shop): if Owners.add_owner(Owner(username, shop.name, None)): LoggerLogic.add_event_log(username, "OPEN SHOP") return "SUCCESS" return "FAILED: Adding Owner" return "FAILED: Adding Shop" return "FAILED: Shop name is taken" return "FAILED: Missing parameters"
def add_system_manager(system_manager): if system_manager.username == 'System': return False if RegisteredUsers.get_user( system_manager.username) is False and Shops.search_shop( system_manager.username) is False: return SystemManagers.add_system_manager(system_manager)
def send_message(message): if message.from_username is not None and message.to_username is not None and message.content is not None: if message.to_username == 'System' or get_user( message.to_username) is not False or Shops.search_shop( message.to_username) is not False: # output = Messages.send_message(message) if SystemManagers.is_system_manager(message.from_username): message.from_username = '******' output = Messages.send_message(message) else: return "FAILED: Target user is incorrect" else: return "FAILED: Missing Parameters" if output: users = [message.to_username] if message.to_username == 'System': LoggerLogic.add_event_log(message.from_username, "REPORT ITEM / SHOP") SMs = SystemManagers.get_all_system_managers() SM_names = [] for sm in SMs: SM_names.append(sm.username) users = SM_names MessagingAlerts.notify_messaging_alerts( users, '<a href = "../app/home/messages/?content=received" > ' 'You Have a new message from ' + message.from_username + '</a>') return "SUCCESS" else: return "FAILED"
def send_message_from_shop(username, message): output = False manager = StoreManagers.get_store_manager(username, message.from_username) if Shops.search_shop( message.to_username) is False and RegisteredUsers.is_user_exists( message.to_username) is False: return "FAILED: Target does not exists" if manager is not False: if manager.permission_reply_messages > 0: output = Messages.send_message_from_shop(message) else: return "FAILED: You don't have the permissions" if Owners.get_owner(username, message.from_username) is not False: output = Messages.send_message_from_shop(message) else: return "FAILED: You are not authorized" if output: users = [message.to_username] if message.to_username == 'System': SMs = SystemManagers.get_all_system_managers() SM_names = [] for sm in SMs: SM_names.append(sm.username) users = SM_names MessagingAlerts.notify_messaging_alerts( users, '<a href = "../app/home/messages/?content=received" >' ' You Have a new message from <strong>Shop</strong>' + message.from_username + '</a>') return "SUCCESS" else: return "FAILED"
def test_bad_create_shop(self): register(RegisteredUser('TomerTomer', '1234567878')) shop = Shop('My Shop', 'Active') ShopLogic.create_shop(shop, 'TomerTomer') shop_founded = Shops.search_shop('My Shop') self.assertTrue(shop_founded.name == 'My Shop') status = ShopLogic.create_shop(shop, 'TomerTomer') self.assertEqual(status, 'FAILED: Shop name is taken')
def close_shop_permanently(username, shop_name): if username is not None and shop_name is not None: sys_manager = SystemManagers.is_system_manager(username) if sys_manager is not False: shop = search_shop(shop_name) if shop is not False: return Shops.close_shop_permanently(shop_name) return False return False
def re_open_shop(username, shop_name): owner_of_shop = Owners.get_owner(username, shop_name) if owner_of_shop is not False: result = Shops.re_open_shop(shop_name) if result: LoggerLogic.add_event_log(username, "SHOP STATUS CHANGED - RE-OPEN") return result else: return False
def close_shop(username, shop_name): owner_of_shop = Owners.get_owner(username, shop_name) if owner_of_shop is not False: result = Shops.close_shop(shop_name) if result: lotteries = get_lotteries_by_shop(shop_name) for lottery in lotteries: lottery_timer(lottery.id) LoggerLogic.add_event_log(username, "SHOP STATUS CHANGED - CLOSE") return result else: return False
def register(user): if user.username is not None and user.password is not None and not SystemManagers.is_system_manager( user.username): if re.match(r'[A-Za-z0-9]{8,20}', user.username): if re.match(r'[A-Za-z0-9]{8,20}', user.password): user.password = hashlib.sha256( user.password.encode()).hexdigest() if Shops.search_shop(user.username) is not False: return 'FAILED: Username is already taken' if RegisteredUsers.get_user(user.username) is not False: return 'FAILED: Username is already taken' if RegisteredUsers.add_user(user): UserDetails.insert(user.username) LoggerLogic.add_event_log(user.username, "REGISTER") return 'SUCCESS' return 'FAILED' else: return 'FAILED: Password must be 8 to 20 alphabetic letters and numbers' else: return 'FAILED: Username must be 8 to 20 alphabetic letters and numbers' else: return 'FAILED: Username is already taken'
def get_all_shops(): return Shops.get_all_shops()
def test_create_shop(self): register(RegisteredUser('TomerTomer', '1234567878')) shop = Shop('My Shop', 'Active') ShopLogic.create_shop(shop, 'TomerTomer') shop_founded = Shops.search_shop('My Shop') self.assertTrue(shop_founded.name == 'My Shop')
def search_shop(shop_name): if shop_name is not None: return Shops.search_shop(shop_name)
def test_search_shop(self): shop_founded = Shops.search_shop('My Shop') self.assertTrue(shop_founded.name == 'My Shop')