def put(self, role_id): """ .. http:put:: /roles/1 Update a role **Example request**: .. sourcecode:: http PUT /roles/1 HTTP/1.1 Host: example.com Accept: application/json, text/javascript { "name": "role1", "description": "This is a new description" } **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: text/javascript { "id": 1, "name": "role1", "description": "this is a new description" } :reqheader Authorization: OAuth token to authenticate :statuscode 200: no error :statuscode 403: unauthenticated """ permission = ViewRoleCredentialsPermission(role_id) if permission.can(): self.reqparse.add_argument('name', type=str, location='json', required=True) self.reqparse.add_argument('description', type=str, location='json') self.reqparse.add_argument('users', type=list, location='json') args = self.reqparse.parse_args() return service.update(role_id, args['name'], args.get('description'), args.get('users')) abort(403)
def put(self, role_id, data=None): """ .. http:put:: /roles/1 Update a role **Example request**: .. sourcecode:: http PUT /roles/1 HTTP/1.1 Host: example.com Accept: application/json, text/javascript { "name": "role1", "description": "This is a new description" } **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: text/javascript { "id": 1, "name": "role1", "description": "this is a new description" } :reqheader Authorization: OAuth token to authenticate :statuscode 200: no error :statuscode 403: unauthenticated """ permission = ViewRoleCredentialsPermission(role_id) if permission.can(): return service.update(role_id, data['name'], data.get('description'), data.get('users')) abort(403)
def get(self, role_id): """ .. http:get:: /roles/1/credentials View a roles credentials **Example request**: .. sourcecode:: http GET /users/1 HTTP/1.1 Host: example.com Accept: application/json, text/javascript **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: text/javascript { "username: "******", "password": "******" } :reqheader Authorization: OAuth token to authenticate :statuscode 200: no error :statuscode 403: unauthenticated """ permission = ViewRoleCredentialsPermission(role_id) if permission.can(): role = service.get(role_id) response = make_response( jsonify(username=role.username, password=role.password), 200) response.headers[ 'cache-control'] = 'private, max-age=0, no-cache, no-store' response.headers['pragma'] = 'no-cache' return response abort(403)
def get(self, role_id): """ .. http:get:: /roles/1/credentials View a roles credentials **Example request**: .. sourcecode:: http GET /users/1 HTTP/1.1 Host: example.com Accept: application/json, text/javascript **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: text/javascript { "username: "******", "password": "******" } :reqheader Authorization: OAuth token to authenticate :statuscode 200: no error :statuscode 403: unauthenticated """ permission = ViewRoleCredentialsPermission(role_id) if permission.can(): role = service.get(role_id) response = make_response(jsonify(username=role.username, password=role.password), 200) response.headers['cache-control'] = 'private, max-age=0, no-cache, no-store' response.headers['pragma'] = 'no-cache' return response abort(403)