Ejemplo n.º 1
0
 def _put(self, username, permission, changed_by, transaction):
     try:
         if dbo.permissions.getUserPermissions(username, transaction).get(permission):
             form = ExistingPermissionForm()
             if not form.data_version.data:
                 raise ValueError("Must provide the data version when updating an existing permission.")
             dbo.permissions.updatePermission(changed_by, username, permission, form.data_version.data, form.options.data, transaction=transaction)
             new_data_version = dbo.permissions.getPermission(username=username, permission=permission, transaction=transaction)['data_version']
             return make_response(json.dumps(dict(new_data_version=new_data_version)), 200)
         else:
             form = NewPermissionForm()
             dbo.permissions.grantPermission(changed_by, username, permission, form.options.data, transaction=transaction)
             return make_response(json.dumps(dict(new_data_version=1)), 201)
     except ValueError, e:
         cef_event("Bad input", CEF_WARN, errors=e.args)
         return Response(status=400, response=e.args)
Ejemplo n.º 2
0
 def _put(self, username, permission, changed_by, transaction):
     try:
         if dbo.permissions.getUserPermissions(username,
                                               transaction).get(permission):
             form = ExistingPermissionForm()
             if not form.validate():
                 self.log.warning("Bad input: %s", form.errors)
                 return Response(status=400,
                                 response=json.dumps(form.errors))
             dbo.permissions.update(where={
                 "username": username,
                 "permission": permission
             },
                                    what={"options": form.options.data},
                                    changed_by=changed_by,
                                    old_data_version=form.data_version.data,
                                    transaction=transaction)
             new_data_version = dbo.permissions.getPermission(
                 username=username,
                 permission=permission,
                 transaction=transaction)['data_version']
             return jsonify(new_data_version=new_data_version)
         else:
             form = NewPermissionForm()
             if not form.validate():
                 self.log.warning("Bad input: %s", form.errors)
                 return Response(status=400,
                                 response=json.dumps(form.errors))
             dbo.permissions.insert(changed_by,
                                    transaction=transaction,
                                    username=username,
                                    permission=permission,
                                    options=form.options.data)
             return Response(status=201,
                             response=json.dumps(dict(new_data_version=1)))
     except ValueError as e:
         self.log.warning("Bad input: %s", e.args)
         return Response(status=400, response=e.args)
Ejemplo n.º 3
0
 def _put(self, username, permission, changed_by, transaction):
     try:
         if dbo.permissions.getUserPermissions(username,
                                               transaction).get(permission):
             form = ExistingPermissionForm()
             if not form.validate():
                 self.log.warning("Bad input: %s", form.errors)
                 return Response(status=400,
                                 response=json.dumps(form.errors))
             dbo.permissions.updatePermission(changed_by,
                                              username,
                                              permission,
                                              form.data_version.data,
                                              form.options.data,
                                              transaction=transaction)
             new_data_version = dbo.permissions.getPermission(
                 username=username,
                 permission=permission,
                 transaction=transaction)['data_version']
             return make_response(
                 json.dumps(dict(new_data_version=new_data_version)), 200)
         else:
             form = NewPermissionForm()
             if not form.validate():
                 self.log.warning("Bad input: %s", form.errors)
                 return Response(status=400,
                                 response=json.dumps(form.errors))
             dbo.permissions.grantPermission(changed_by,
                                             username,
                                             permission,
                                             form.options.data,
                                             transaction=transaction)
             return make_response(json.dumps(dict(new_data_version=1)), 201)
     except ValueError as e:
         self.log.warning("Bad input: %s", e.args)
         return Response(status=400, response=e.args)