mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-12 23:27:22 +00:00
URSH: Include indico user id in metadata
At least for custom shortcuts, since those are only available to event managers and it may be useful to know who created such a shortcut, e.g. in case of very inappropriate shortcuts.
This commit is contained in:
parent
3fd3f3d0fb
commit
51405ed3d9
@ -9,7 +9,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import posixpath
|
||||
|
||||
from flask import jsonify, request
|
||||
from flask import jsonify, request, session
|
||||
from flask_pluginengine import render_plugin_template
|
||||
from werkzeug.exceptions import BadRequest
|
||||
from werkzeug.urls import url_parse
|
||||
@ -17,7 +17,7 @@ from werkzeug.urls import url_parse
|
||||
from indico.core.config import config
|
||||
from indico.modules.events.management.controllers import RHManageEventBase
|
||||
from indico.web.rh import RH
|
||||
from indico.web.util import jsonify, jsonify_template
|
||||
from indico.web.util import jsonify_template
|
||||
|
||||
from indico_ursh import _
|
||||
from indico_ursh.util import register_shortcut, request_short_url, strip_end
|
||||
@ -84,7 +84,7 @@ class RHCustomShortURLPage(RHManageEventBase):
|
||||
def _process_POST(self):
|
||||
original_url = self._make_absolute_url(request.args['original_url'])
|
||||
shortcut = request.form['shortcut'].strip()
|
||||
result = register_shortcut(original_url, shortcut)
|
||||
result = register_shortcut(original_url, shortcut, session.user)
|
||||
|
||||
if result.get('error'):
|
||||
kwargs = {'success': False, 'msg': self._get_error_msg(result)}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import posixpath
|
||||
|
||||
import requests
|
||||
@ -26,21 +27,21 @@ def _get_settings():
|
||||
|
||||
def request_short_url(original_url):
|
||||
api_key, api_host = _get_settings()
|
||||
headers = {'Authorization': 'Bearer {api_key}'.format(api_key=api_key)}
|
||||
headers = {'Authorization': 'Bearer {api_key}'.format(api_key=api_key), 'Content-Type': 'application/json'}
|
||||
url = posixpath.join(api_host, 'api/urls/')
|
||||
|
||||
response = requests.post(url, data={'url': original_url, 'allow_reuse': True}, headers=headers)
|
||||
response = requests.post(url, data=json.dumps({'url': original_url, 'allow_reuse': True}), headers=headers)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
return data['short_url']
|
||||
|
||||
|
||||
def register_shortcut(original_url, shortcut):
|
||||
def register_shortcut(original_url, shortcut, user):
|
||||
api_key, api_host = _get_settings()
|
||||
headers = {'Authorization': 'Bearer {api_key}'.format(api_key=api_key)}
|
||||
headers = {'Authorization': 'Bearer {api_key}'.format(api_key=api_key), 'Content-Type': 'application/json'}
|
||||
url = posixpath.join(api_host, 'api/urls', shortcut)
|
||||
|
||||
response = requests.put(url, data={'url': original_url, 'allow_reuse': True}, headers=headers)
|
||||
data = {'url': original_url, 'allow_reuse': True, 'metadata': {'indico.user': user.id}}
|
||||
response = requests.put(url, data=json.dumps(data), headers=headers)
|
||||
if not (400 <= response.status_code < 500):
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user