def assign_responsible(name, form): """ Assigning a responsible to a project. Admins do that without check with any users. For non admins several conditions has to be satisfied: 1) New responsible has to be different user. 2) New responsible should be one of project's users :param name: String. Name of the project :param form: WTForm. Form with data :return: object. Instance of ProjectLog object """ if not form.validate_on_submit(): raise ValueError(form_error_string(form.errors)) uid = form.login.data send = form.send.data user = user_by_id(uid) if "admin" in current_user.permissions(): project = get_project_by_name(name) else: project = check_responsible(name) if user == project.responsible: raise ValueError("User %s is already responsible for the project %s" % (user.full_name(), project.get_name())) if "admin" in current_user.permissions(): task = TaskQueue().project(project).responsible_assign(user).task Task(task).accept() return ProjectLog(project).send_message(send).responsible_assign(task) if user not in project.users: raise ValueError("New responsible has to be one of the project users") task = TaskQueue().project(project).responsible_assign(user).task return ProjectLog(project).responsible_assign(task)
def project_create_user(name, form): """ Function which creates a temporary user based on provide info and add a create user task in the task queue :param name: String. Name of the project where a use should be created :param form: Instance of WTForm :return: Instance of a project to which a new user has to be attached and an instance of TmpUser class """ project = check_responsible(name) prenom = form.prenom.data.strip().lower() surname = form.surname.data.strip().lower() email = form.email.data.strip().lower() if User.query.filter(User.email == email).first(): raise ValueError("User with e-mail %s has been registered already" % email) user = TmpUser() user.login = generate_login(prenom, surname) user.password = generate_password(16) user.name = prenom user.surname = surname user.email = email task = TaskQueue().project(project).user_create(user).task if current_user.login and "admin" in current_user.permissions(): Task(task).accept() return ProjectLog(project).user_create(task)
def web_modal_responsible(pid): project = get_project_record(pid) if "admin" in current_user.permissions(): form = new_responsible(project, True) else: form = new_responsible(project, False) return jsonify( render_template("modals/project_add_responsible.html", form=form))
def decorated_view(*args, **kwargs): if not (current_user and current_user.is_authenticated): return login_manager.unauthorized() acceptable_permissions = set(("ANY", *current_user.permissions())) if permission not in acceptable_permissions: return login_manager.unauthorized() return func(*args, **kwargs)
def project_attach_user(name, form): """ Function which attach an existing user to a given project :param name: String. Name of the project to which user should be attached :param form: Instance of WTForm :return: Instance of a project to which a new user has to be attached and an instance of User class """ project = check_responsible(name) uid = form.login.data user = User.query.filter(User.id == uid).first() if not user: raise ValueError("Failed to find user with ID '%s' in database" % uid) if user in project.users: raise ValueError("User %s has been already attached to project %s" % (user.full(), project.get_name())) task = TaskQueue().project(project).user_assign(user).task if "admin" in current_user.permissions(): Task(task).accept() return ProjectLog(project).user_assign(task)
def first_request(): logging.debug("-" * 80) user_list = cache.get("user_list") if not user_list: users_obj = User.query.all() users = map(lambda x: x.login, users_obj) user_list = sorted(list(users)) cache.set("user_list", user_list, 600) g.user_list = user_list if current_user.is_authenticated: g.permissions = current_user.permissions() else: g.permissions = [] tmp = "%s" % dt.now() g.timestamp = tmp.split(".")[0] url_list = cache.get("url_list") if not url_list: url_list = ["%s" % rule for rule in app.url_map.iter_rules()] cache.set("url_list", url_list, 600) g.url_list = url_list
def is_accessible(self): return (current_user.is_authenticated and len(current_user.permissions()) != 0)
def is_accessible(self): print(current_user.permissions()) return "post_verification" in { i.split()[0] for i in current_user.permissions() }
def is_accessible(self): return "role" in {i.split()[0] for i in current_user.permissions()}
def can_delete(self): return "role w" in current_user.permissions()
def can_edit(self): return "role w" in current_user.permissions()