Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/quicksight-access #1432

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controlpanel/frontend/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,11 @@ def set_quicksight_embed_access(self, permission_name, quicksight_access):
permission = Permission.objects.get(codename=codename)

if permission_name in quicksight_access and not self.user.has_perm(f"api.{codename}"):
self.user.user_permissions.add(permission)
identity_store.add_user_to_group(self.user.justice_email, group)
self.user.user_permissions.add(permission)
elif self.user.has_perm(f"api.{codename}"):
self.user.user_permissions.remove(permission)
identity_store.delete_group_membership(self.user.justice_email, group)
self.user.user_permissions.remove(permission)


class FeedbackForm(forms.ModelForm):
Expand Down
2 changes: 1 addition & 1 deletion controlpanel/frontend/jinja2/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"active": page_name == "parameters",
},
{
"hide": not request.user.has_perm("api.quicksight_embed_access"),
"hide": not request.user.has_perm("api.quicksight_embed_author_access") and not request.user.has_perm("api.quicksight_embed_reader_access"),
"text": "QuickSight",
"href": url("quicksight"),
"active": page_name == "quicksight",
Expand Down
12 changes: 10 additions & 2 deletions controlpanel/frontend/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime, timedelta

# Third-party
import structlog
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.models import Permission
Expand All @@ -24,6 +25,8 @@
from controlpanel.frontend.mixins import PolicyAccessMixin
from controlpanel.oidc import OIDCLoginRequiredMixin

log = structlog.getLogger(__name__)


def ninety_days_ago():
"""
Expand Down Expand Up @@ -142,8 +145,13 @@ def get_form_kwargs(self):
return kwargs

def form_valid(self, form):
form.grant_access()
messages.success(self.request, "Successfully updated Quicksight access")
try:
form.grant_access()
messages.success(self.request, "Successfully updated Quicksight access")
except Exception as e:
log.error(f"Could not update QuickSight access - {e}")
messages.error(self.request, "Could not update Quicksight access")

return HttpResponseRedirect(reverse_lazy("manage-user", kwargs={"pk": form.user.auth0_id}))

def form_invalid(self, form):
Expand Down
Loading