-
Notifications
You must be signed in to change notification settings - Fork 7
removed excess tom toolkit overwrite and added snex1 pw account deletion sync #148
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ | |
| from tom_targets.models import TargetList, Target, TargetName | ||
| from custom_code.models import TNSTarget, ScienceTags, TargetTags, ReducedDatumExtra, Papers, InterestedPersons, BrokerTarget | ||
| from custom_code.filters import TNSTargetFilter, CustomTargetFilter, BrokerTargetFilter, BrokerTargetForm | ||
| from custom_code.forms import SNEx2UserCreationForm | ||
| from guardian.mixins import PermissionListMixin | ||
| from guardian.models import GroupObjectPermission | ||
| from guardian.shortcuts import get_objects_for_user, assign_perm, remove_perm, get_users_with_perms | ||
|
|
@@ -29,6 +28,8 @@ | |
| from django.contrib import messages | ||
| from django.conf import settings | ||
| from django.db.models.fields.json import KeyTextTransform | ||
| from django.contrib.auth.signals import user_logged_in | ||
| import crypt | ||
|
|
||
| from astropy.coordinates import SkyCoord | ||
| from astropy import units as u | ||
|
|
@@ -346,50 +347,39 @@ def get_initial(self): | |
| 'groups': Group.objects.filter(name__in=settings.DEFAULT_GROUPS), | ||
| **dict(self.request.GET.items()) | ||
| } | ||
|
|
||
|
|
||
| class CustomUserUpdateView(UserUpdateView): | ||
|
|
||
| form_class = SNEx2UserCreationForm | ||
|
|
||
| def get_success_url(self): | ||
| """ | ||
| Returns the redirect URL for a successful update. If the current user is a superuser, returns the URL for the | ||
| user list. Otherwise, returns the URL for updating the current user. | ||
|
|
||
| :returns: URL for user list or update user | ||
| :rtype: str | ||
| """ | ||
| if self.request.user.is_superuser: | ||
| return reverse_lazy('user-list') | ||
| else: | ||
| return reverse_lazy('custom_code:custom-user-update', kwargs={'pk': self.request.user.id}) | ||
|
|
||
| def dispatch(self, *args, **kwargs): | ||
| """ | ||
| Directs the class-based view to the correct method for the HTTP request method. Ensures that non-superusers | ||
| are not incorrectly updating the profiles of other users. | ||
| """ | ||
| if not self.request.user.is_superuser and self.request.user.id != self.kwargs['pk']: | ||
| return redirect('custom_code:custom-user-update', self.request.user.id) | ||
| else: | ||
| return super().dispatch(*args, **kwargs) | ||
|
|
||
| def form_valid(self, form): | ||
| old_username = self.get_object().username | ||
| super().form_valid(form) | ||
| run_hook('sync_users_with_snex1', self.get_object(), False, old_username) | ||
| return redirect(self.get_success_url()) | ||
|
|
||
|
|
||
| class SNEx2UserApprovalView(UserApprovalView): | ||
|
|
||
| def form_valid(self, form): | ||
| response = super().form_valid(form) | ||
| run_hook("sync_users_with_snex1", self.get_object(), True) | ||
|
|
||
| return response | ||
|
|
||
| def encrypt_pw(pw=None): | ||
| if not pw: | ||
| return None | ||
|
|
||
| chars = 'abcdefghijklmnopqrstuvwxyz' \ | ||
| 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \ | ||
| '0123456789' | ||
|
|
||
| salt = '' | ||
| for i in range(2): | ||
| salt += random.choice(chars) | ||
|
|
||
| encpw = crypt.crypt(pw, salt) | ||
|
|
||
| return encpw | ||
|
|
||
| @receiver(user_logged_in) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be a dumb question, but does this run every time the user logs in, or just the first time? Doing this every time is probably overkill |
||
| def snex1_pw_sync(sender, request, user, **kwargs): | ||
| logger.info(f"Receiver called, User {user.username} has logged in. request: {request}") | ||
| password = request.POST.get("password") | ||
| logger.info(f"password: {password}") | ||
| snex1_pw = encrypt_pw(password) | ||
| logger.info(f'snex1pw: {snex1_pw}') | ||
| run_hook('sync_users_with_snex1', user, snex1_pw = snex1_pw) | ||
|
|
||
| @receiver(post_delete, sender=User) | ||
| def user_account_remove(sender, instance, **kwargs): | ||
| logger.info(f'user account deleted {instance.username}') | ||
| logger.info(f'what is instance? {instance}') | ||
| logger.info(f'type instance? {type(instance)}') | ||
| logger.info(f'keys for instance? {dir(instance)}') | ||
| run_hook('sync_users_with_snex1', instance, delete = True) | ||
|
|
||
| class CustomDataProductUploadView(DataProductUploadView): | ||
|
|
||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does deleting users work in SNEx1? I don't know if I've ever done it, so not sure what the implications would be on anything that's connected to the user. Hopefully not a cascading delete on things like observation sequences, targets, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point, I haven't tested it with that, I'll need to go through and check this.