Esempio n. 1
0
def delete_user(username):
    user = UserDao.get_user(username)
    if user and authentication.allow_full_user_changes(username):
        UserDao.delete_user(username)
    user = UserDao.get_user(username)
    if not user:
        assignees = assigneesHandler.get_customers(username)
        for assignee in assignees:
            assigneesHandler.delete(assignee.get('user'), assignee.get('customer'))
        assignees = assigneesHandler.get_customers('username')
        if not assignees or len(assignees) == 0:
            return True
    return False
Esempio n. 2
0
def get_users():
    current_user = get_current_user()
    result = []
    customers = assigneesHandler.get_customers(current_user.get('username'))
    if authentication.has_full_access(current_user):
        # super user, master admin
        result = [_set_customers(u) for u in UserDao.get_all()]
    elif authentication.user_is_master(current_user):
        if authentication.user_is_assigned_master(current_user):
            # master user (assigned master customer)
            users = [_set_customers(u) for u in UserDao.get_all()]
            result = [u for u in users if authentication.allow_semi_user_changes(u)]
        else:
            # master user (not assigned master customer)
            for customer in customers:
                assigned_users = assigneesHandler.get_assignees(customer.get('customer'))
                users = [get_user(a['user']) for a in assigned_users]
                result = result + [u for u in users if authentication.allow_semi_user_changes(u)]
    else:
        # can only be assigned to one..
        customer = customers[0]
        assigned_users = assigneesHandler.get_assignees(customer.get('customer'))
        users = [get_user(a['user']) for a in assigned_users]
        result = [u for u in users if u and authentication.allow_semi_user_changes(u)]
    return result
Esempio n. 3
0
 def index(self):
     if authentication.is_logged_in(cherrypy.session):
         user = authentication.get_current_user()
         if authentication.is_master(user):
             redirect(URL_MASTER)
         else:
             customers = assigneesHandler.get_customers(user.get('username'))
             #Normal users can only be assigned to one customer.
             if customers:
                 customer = customers.pop()
                 redirect(URL_USER + str(customer.get('customer')))
             else:
                 redirect(URL_LOGIN)
     else:
         redirect(URL_LOGIN)
Esempio n. 4
0
def get_customers_for(username= None):
    user = userHandler.get_user(username)
    assignees = assigneesHandler.get_customers(user.get('username'))
    customers = []
    if not authentication.is_master(user):
        # admin and user
        if assignees:
            customers.append(get_customer(assignees[0].get('customer')))
            return customers
    else:
        if not authentication.user_is_admin(user):
            # master_user
            for assignee in assignees:
                customers.append(get_customer(assignee.get('customer')))
            return customers
        # super_user and master_admin
        return [{'id': 1, 'name': 'master'}]
Esempio n. 5
0
def _set_customers(user):
    if authentication.has_full_access(user) or authentication.user_is_assigned_master(user):
        user['customers'] = [1]
        return user
    user['customers'] = [a['customer'] for a in assigneesHandler.get_customers(user.get('username'))]
    return user
Esempio n. 6
0
def user_is_assigned_customer(user, customer):
    return customer["id"] in [d["customer"] for d in assigneesHandler.get_customers(user.get("username"))]