def get(username=None): if username: user = userHandler.get_user(username) else: user = get_current_user() if user: user = userHandler.safe_fields(user) customers = customerHandler.get_customers_for(user.get('username')) user['customers'] = customers return OkResponse(userHandler.safe_fields(user)) else: return ConflictResponse("Could not fetch the user.")
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'}]
def get(): user = userHandler.get_user() user["password"] = "" user["salt"] = "" return OkResponse(user)