Пример #1
0
def task_gold(project_id=None):
    """Make task gold"""
    try:
        if not current_user.is_authenticated:
            return abort(401)

        project = project_repo.get(project_id)

        # Allow project owner, sub-admin co-owners, and admins to update Gold tasks.
        is_gold_access = (current_user.subadmin and current_user.id
                          in project.owners_ids) or current_user.admin
        if project is None or not is_gold_access:
            raise Forbidden
        if request.method == 'POST':
            task_data = json.loads(
                request.form['request_json']
            ) if 'request_json' in request.form else request.json
            task_id = task_data['task_id']
            task = task_repo.get_task(task_id)
            if task.project_id != project_id:
                raise Forbidden
            preprocess_task_run(project_id, task_id, task_data)
            info = task_data['info']
            set_gold_answers(task, info)
            task_repo.update(task)

            response_body = json.dumps({'success': True})
        else:
            task = sched.select_task_for_gold_mode(project, current_user.id)
            if task:
                task = task.dictize()
                sign_task(task)
            response_body = json.dumps(task)
        return Response(response_body, 200, mimetype="application/json")
    except Exception as e:
        return error.format_exception(e,
                                      target='taskgold',
                                      action=request.method)
Пример #2
0
def add_task_signature(tasks):
    if current_app.config.get('ENABLE_ENCRYPTION'):
        for task in tasks:
            sign_task(task)
Пример #3
0
 def _sign_item(self, item):
     project_id = item['project_id']
     if current_user.admin or \
        current_user.id in get_project_data(project_id)['owners_ids']:
         sign_task(item)