providers/*: use PolicyAccessMixin to simplify
This commit is contained in:
		| @ -1,5 +1,4 @@ | ||||
| """passbook OAuth2 Views""" | ||||
| from django.contrib import messages | ||||
| from django.contrib.auth.mixins import LoginRequiredMixin | ||||
| from django.http import HttpRequest, HttpResponse, HttpResponseRedirect | ||||
| from django.shortcuts import get_object_or_404, redirect | ||||
| @ -11,7 +10,6 @@ from structlog import get_logger | ||||
|  | ||||
| from passbook.audit.models import Event, EventAction | ||||
| from passbook.core.models import Application | ||||
| from passbook.core.views.access import AccessMixin | ||||
| from passbook.flows.models import in_memory_stage | ||||
| from passbook.flows.planner import ( | ||||
|     PLAN_CONTEXT_APPLICATION, | ||||
| @ -21,6 +19,7 @@ from passbook.flows.planner import ( | ||||
| from passbook.flows.stage import StageView | ||||
| from passbook.flows.views import SESSION_KEY_PLAN | ||||
| from passbook.lib.utils.urls import redirect_with_qs | ||||
| from passbook.policies.mixins import PolicyAccessMixin | ||||
| from passbook.providers.oauth.models import OAuth2Provider | ||||
| from passbook.stages.consent.stage import PLAN_CONTEXT_CONSENT_TEMPLATE | ||||
|  | ||||
| @ -38,7 +37,7 @@ PLAN_CONTEXT_NONCE = "nonce" | ||||
| PLAN_CONTEXT_SCOPE_DESCRIPTION = "scope_descriptions" | ||||
|  | ||||
|  | ||||
| class AuthorizationFlowInitView(AccessMixin, LoginRequiredMixin, View): | ||||
| class AuthorizationFlowInitView(PolicyAccessMixin, LoginRequiredMixin, View): | ||||
|     """OAuth2 Flow initializer, checks access to application and starts flow""" | ||||
|  | ||||
|     # pylint: disable=unused-argument | ||||
| @ -51,10 +50,8 @@ class AuthorizationFlowInitView(AccessMixin, LoginRequiredMixin, View): | ||||
|         except Application.DoesNotExist: | ||||
|             return redirect("passbook_providers_oauth:oauth2-permission-denied") | ||||
|         # Check permissions | ||||
|         result = self.user_has_access(application, request.user) | ||||
|         result = self.user_has_access(application) | ||||
|         if not result.passing: | ||||
|             for policy_message in result.messages: | ||||
|                 messages.error(request, policy_message) | ||||
|             return redirect("passbook_providers_oauth:oauth2-permission-denied") | ||||
|         # Regardless, we start the planner and return to it | ||||
|         planner = FlowPlanner(provider.authorization_flow) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer