def has_permission(self, request, view): try: if request.method == 'GET': return True r = AuthRequester() response, status_code = r.get_user_info( r.get_token_from_request(request)) auth_json = r.get_data_from_response(response) print(auth_json) try: return int(view.kwargs[view.lookup_url_kwarg] ) == auth_json['id'] or auth_json['is_superuser'] except KeyError: return False except BaseApiRequestError: return False
class IsAuthenticated(BaseAuthPermission): AUTH_REQUESTER = AuthRequester() def has_permission(self, request, view): token = self.AUTH_REQUESTER.get_token_from_request(request) if token is None: return False return AuthRequester().is_token_valid(token)[1]
def delete_billing(self, uuid, token=None): headers = {} if token: headers = AuthRequester()._create_auth_header(token) response = self.delete_request(self.BILLING_HOST + str(uuid) + '/', headers=headers) if response is None: return self.BASE_HTTP_ERROR return self.get_data_from_response(response), response.status_code
class IsAppTokenCorrect(BaseAuthPermission): AUTH_REQUESTER = AuthRequester() def has_permission(self, request, view): token = self.AUTH_REQUESTER.get_token_from_request(request) if token is None: return False view.app_access_token = token return AuthRequester().app_verify_token(token)[1]
def post_billing(self, data={}, token=None): headers = {} if token: headers = AuthRequester()._create_auth_header(token) response = self.post_request(self.BILLING_HOST, data=data, headers=headers) if response is None: return self.BASE_HTTP_ERROR return response, response.status_code
def get_billing(self, uuid, token=None): headers = {} print(uuid) if token: headers = AuthRequester()._create_auth_header(token) response = self.get_request(self.BILLING_HOST + str(uuid) + '/', headers=headers) if response is None: return self.BASE_HTTP_ERROR #print(response.json()) return response, response.status_code
class IsSuperuser(BaseAuthPermission): AUTH_REQUESTER = AuthRequester() def has_permission(self, request, view): print(2) token = self.AUTH_REQUESTER.get_token_from_request(request) if token is None: return False response, response_status_code = self.AUTH_REQUESTER.get_user_info( token) response_data = self.AUTH_REQUESTER.get_data_from_response(response) try: print(response_data['is_superuser']) return response_data['is_superuser'] except KeyError: return False
def has_permission(self, request, view): token = self.AUTH_REQUESTER.get_token_from_request(request) if token is None: return False view.app_access_token = token return AuthRequester().app_verify_token(token)[1]
def has_permission(self, request, view): token = self.AUTH_REQUESTER.get_token_from_request(request) if token is None: return False return AuthRequester().is_token_valid(token)[1]