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

View and edit permissions for dashboards #27

Closed
simonw opened this issue Mar 15, 2021 · 9 comments
Closed

View and edit permissions for dashboards #27

simonw opened this issue Mar 15, 2021 · 9 comments
Labels
enhancement New feature or request security

Comments

@simonw
Copy link
Owner

simonw commented Mar 15, 2021

The ability to control who can view a dashboard, and who can edit a dashboard at the individual dashboard level.

@simonw simonw added enhancement New feature or request security labels Mar 15, 2021
@simonw
Copy link
Owner Author

simonw commented Mar 15, 2021

I'm going to optionally use Django auth groups for this, if they are defined.

I think a select box for "who can view" and a select box for "who can edit" will work. Following options:

  • Anyone (available for view but not for edit)
  • Only me (effectively private dashboards)
  • Logged in users
  • Staff users
  • Super users
  • Users in group X (one option for each group)

@simonw
Copy link
Owner Author

simonw commented Mar 15, 2021

I'm going to add six columns to Dashboard for this:

  • created_by - foreign key to User
  • created_at - datetime
  • view_policy - enum
  • edit_policy - enum
  • view_group - nullable foreign key to Group
  • edit_group - nullable foreign key to Group

@simonw
Copy link
Owner Author

simonw commented Mar 15, 2021

The policy enums will cover:

  • public (not for view, just edit)
  • creator
  • loggedin_users
  • group
  • staff
  • superusers

@simonw
Copy link
Owner Author

simonw commented Mar 15, 2021

Another view permission option: unlisted - available to the public but only if they know the dashboard URL.

These ones won't be shown on the /dashboard/ index page and will have robots SEO exclusion.

@simonw
Copy link
Owner Author

simonw commented Mar 16, 2021

Model changes in the admin (I customized the admin fieldsets):

Mozilla_Firefox

@simonw
Copy link
Owner Author

simonw commented Mar 16, 2021

class Dashboard(models.Model):
slug = models.SlugField(unique=True)
title = models.CharField(blank=True, max_length=128)
description = models.TextField(blank=True)
created_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="created_dashboards",
)
created_at = models.DateTimeField(default=timezone.now())
class ViewPolicies(models.TextChoices):
PRIVATE = ("private", "Private")
PUBLIC = ("public", "Public")
UNLISTED = ("unlisted", "Unlisted")
LOGGEDIN = ("loggedin", "Logged-in users")
GROUP = ("group", "Users in group")
STAFF = ("staff", "Staff users")
SUPERUSER = ("superuser", "Superusers")
class EditPolicies(models.TextChoices):
PRIVATE = ("private", "Private")
LOGGEDIN = ("loggedin", "Logged-in users")
GROUP = ("group", "Users in group")
STAFF = ("staff", "Staff users")
SUPERUSER = ("superuser", "Superusers")
# Permissions
view_policy = models.CharField(
max_length=10,
choices=ViewPolicies.choices,
default=ViewPolicies.PRIVATE,
)
edit_policy = models.CharField(
max_length=10,
choices=EditPolicies.choices,
default=EditPolicies.PRIVATE,
)
view_group = models.ForeignKey(
"auth.Group",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="can_view_dashboards",
)
edit_group = models.ForeignKey(
"auth.Group",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="can_edit_dashboards",
)

@simonw
Copy link
Owner Author

simonw commented Mar 16, 2021

I'm going to change created_by to owned_by since that makes it clear that it's OK for a user to "transfer ownership" of a dashboard to someone else.

@simonw
Copy link
Owner Author

simonw commented Mar 16, 2021

Next steps: get the dashboards to obey these permissions, with comprehensive tests. Editing can still happen through the admin interface for the moment.

Dashboards should include a visible note that explains who is allowed to edit or view the dashboard.

@simonw
Copy link
Owner Author

simonw commented Mar 21, 2021

The remaining edit work will take place in #44.

@simonw simonw closed this as completed Mar 21, 2021
@simonw simonw unpinned this issue Mar 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request security
Projects
None yet
Development

No branches or pull requests

1 participant