obs_operator: change to two-level POST paths and same func naming as GET.

This commit is contained in:
Jimmy Berry 2019-05-01 15:04:10 -05:00
parent 491142d2fa
commit d78d9657ae
2 changed files with 16 additions and 11 deletions

View File

@ -29,7 +29,9 @@ class RequestHandler(BaseHTTPRequestHandler):
'origin/package', 'origin/package',
'origin/report', 'origin/report',
] ]
POST_ACTIONS = ['select'] POST_PATHS = [
'staging/select',
]
def do_GET(self): def do_GET(self):
url_parts = urlparse(self.path) url_parts = urlparse(self.path)
@ -67,25 +69,28 @@ class RequestHandler(BaseHTTPRequestHandler):
self.write_string(str(e)) self.write_string(str(e))
def do_POST(self): def do_POST(self):
action = self.path.lstrip('/') url_parts = urlparse(self.path)
if action not in self.POST_ACTIONS:
path = url_parts.path.lstrip('/')
path_parts = path.split('/')
path_prefix = '/'.join(path_parts[:2])
query = parse_qs(url_parts.query)
if len(path_parts) < 2 or path_prefix not in self.POST_PATHS:
self.send_response(404) self.send_response(404)
self.end_headers() self.end_headers()
return return
data = self.data_parse() data = self.data_parse()
user = data.get('user') user = data.get('user')
if not data or not user:
self.send_response(400)
self.end_headers()
return
if self.debug: if self.debug:
print('data: {}'.format(data)) print('data: {}'.format(data))
try: try:
with OSCRequestEnvironment(self, user) as oscrc_file: with OSCRequestEnvironment(self, user) as oscrc_file:
func = getattr(self, 'handle_{}'.format(action)) func = getattr(self, 'handle_{}'.format(path_prefix.replace('/', '_')))
commands = func(data) commands = func(path_parts[2:], query, data)
self.end_headers() self.end_headers()
for command in commands: for command in commands:
@ -210,7 +215,7 @@ class RequestHandler(BaseHTTPRequestHandler):
def staging_command(self, project, subcommand): def staging_command(self, project, subcommand):
return ['osc', 'staging', '-p', project, subcommand] return ['osc', 'staging', '-p', project, subcommand]
def handle_select(self, data): def handle_staging_select(self, args, query, data):
for staging, requests in data['selection'].items(): for staging, requests in data['selection'].items():
command = self.staging_command(data['project'], 'select') command = self.staging_command(data['project'], 'select')
if 'move' in data and data['move']: if 'move' in data and data['move']:

View File

@ -273,7 +273,7 @@ var initMoveInterface = function() {
var data = JSON.stringify({'user': user, 'project': project, 'move': true, 'selection': summary}); var data = JSON.stringify({'user': user, 'project': project, 'move': true, 'selection': summary});
var domain_parent = window.location.hostname.split('.').splice(1).join('.'); var domain_parent = window.location.hostname.split('.').splice(1).join('.');
var subdomain = domain_parent.endsWith('suse.de') ? 'tortuga' : 'operator'; var subdomain = domain_parent.endsWith('suse.de') ? 'tortuga' : 'operator';
var url = 'https://' + subdomain + '.' + domain_parent + '/select'; var url = 'https://' + subdomain + '.' + domain_parent + '/staging/select';
$.post({url: url, data: data, crossDomain: true, xhrFields: {withCredentials: true}, $.post({url: url, data: data, crossDomain: true, xhrFields: {withCredentials: true},
success: applyChangesSuccess}).fail(applyChangesFailed); success: applyChangesSuccess}).fail(applyChangesFailed);
} }