예제 #1
0
def remove_user(username, registered_user):
    if username is not None and registered_user is not None:
        if SystemManagers.is_system_manager(username) is not False:
            sys_manager = SystemManagers.is_system_manager(
                registered_user.username)
            is_store_manager = StoreManagers.is_store_manager(
                registered_user.username)
            is_owner = Owners.is_owner(registered_user.username)
            if sys_manager is False:
                user = RegisteredUsers.get_user(registered_user.username)
                if user is not False:
                    result_delete = True
                    if is_store_manager is not False:
                        result_delete = StoreManagers.remove_manager(
                            registered_user.username)
                    else:
                        if is_owner is not False:
                            result_delete = Owners.remove_owner(
                                registered_user.username)
                    final_result = result_delete and RegisteredUsers.remove_user(
                        registered_user.username)
                    if final_result:
                        LoggerLogic.add_event_log(username, "DELETE USER")
                    return final_result
            return False
    return False
예제 #2
0
def update_permissions(username, store_manager):
    if Owners.is_owner_on_shop(username,
                               store_manager.store_name) is not False:
        previous_store_manager = StoreManagers.get_store_manager(
            store_manager.username, store_manager.store_name)
        status = StoreManagers.update_permissions(store_manager)
        if status:
            if isEmptyPermissions(previous_store_manager):
                status = HistoryAppointings.update_history_appointing(
                    username, store_manager.username, store_manager.store_name,
                    getPermissionsString(store_manager))
        return status
    return False
예제 #3
0
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"
예제 #4
0
def update_shopping_policy_on_shop(username, policy_id, field_name, new_value, shop_name):
    if policy_id is not None and field_name is not None and new_value is not None:
        if int(policy_id) < 0:
            return "FAILED: Invalid id of Policy"
        if field_name not in ['shop_name', 'conditions', 'restriction', 'quantity']:
            return "FAILED: Invalid field name"
        if Owners.get_owner(username, shop_name) is not False:
            if field_name in ['conditions']:
                status = checkConditionsSyntax(new_value)
                if new_value == "":
                    new_value = "1=1"
                if status is not True:
                    return status

            if not ShoppingPolicies.update_shopping_policy_on_shop(policy_id, field_name, new_value):
                return "FAILED: DB error."
            LoggerLogic.add_event_log(username, "POLICY: UPDATE SHOP SHOPPING POLICY")
            return True
        manager = StoreManagers.get_store_manager(username, shop_name)
        if manager is not False:
            if manager.permission_set_policy > 0:
                if field_name in ['conditions']:
                    status = checkConditionsSyntax(new_value)
                    if new_value == "":
                        new_value = "1=1"
                    if status is not True:
                        return status

                if not ShoppingPolicies.update_shopping_policy_on_shop(policy_id, field_name, new_value):
                    return "FAILED: DB error."
                LoggerLogic.add_event_log(username, "POLICY: UPDATE SHOP SHOPPING POLICY")
                return True
            return 'FAILED: no permissions!'
        return 'FAILED: you are not a the Owner of the shop'
    return "FAILED: One (or more) of the parameters is None"
예제 #5
0
def add_invisible_discount_category(disc, username):
    if disc is not None and username is not None and 0 <= disc.percentage <= 100:
        is_owner = Owners.get_owner(username, disc.shop_name)
        is_manager = StoreManagers.get_store_manager(username, disc.shop_name)
        if is_owner is not False or (is_manager is not False
                                     and is_manager.discount_permission == 1):
            return Discount.add_invisible_discount_category(disc)
    return False
예제 #6
0
def get_shop_purchase_history(username, shop_name):
    manager = StoreManagers.get_store_manager(username, shop_name)
    owner = Owners.get_owner(username, shop_name)
    if manager is not False:
        if manager.permission_get_purchased_history > 0:
            return PurchasedItems.get_purchased_items_by_shop(shop_name)
    else:
        if owner is not False:
            return PurchasedItems.get_purchased_items_by_shop(shop_name)
    return False
예제 #7
0
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
예제 #8
0
def edit_shop_item(username, item_id, field_name, new_value):
    item = Items.get_item(item_id)
    result = StoreManagers.get_store_manager(username, item.shop_name)
    if result is not False:
        edit_item_permission = result.permission_edit_item
        if edit_item_permission > 0:
            return Items.update_item(item_id, field_name, new_value)
    else:
        if Owners.get_owner(username, item.shop_name) is not False:
            return Items.update_item(item_id, field_name, new_value)
    return False
예제 #9
0
def add_item_to_shop(item, username):
    if item is not None and item.shop_name is not None and username is not None and item.quantity >= 0 \
            and item.price >= 0:
        manager = StoreManagers.get_store_manager(username, item.shop_name)
        if manager is not False:
            add_item_permission = manager.permission_add_item
            if add_item_permission > 0:
                return Items.add_item_to_shop(item)
        if Owners.get_owner(username, item.shop_name) is not False:
            return Items.add_item_to_shop(item)
    return False
