def delete_group(group=None): """Delete a Group for good. Args: group: Group instance to delete. Returns: True if group was deleted, False otherwise. """ if not group: return False if group.name == 'Administrator': return False # Build users and customer list before deleting group. group_users = group.get_users() found_users = [] for user in group_users: u = Hierarchy.get_user(user.name) if u: found_users.append(u) customer = group.get_customer() customer = Hierarchy.get_customer(customer.name) deleted = _db._db_delete(collection_name=GroupCollection, _id=group.id) if deleted: for user in found_users: user, __ = Hierarchy.toggle_user_from_group(user, group) Hierarchy.save_user(user) if customer: __, customer = Hierarchy.toggle_group_from_customer( group, customer ) Hierarchy.save_customer(customer) return deleted
def delete_group(group=None): """Delete a Group for good. Args: group: Group instance to delete. Returns: True if group was deleted, False otherwise. """ if not group: return False if group.name == 'Administrator': return False # Build users and customer list before deleting group. group_users = group.get_users() found_users = [] for user in group_users: u = Hierarchy.get_user(user.name) if u: found_users.append(u) customer = group.get_customer() customer = Hierarchy.get_customer(customer.name) deleted = _db._db_delete(collection_name=GroupCollection, _id=group.id) if deleted: for user in found_users: user, __ = Hierarchy.toggle_user_from_group(user, group) Hierarchy.save_user(user) if customer: __, customer = Hierarchy.toggle_group_from_customer( group, customer) Hierarchy.save_customer(customer) return deleted
def delete_customer(name=None): """Delete a Customer for good. Args: name: Name of the customer to delete. Returns: True if customer was deleted, False otherwise. """ if( not name or name == 'default' ): return False customer = Hierarchy.get_customer(name) # Build users and groups list before deleting customer. customer_groups = customer.get_groups() found_groups = [] for group in customer_groups: g = Hierarchy.get_group({GroupKey.Id: group.id}) if g: found_groups.append(g) customer_users = customer.get_users() found_users = [] for user in customer_users: u = Hierarchy.get_user(user.name) if u: found_users.append(u) deleted = _db._db_delete(collection_name=CustomerCollection, _id=customer.name) if deleted: for group in found_groups: group, __ = Hierarchy.toggle_group_from_customer( group, customer, both=True ) _db.save_group(group) for user in found_users: user, __ = Hierarchy.toggle_user_from_customer( user, customer, both=True ) _db.save_user(user) return deleted
def delete_user(name=None, current_customer=None): """Delete a User for good. Args: name: Name of the user to delete. Returns: True if user was deleted, False otherwise. """ if name == 'admin': return False user = Hierarchy.get_user(name) if not name: return False # Build users and groups list before deleting user. user_groups = user.get_groups() found_groups = [] for group in user_groups: g = Hierarchy.get_group({GroupKey.Id: group.id}) if g: found_groups.append(g) user_customers = user.get_customers() found_customers = [] for customer in user_customers: c = Hierarchy.get_customer(customer.name) if c: found_customers.append(c) deleted = _db._db_delete(collection_name=UserCollection, _id=name) if deleted: for group in found_groups: __, group = Hierarchy.toggle_user_from_group(user, group) _db.save_group(group) for customer in found_customers: __, customer = Hierarchy.toggle_user_from_customer(user, customer) _db.save_customer(customer) return deleted
def delete_customer(name=None): """Delete a Customer for good. Args: name: Name of the customer to delete. Returns: True if customer was deleted, False otherwise. """ if (not name or name == 'default'): return False customer = Hierarchy.get_customer(name) # Build users and groups list before deleting customer. customer_groups = customer.get_groups() found_groups = [] for group in customer_groups: g = Hierarchy.get_group({GroupKey.Id: group.id}) if g: found_groups.append(g) customer_users = customer.get_users() found_users = [] for user in customer_users: u = Hierarchy.get_user(user.name) if u: found_users.append(u) deleted = _db._db_delete(collection_name=CustomerCollection, _id=customer.name) if deleted: for group in found_groups: group, __ = Hierarchy.toggle_group_from_customer(group, customer, both=True) _db.save_group(group) for user in found_users: user, __ = Hierarchy.toggle_user_from_customer(user, customer, both=True) _db.save_user(user) return deleted
def delete_user(name=None, current_customer=None): """Delete a User for good. Args: name: Name of the user to delete. Returns: True if user was deleted, False otherwise. """ if name == 'admin': return False user = Hierarchy.get_user(name) if not name: return False # Build users and groups list before deleting user. user_groups = user.get_groups() found_groups = [] for group in user_groups: g = Hierarchy.get_group({GroupKey.Id: group.id}) if g: found_groups.append(g) user_customers = user.get_customers() found_customers = [] for customer in user_customers: c = Hierarchy.get_customer(customer.name) if c: found_customers.append(c) deleted = _db._db_delete(collection_name=UserCollection, _id=name) if deleted: for group in found_groups: __, group = Hierarchy.toggle_user_from_group(user, group) _db.save_group(group) for customer in found_customers: __, customer = Hierarchy.toggle_user_from_customer( user, customer) _db.save_customer(customer) return deleted