Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
headers={'Accept': 'application/json', 'Content-Type': 'application/json'})
except Exception as e:
logger.error(u'Failed to POST {} because {}'.format(url, e))
raise e
else:
raise ValueError('Error - unsupported HTTP method {}'.format(http_method))
end_time = time.time()
logger.debug(u"Profiling: {}s for {} to {} (with {} / {})".format(end_time - start_time, http_method,
url, params,
json.dumps(_remove_private_info(json_data))))
if r.status_code is not requests.codes['ok']:
logger.info(u'Bad HTTP response to {}: {} {}'.format(r.url, r.status_code, r.reason))
# logger.info(u'\t{}'.format(r.content))
msg = u'Error - got a HTTP status code of {} with the message "{}", body: {}'.format(r.status_code,
r.reason, r.text)
raise mediacloud.error.MCException(msg, r.status_code)
return r
user_mc = user_admin_mediacloud_client()
new_permissions = json.loads(request.form["permissions"])
current_permissions = user_mc.topicPermissionsList(topics_id)['permissions']
# first remove any people that you need to
new_emails = [p['email'] for p in new_permissions]
current_emails = [p['email'] for p in current_permissions]
for email in current_emails:
if email not in new_emails:
user_mc.topicPermissionsUpdate(topics_id, email, 'none')
# now update the remaining permissions
for permission in new_permissions:
if permission['permission'] not in ['read', 'write', 'admin', 'none']:
return json_error_response('Invalid permission value')
try:
user_mc.topicPermissionsUpdate(topics_id, permission['email'], permission['permission'])
except MCException as e:
# show a nice error if they type the email wrong
if 'Unknown email' in e.message:
return jsonify({'success': 0, 'results': e.message})
return jsonify({'success': 1, 'results': user_mc.topicPermissionsList(topics_id)})
def activation_confirm():
logger.debug("activation request from %s", request.args['email'])
try:
results = mc.authActivate(request.args['email'], request.args['activation_token'])
if results['success'] is 1:
redirect_to_return = redirect(AUTH_MANAGEMENT_DOMAIN + '/#/user/activated?success=1')
else:
redirect_to_return = redirect(AUTH_MANAGEMENT_DOMAIN + '/#/user/activated?success=0&msg=' +
results['error'])
except MCException as mce:
# this is long stack trace so we have to trim it for url length support
redirect_to_return = redirect(AUTH_MANAGEMENT_DOMAIN + '/#/user/activated?success=0&msg=' + str(mce[:300]))
return redirect_to_return
def _queryForJson(self, url, params=None, http_method='GET', json_data=None):
# Helper that returns queries to the API as real objects
response = self._query(url, params, http_method, json_data)
# print response.content
response_json = response.json()
# print json.dumps(response_json, indent=2)
if 'error' in response_json:
logger.error(u'Error in response from server on request to {}: {}'.format(url, response_json['error']))
raise mediacloud.error.MCException(response_json['error'], requests.codes['ok'])
return response_json