예제 #10
0
def remove_item_from_shop(item_id, username):
    if item_id is not None:
        item = Items.get_item(item_id)
        if item is not False:
            manager = StoreManagers.get_store_manager(username, item.shop_name)
            if manager is not False:
                remove_item_permission = manager.permission_remove_item
                if remove_item_permission > 0:
                    return Items.remove_item_from_shop(item_id)
            elif Owners.is_owner(username):
                return Items.remove_item_from_shop(item_id)

    return False
예제 #11
0
 def test_add_store_manager(self):
     UsersLogic.register(RegisteredUser('ShaharShahar', '12345126'))
     UsersLogic.register(RegisteredUser('TomerTomerLev', '65412321'))
     shop = Shop('myShop', 'Active')
     ShopLogic.create_shop(shop, 'ShaharShahar')
     UsersLogic.add_manager(
         'ShaharShahar',
         StoreManager('TomerTomerLev', 'myShop', 1, 1, 1, 1, 1, 1, 1, 1))
     manager = StoreManagers.get_store_manager('TomerTomerLev', 'myShop')
     self.assertTrue(manager.permission_add_item > 0)
     self.assertTrue(manager.permission_remove_item > 0)
     self.assertTrue(manager.permission_edit_item > 0)
     self.assertEqual(manager.store_name, 'myShop')
     self.assertEqual(manager.username, 'TomerTomerLev')
예제 #12
0
def add_shopping_policy_on_shop(username, shop_name, conditions, restriction, quantity):
    if shop_name is not None and conditions is not None:
        if restriction is not None and quantity is not None:
            if restriction not in ['N', 'AL', 'E', 'UT']:
                return "FAILED: Invalid value of restriction."
            if int(quantity) < 0:
                return "FAILED: Negative quantity is invalid."
            if Owners.get_owner(username, shop_name) is not False:
                if not ShoppingPolicies.add_shopping_policy_on_shop(shop_name, conditions, restriction, quantity):
                    return "FAILED: DB error."
                LoggerLogic.add_event_log(username, "POLICY: ADD SHOP SHOPPING POLICY")
                return True
            manager = StoreManagers.get_store_manager(username,shop_name)
            if manager is not False:
                if manager.permission_set_policy > 0:
                    if not ShoppingPolicies.add_shopping_policy_on_shop(shop_name, conditions, restriction, quantity):
                        return "FAILED: DB error."
                    LoggerLogic.add_event_log(username, "POLICY: ADD SHOP SHOPPING POLICY")
                    return True
                return 'FAILED: no permissions!'
            return 'FAILED: you are not a the Owner of the shop'
        return "FAILED: One (or more) of the parameters is None"
    return "FAILED: One (or more) of the parameters is None"
예제 #13
0
def add_manager(username, store_manager):
    if username is not None:
        if Owners.get_owner(username, store_manager.store_name) is not False:
            if RegisteredUsers.get_user(store_manager.username) is not False:
                if store_manager.store_name is not None:
                    if Owners.get_owner(store_manager.username,
                                        store_manager.store_name):
                        return "FAILED! An owner can't be store manager"
                    if StoreManagers.add_manager(store_manager):
                        if HistoryAppointings.add_history_appointing(
                                username, store_manager.username,
                                'Store Manager', store_manager.store_name,
                                strftime("%d-%m-%Y %H:%M:%S", gmtime()), ''):
                            return 'SUCCESS'
                        return "FAILED"
                    return "FAILED"
                else:
                    return "FAILED: Shop does not exists"
            else:
                return "FAILED: User does not exists"
        else:
            return "FAILED: You are not the owner of this shop"
    else:
        return "FAILED: Missing Parameters"
