Moved Subversion stuff to its own module, and unified push & pull approaches

This commit is contained in:
2016-11-01 11:58:12 +01:00
parent b8d12d1a4d
commit bc58b6d5ac
7 changed files with 198 additions and 114 deletions

View File

@@ -1,18 +1,15 @@
import functools
import logging
from flask import Blueprint, render_template, url_for, request, current_app
from flask import Blueprint, render_template, url_for
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, EXTENSION_NAME
from attract import current_attract
from attract.node_types.task import node_type_task
from attract.node_types.shot import node_type_shot
@@ -150,82 +147,6 @@ def attract_project_view(extra_project_projections=None, extension_props=False):
return decorator
@blueprint.route('/<project_url>/subversion/kick')
@attract_project_view(extension_props=True)
def subversion_kick(project, attract_props):
from . import subversion
svn_server_url = attract_props.svn_url # 'svn://localhost/agent327'
log.info('Re-examining SVN server %s', svn_server_url)
client = subversion.obtain(svn_server_url)
# TODO: last_seen_revision should be stored, probably at the project level.
last_seen_revision = 0
observer = subversion.CommitLogObserver(client, last_seen_revision=last_seen_revision)
observer.fetch_and_observe()
return jsonify({
'previous_last_seen_revision': last_seen_revision,
'last_seen_revision': observer.last_seen_revision,
})
@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):