Start of support for pushing activities from SVN hooks.
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import functools
|
||||
import logging
|
||||
|
||||
from flask import Blueprint, render_template, url_for
|
||||
from flask import Blueprint, render_template, url_for, request, current_app
|
||||
import flask_login
|
||||
|
||||
from pillar.web.utils import attach_project_pictures
|
||||
from pillar.api.utils import jsonify
|
||||
from pillar.api.utils import authorization, authentication
|
||||
import pillar.web.subquery
|
||||
from pillar.web.system_util import pillar_api
|
||||
import pillarsdk
|
||||
import werkzeug.exceptions as wz_exceptions
|
||||
|
||||
from attract import current_attract
|
||||
from attract import current_attract, EXTENSION_NAME
|
||||
from attract.node_types.task import node_type_task
|
||||
from attract.node_types.shot import node_type_shot
|
||||
|
||||
@@ -38,7 +40,7 @@ def index():
|
||||
projs_with_summaries = [
|
||||
(proj, current_attract.shot_manager.shot_status_summary(proj['_id']))
|
||||
for proj in projects['_items']
|
||||
]
|
||||
]
|
||||
|
||||
# Fetch all activities for all Attract projects.
|
||||
id_to_proj = {p['_id']: p for p in projects['_items']}
|
||||
@@ -168,10 +170,65 @@ def subversion_kick(project, attract_props):
|
||||
})
|
||||
|
||||
|
||||
@blueprint.route('/api/<project_url>/subversion/log', methods=['POST'])
|
||||
@authorization.require_login(require_roles={u'service', u'svner'}, require_all=True)
|
||||
def subversion_log(project_url):
|
||||
if request.mimetype != 'application/json':
|
||||
log.debug('Received %s instead of application/json', request.mimetype)
|
||||
raise wz_exceptions.BadRequest()
|
||||
|
||||
# Parse the request
|
||||
args = request.json
|
||||
revision = args['revision']
|
||||
commit_message = args['log']
|
||||
commit_author = args['author']
|
||||
|
||||
current_user_id = authentication.current_user_id()
|
||||
log.info('Service account %s registers SVN commit %s of user %s',
|
||||
current_user_id, revision, commit_author)
|
||||
assert current_user_id
|
||||
|
||||
users_coll = current_app.db()['users']
|
||||
projects_coll = current_app.db()['projects']
|
||||
project = projects_coll.find_one({'url': project_url},
|
||||
projection={'_id': 1, 'url': 1,
|
||||
'extension_props': 1})
|
||||
if not project:
|
||||
return 'Project not found', 403
|
||||
|
||||
# Check that the service user is allowed to log on this project.
|
||||
srv_user = users_coll.find_one(current_user_id,
|
||||
projection={'service.svner': 1})
|
||||
if srv_user is None:
|
||||
log.error('subversion_log(%s): current user %s not found -- how did they log in?',
|
||||
project['url'], current_user_id)
|
||||
return 'User not found', 403
|
||||
|
||||
allowed_project = srv_user.get('service', {}).get('svner', {}).get('project')
|
||||
if allowed_project != project['_id']:
|
||||
log.warning('subversion_log(%s): current user %s not authorized to project %s',
|
||||
project['url'], current_user_id, project['_id'])
|
||||
return 'Project not allowed', 403
|
||||
|
||||
from . import subversion
|
||||
|
||||
try:
|
||||
attract_props = project['extension_props'][EXTENSION_NAME]
|
||||
except KeyError:
|
||||
return 'Not set up for Attract', 400
|
||||
|
||||
svn_server_url = attract_props['svn_url']
|
||||
log.info('Re-examining SVN server %s', svn_server_url)
|
||||
client = subversion.obtain(svn_server_url)
|
||||
observer = subversion.CommitLogObserver(client)
|
||||
observer.process_log(revision, commit_author, commit_message)
|
||||
|
||||
return 'Registered in Attract'
|
||||
|
||||
|
||||
@blueprint.route('/<project_url>')
|
||||
@attract_project_view(extension_props=True)
|
||||
def project_index(project, attract_props):
|
||||
|
||||
return render_template('attract/project.html',
|
||||
project=project,
|
||||
attract_props=attract_props)
|
||||
@@ -180,7 +237,6 @@ def project_index(project, attract_props):
|
||||
@blueprint.route('/<project_url>/help')
|
||||
@attract_project_view(extension_props=False)
|
||||
def help(project):
|
||||
|
||||
nt_task = project.get_node_type(node_type_task['name'])
|
||||
nt_shot = project.get_node_type(node_type_shot['name'])
|
||||
|
||||
|
Reference in New Issue
Block a user