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

Add per-hunt access permissions #753

Merged
merged 11 commits into from
Dec 15, 2024
Merged

Conversation

rgossiaux
Copy link
Contributor

After this change, anyone is allowed to log in to cardboard, but they can only see hunts that they have access to. For the moment, users gain access to a hunt via a button on the /edit page that syncs permissions from the Drive folder. Note that this only gives people access, it never removes access right now.


UserModel = get_user_model()
emails = get_file_user_emails.run(hunt.settings.google_drive_folder_id)
print(f"Found emails {emails}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, delete these

@rgossiaux rgossiaux requested a review from rawxfish January 21, 2024 05:57
@rgossiaux
Copy link
Contributor Author

I think I want to write some tests before trying to ship this but looking for feedback anyway

@@ -22,6 +22,7 @@ redis = "^4.1.0"
django-celery-beat = "^2.4.0"
python-dateutil = "^2.8.2"
django-cors-headers = "^4.3.1"
django-guardian = "^2.4.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh cool, didn't know something like this existed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember researching it when @rgossiaux brought it up in #191

Should we be concerned that the codebase hasn't been touched in 2+ years? https://github.com/django-guardian/django-guardian

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On that note, is there a reason to use django-guardian over the per-object permissions provided by DRF? https://www.django-rest-framework.org/api-guide/permissions/#object-level-permissions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I know it's the most popular/mature library for this in the django ecosystem. No commits in 2 years is probably a bit worrying but I'm just doing pretty basic core stuff with it so I'm personally not too bothered atm

DRF provides view methods for checking permissions (I'm using them in this PR already I think), but not a permissions backend itself. Still need some way of storing permissions in the DB--that's what django-guardian provides

@@ -131,11 +131,6 @@ Global Google Drive, Sheets, and API settings for automatic sheets creation:
* `GOOGLE_API_PRIVATE_KEY` - the private key for the key you added, with newlines replaced with `\n` (should be the value of the `private_key` field in the downloaded JSON when you [created the key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating_service_account_keys); should look something like `-----BEGIN ... KEY-----\n...<long base64-encoded key>...\n-----END ... KEY-----\n`)
* `GOOGLE_API_X509_CERT_URL` - the value of the `client_x509_cert_url` field in the downloaded JSON when you [created the key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating_service_account_keys)

Hunt-specific Google settings:

* `GOOGLE_DRIVE_HUNT_FOLDER_ID` - the id of your Google Drive folder, should be part of the URL (`https://drive.google.com/drive/folders/<folder_id>`). This environment variable is used for getting the list of allowed emails for OAuth. Please keep consistent with the value in HuntSettings. Deprecating this variable is tracked in #662.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh we still use it as the default value in google_api_lib/tasks.py, probably should clean this up or make an issue to clean it up later.

Copy link
Collaborator

@rawxfish rawxfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look great, woo!

@rgossiaux rgossiaux force-pushed the rgossiaux/object-permissions branch from bc140c6 to 35537f5 Compare December 15, 2024 06:52
@rgossiaux rgossiaux merged commit ad23798 into main Dec 15, 2024
2 checks passed
@rgossiaux rgossiaux deleted the rgossiaux/object-permissions branch December 15, 2024 08:11
@calvinballing
Copy link
Contributor

This change appears to have broken the hunt settings page by removing the submit button from the associated form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants