def delete(self, request, *args, **kwargs): info = EnvView.RequestInfo(request, *args, **kwargs) if not info.valid: return info.error_message env = info.auth.get_env(info.env) try: env.delete(info.path, info.override) end_request(request, info.auth) return {'Response': 'Ok'} except Exception as e: return {'Response': 'Failure', 'Message': e.message}
def get(self, request, *args, **kwargs): info = EnvView.RequestInfo(request, *args, **kwargs) if not info.valid: return info.error_message call_args = [info.auth, info.env, info.path, info.override] if 'viewchildren' in request.GET: ret = EnvView.get_children_for(*call_args) elif 'viewhistory' in request.GET: ret = EnvView.get_history_for(*call_args) else: ret = EnvView.get_value_for(*call_args) end_request(request, info.auth) return ret
def post(self, request, *args, **kwargs): info = EnvView.RequestInfo(request, *args, **kwargs) if not info.valid: return info.error_message value = request.data.get('value', None) protect = request.data.get('protect', None) if (info.path is None) or (info.env is None) or\ ((value is None) and (protect is None)): return { 'Response': 'Failure', 'Message': 'Expected an environment, name, and value or ' 'protect to create' } if protect is not None: protect = str(protect).upper() in ['1', 'TRUE', 'Y', 'YES', ] env = info.auth.get_env(info.env) if int(env.permissions) < Rights.Write: return { 'Response': 'Failure', 'Message': 'Do not have write permissions to {}'.format(info.env) } try: if protect is not None: # cannot set protect if doesn't exist, so ensure it exists exist = env.get_explicit(info.path, info.override) if (exist is None) or (exist[0] is None): env.set(info.path, '', info.override) env.set_protect(protect, info.path, info.override) if value is not None: env.set(info.path, value, info.override) end_request(request, info.auth) return {'Response': 'Ok'} except Exception as e: return {'Response': 'Failure', 'Message': e.message}