예제 #14
0
    def test_torture2(self):
        # Adding Users
        status = UsersLogic.register(
            RegisteredUser('u1ser1u1ser1', 'wxde12exd12'))
        self.assertTrue(status)
        status = UsersLogic.register(RegisteredUser('u2ser2u2ser2',
                                                    '34c124c1'))
        self.assertTrue(status)
        status = UsersLogic.register(
            RegisteredUser('u3ser3u3ser3', '1c241c24c1'))
        self.assertTrue(status)
        status = UsersLogic.register(
            RegisteredUser('u4ser4u4ser4', '3214v132v4132'))
        self.assertTrue(status)
        status = UsersLogic.register(RegisteredUser('u5seru5ser', '12121212'))
        self.assertTrue(status)

        # Adding System Managers
        status = UsersLogic.add_system_manager(
            SystemManager('sys1sys1', 'POWER123'))
        self.assertTrue(status)

        # Creating Shops
        status = ShopLogic.create_shop(Shop('myShop1', 'Active'),
                                       'u1ser1u1ser1')
        self.assertTrue(status)

        status = ShopLogic.create_shop(Shop('myShop2', 'Active'),
                                       'u2ser2u2ser2')
        self.assertTrue(status)

        status = UsersLogic.add_owner('u1ser1u1ser1',
                                      Owner('u3ser3u3ser3', 'myShop1', 0))
        self.assertTrue(status)

        owner = Owners.get_owner('u1ser1u1ser1', 'myShop1')
        status = UsersLogic.add_manager(
            owner.username,
            StoreManager('u4ser4u4ser4', 'myShop1', 1, 1, 1, 1, 1, 1, 1, 1))
        status = UsersLogic.add_manager(
            'u2ser2u2ser2',
            StoreManager('u4ser4u4ser4', 'myShop2', 1, 1, 1, 1, 1, 1, 1, 1))

        manager = StoreManagers.get_store_manager('u4ser4u4ser4', 'myShop1')

        self.assertEqual(manager.permission_reply_messages, 1)

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop1', 'banana', 'fruits', 'fruit;healthy;yellow',
                 4.90, 300, 'regular', None, 0, 0, 0), 'u4ser4u4ser4')

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop2', 'doll', 'toys', 'fun', 30, 10, 'regular',
                 None, 0, 0, 0), 'u2ser2u2ser2')

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop1', 'soda', 'drinks', 'good', 4.90, 20,
                 'regular', None, 0, 0, 0), 'u1ser1u1ser1')

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop2', 'cucumber', 'vegetables', 'fun', 4.90, 300,
                 'regular', None, 0, 0, 0), 'u4ser4u4ser4')

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop1', 'vodka', 'drinks', 'bad;for;your;health', 70,
                 2, 'regular', None, 0, 0, 0), 'u3ser3u3ser3')

        items = SearchLogic.search_by_name('banana')
        self.assertEqual(items[0].quantity, 300)
        self.assertEqual(items[0].price, 4.90)
        self.assertEqual(len(items), 1)

        items = SearchLogic.search_by_category('drinks')
        self.assertEqual(items[0].quantity, 20)
        self.assertEqual(items[1].price, 70)
        self.assertEqual(len(items), 2)

        items = SearchLogic.search_by_keywords('fun')
        self.assertEqual(items[0].quantity, 10)
        self.assertEqual(items[1].price, 4.90)
        self.assertEqual(len(items), 2)

        items = SearchLogic.search_items_in_shop('myShop2')
        self.assertEqual(items[0].name, 'doll')
        self.assertEqual(items[1].name, 'cucumber')
        self.assertEqual(len(items), 2)

        MessagingLogic.send_message_from_shop(
            'u4ser4u4ser4',
            Message(None, 'myShop1', 'u5seru5ser',
                    'Nadav is our lord and savior'))
        messages = MessagingLogic.get_all_messages('u5seru5ser')
        self.assertEqual(len(messages), 1)
        self.assertEqual(messages[0].content, 'Nadav is our lord and savior')

        MessagingLogic.send_message(
            Message(None, 'u5seru5ser', 'myShop1', 'Hello Shop'))
        messages = MessagingLogic.get_all_shop_messages(
            'u4ser4u4ser4', 'myShop1')
        self.assertEqual(len(messages), 1)
        self.assertEqual(messages[0].content, 'Hello Shop')

        MessagingLogic.send_message_from_shop(
            'u1ser1u1ser1', Message(None, 'myShop1', 'myShop2', 'Hello Shop2'))
        messages = MessagingLogic.get_all_shop_messages(
            'u2ser2u2ser2', 'myShop2')
        self.assertEqual(len(messages), 1)
        self.assertEqual(messages[0].content, 'Hello Shop2')

        MessagingLogic.send_message(
            Message(None, 'u1ser1u1ser1', 'u3ser3u3ser3', 'Shop2 Sucks!'))
        messages = MessagingLogic.get_all_messages('u3ser3u3ser3')
        self.assertEqual(messages[0].content, 'Shop2 Sucks!')

        UsersLogic.close_shop('u1ser1u1ser1', 'myShop1')
        items = SearchLogic.search_by_name('banana')
        self.assertEqual(len(items), 0)
예제 #15
0
def get_manager(username, shop_name):
    return StoreManagers.get_store_manager(username, shop_name)
예제 #16
0
def remove_store_manager(username, shop_name, target_id):
    if Owners.is_owner_on_shop(username, shop_name) is not False:
        return StoreManagers.remove_manager_from_shop(target_id, shop_name)
    return False
예제 #17
0
def get_managed_shops(username):
    return StoreManagers.get_manager_shops(username)
예제 #18
0
def get_store_managers(shop_name):
    return StoreManagers.get_store_managers_on_shop(shop_name)
예제 #19
0
def is_manager_of_shop(username, shop_name):
    return StoreManagers.is_store_manager_of_shop(username, shop_name)