From a52b1d7f378c3cc7742bf68a442c82c3fdf79a51 Mon Sep 17 00:00:00 2001 From: Micha Hulsbosch Date: Wed, 3 Jul 2024 15:03:41 +0200 Subject: [PATCH] chore: Remove unused can_view_dataset refs #1281 --- signbank/context_processors.py | 2 +- signbank/dictionary/adminviews.py | 35 +++++++++---------- signbank/dictionary/models.py | 7 +--- .../dictionary/admin_dataset_list.html | 4 +-- .../dictionary/admin_dataset_select_list.html | 2 +- signbank/dictionary/tests.py | 30 ++++++++-------- signbank/dictionary/update.py | 4 +-- signbank/registration/views.py | 6 ++-- signbank/tools.py | 2 +- 9 files changed, 43 insertions(+), 49 deletions(-) diff --git a/signbank/context_processors.py b/signbank/context_processors.py index 3f7408503..8dd5b6b78 100755 --- a/signbank/context_processors.py +++ b/signbank/context_processors.py @@ -26,7 +26,7 @@ def url(request): viewable_datasets.append(dataset) continue permissions_for_dataset = get_user_perms(request.user, dataset) - if 'view_dataset' in permissions_for_dataset or 'can_view_dataset' in permissions_for_dataset: + if 'view_dataset' in permissions_for_dataset: viewable_datasets.append(dataset) return {'URL': settings.URL, diff --git a/signbank/dictionary/adminviews.py b/signbank/dictionary/adminviews.py index 04b0d4993..f8119fd6b 100755 --- a/signbank/dictionary/adminviews.py +++ b/signbank/dictionary/adminviews.py @@ -840,7 +840,7 @@ def get(self, request, *args, **kwargs): return HttpResponseRedirect(reverse('registration:login')) dataset_of_requested_gloss = self.object.lemma.dataset - datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) if dataset_of_requested_gloss not in selected_datasets: @@ -1279,7 +1279,7 @@ def get_context_data(self, **kwargs): context['dataset_choices'] = {} user = self.request.user if user.is_authenticated: - qs = get_objects_for_user(user, ['view_dataset', 'can_view_dataset'], Dataset, accept_global_perms=True, any_perm=True) + qs = get_objects_for_user(user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) dataset_choices = {} for dataset in qs: dataset_choices[dataset.acronym] = dataset.acronym @@ -1462,7 +1462,7 @@ def get(self, request, *args, **kwargs): return HttpResponseRedirect(reverse('registration:login')) dataset_of_requested_gloss = self.object.lemma.dataset - datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) if dataset_of_requested_gloss not in selected_datasets: @@ -1575,7 +1575,7 @@ def get(self, request, *args, **kwargs): return HttpResponseRedirect(reverse('registration:login')) dataset_of_requested_gloss = self.object.lemma.dataset - datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) if dataset_of_requested_gloss not in selected_datasets: @@ -2841,7 +2841,7 @@ def get_queryset(self): checker.prefetch_perms(qs) for dataset in qs: - checker.has_perm('can_view_dataset', dataset) or checker.has_perm('view_dataset', dataset) + checker.has_perm('view_dataset', dataset) return qs else: @@ -2879,7 +2879,7 @@ def get(self, request, *args, **kwargs): return HttpResponseRedirect(reverse('registration:login')) dataset_of_requested_gloss = self.object.lemma.dataset - datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) if dataset_of_requested_gloss not in selected_datasets: @@ -2948,7 +2948,7 @@ def get_context_data(self, **kwargs): context['dataset_choices'] = {} user = self.request.user if user.is_authenticated: - qs = get_objects_for_user(user, ['view_dataset', 'can_view_dataset'], + qs = get_objects_for_user(user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) dataset_choices = {} for dataset in qs: @@ -3097,7 +3097,7 @@ def get_context_data(self, **kwargs): context['dataset_choices'] = {} user = self.request.user if user.is_authenticated: - qs = get_objects_for_user(user, ['view_dataset', 'can_view_dataset'], + qs = get_objects_for_user(user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) dataset_choices = {} for dataset in qs: @@ -3519,14 +3519,14 @@ def render_to_request_response(self, context): # make sure the user can write to this dataset from guardian.shortcuts import get_objects_for_user, assign_perm - user_view_datasets = get_objects_for_user(self.request.user, ['view_dataset', 'can_view_dataset'], + user_view_datasets = get_objects_for_user(self.request.user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) may_request_dataset = True if dataset_object.is_public and not dataset_object in user_view_datasets: # the user currently has no view permission for the requested dataset # Give permission to access dataset may_request_dataset = True - assign_perm('can_view_dataset', self.request.user, dataset_object) + assign_perm('view_dataset', self.request.user, dataset_object) messages.add_message(self.request, messages.INFO, _('View permission for user successfully granted.')) elif not dataset_object.is_public and not dataset_object in user_view_datasets: @@ -3682,7 +3682,7 @@ def get_queryset(self): checker.prefetch_perms(qs) for dataset in qs: - checker.has_perm('can_view_dataset', dataset) or checker.has_perm('view_dataset', dataset) + checker.has_perm('view_dataset', dataset) qs = qs.annotate(Count('lemmaidgloss__gloss')).order_by('acronym') @@ -3879,7 +3879,7 @@ def render_to_add_user_response(self, context): from guardian.shortcuts import assign_perm, remove_perm datasets_user_can_change = get_objects_for_user(user_object, 'change_dataset', Dataset, accept_global_perms=False) - datasets_user_can_view = get_objects_for_user(user_object, ['view_dataset', 'can_view_dataset'], + datasets_user_can_view = get_objects_for_user(user_object, ['view_dataset'], Dataset, accept_global_perms=False, any_perm=True) groups_user_is_in = Group.objects.filter(user=user_object) @@ -3895,7 +3895,7 @@ def render_to_add_user_response(self, context): return HttpResponseRedirect(reverse('admin_dataset_manager')+'?'+manage_identifier) try: - assign_perm('can_view_dataset', user_object, dataset_object) + assign_perm('view_dataset', user_object, dataset_object) messages.add_message(self.request, messages.INFO, _('View permission for user successfully granted.')) @@ -3982,7 +3982,6 @@ def render_to_add_user_response(self, context): try: # also need to remove change_dataset perm in this case from guardian.shortcuts import remove_perm - remove_perm('can_view_dataset', user_object, dataset_object) remove_perm('change_dataset', user_object, dataset_object) messages.add_message(self.request, messages.INFO, _('View (and change) permission for user successfully revoked.')) @@ -4569,7 +4568,7 @@ def get(self, request, *args, **kwargs): return HttpResponseRedirect(reverse('registration:login')) dataset = self.object - datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset'], Dataset, accept_global_perms=True, any_perm=True) if dataset not in datasets_user_can_view: @@ -4910,7 +4909,7 @@ def get(self, request, *args, **kwargs): return HttpResponseRedirect(reverse('registration:login')) dataset_of_requested_morpheme = self.object.lemma.dataset - datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset'], Dataset, accept_global_perms=False, any_perm=True) if dataset_of_requested_morpheme not in selected_datasets: @@ -5151,7 +5150,7 @@ def get_context_data(self, **kwargs): context['dataset_choices'] = {} user = self.request.user if user.is_authenticated: - qs = get_objects_for_user(user, ['view_dataset', 'can_view_dataset'], + qs = get_objects_for_user(user, ['view_dataset'], Dataset, accept_global_perms=False, any_perm=True) dataset_choices = dict() for dataset in qs: @@ -6298,7 +6297,7 @@ def get(self, request, *args, **kwargs): return HttpResponseRedirect(reverse('registration:login')) dataset_of_requested_lemma = self.object.dataset - datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + datasets_user_can_view = get_objects_for_user(request.user, ['view_dataset'], Dataset, accept_global_perms=False, any_perm=True) if dataset_of_requested_lemma not in selected_datasets: diff --git a/signbank/dictionary/models.py b/signbank/dictionary/models.py index f4948da56..7f93c04b6 100755 --- a/signbank/dictionary/models.py +++ b/signbank/dictionary/models.py @@ -2972,11 +2972,6 @@ class Dataset(models.Model): exclude_choices = models.ManyToManyField('FieldChoice', help_text="Exclude these field choices", blank=True) - class Meta: - permissions = ( - ('can_view_dataset', _('View dataset')), - ) - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -3061,7 +3056,7 @@ def get_users_who_can_view_dataset(self): with_group_users=False) for user in all_users: if user in users_who_can_access_me.keys(): - if 'can_view_dataset' in users_who_can_access_me[user] or 'view_dataset' in users_who_can_access_me[user]: + if 'view_dataset' in users_who_can_access_me[user]: users_who_can_view_dataset.append(user) return users_who_can_view_dataset diff --git a/signbank/dictionary/templates/dictionary/admin_dataset_list.html b/signbank/dictionary/templates/dictionary/admin_dataset_list.html index 11ecf649e..30149aa15 100644 --- a/signbank/dictionary/templates/dictionary/admin_dataset_list.html +++ b/signbank/dictionary/templates/dictionary/admin_dataset_list.html @@ -55,7 +55,7 @@

{% trans "Available Datasets" %}

{% if not user.is_anonymous %} {% get_obj_perms request.user for dataset as "dataset_perms" %} - {% if "view_dataset" in dataset_perms or "can_view_dataset" in dataset_perms %} + {% if "view_dataset" in dataset_perms %} {% trans "Yes" %} {% else %} {% trans "No" %} @@ -72,7 +72,7 @@

{% trans "Available Datasets" %}

{% if dataset.is_public %} {% get_obj_perms request.user for dataset as "dataset_perms" %} - {% if not "view_dataset" in dataset_perms or not "can_view_dataset" in dataset_perms %} + {% if not "view_dataset" in dataset_perms %}
diff --git a/signbank/dictionary/templates/dictionary/admin_dataset_select_list.html b/signbank/dictionary/templates/dictionary/admin_dataset_select_list.html index 9db29c0eb..f09ec142b 100644 --- a/signbank/dictionary/templates/dictionary/admin_dataset_select_list.html +++ b/signbank/dictionary/templates/dictionary/admin_dataset_select_list.html @@ -50,7 +50,7 @@

{% trans "Select Datasets" %}

{% for dataset in object_list %} {% get_obj_perms request.user for dataset as "dataset_perms" %} - {% if "view_dataset" in dataset_perms or "can_view_dataset" in dataset_perms %} + {% if "view_dataset" in dataset_perms %} diff --git a/signbank/dictionary/tests.py b/signbank/dictionary/tests.py index d6e63d139..ddcef4b95 100644 --- a/signbank/dictionary/tests.py +++ b/signbank/dictionary/tests.py @@ -276,7 +276,7 @@ def testSearchForGlosses(self): # Search search_value_handedness = str(self.handedness_fieldchoice_1.machine_value) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) response = client.get('/signs/search/',{'handedness[]': search_value_handedness}) self.assertEqual(len(response.context['object_list']), 2) @@ -294,7 +294,7 @@ def test_package_function(self): # Give the test user permission to change a dataset test_dataset = Dataset.objects.get(name=dataset_name) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) assign_perm('change_dataset', self.user, test_dataset) assign_perm('dictionary.search_gloss', self.user) assign_perm('dictionary.add_gloss', self.user) @@ -378,7 +378,7 @@ def testSearchForGlosses(self): # Give the test user permission to change a dataset test_dataset = Dataset.objects.get(name=dataset_name) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) assign_perm('change_dataset', self.user, test_dataset) assign_perm('dictionary.search_gloss', self.user) self.user.save() @@ -1140,7 +1140,7 @@ def test_DetailViewRenders(self): .format(self.hidden_gloss.pk)) #With permissions you also see something - assign_perm('can_view_dataset', self.user, self.test_dataset) + assign_perm('view_dataset', self.user, self.test_dataset) response = self.client.get('/dictionary/gloss/'+str(self.hidden_gloss.pk)) self.assertNotEqual(len(response.content),0) @@ -1150,7 +1150,7 @@ def test_JavaScriptIsValid(self): self.client = Client() self.client.login(username='test-user', password='test-user') - assign_perm('can_view_dataset', self.user, self.test_dataset) + assign_perm('view_dataset', self.user, self.test_dataset) response = self.client.get('/dictionary/gloss/'+str(self.hidden_gloss.pk)) invalid_patterns = ['= ;','= var'] @@ -1486,7 +1486,7 @@ def test_QueryLemmasWithoutGlosses(self): # Give the test user permission to change a dataset test_dataset = Dataset.objects.get(name=dataset_name) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) self.user.save() # search for the lemma without glosses: test_lemma_without_gloss @@ -1612,7 +1612,7 @@ def test_create_handshape(self): # set the test dataset dataset_name = settings.DEFAULT_DATASET test_dataset = Dataset.objects.get(name=dataset_name) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) assign_perm('change_dataset', self.user, test_dataset) self.client.login(username='test-user', password='test-user') @@ -1636,7 +1636,7 @@ def test_handshape_choices(self): # set the test dataset dataset_name = settings.DEFAULT_DATASET test_dataset = Dataset.objects.get(name=dataset_name) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) assign_perm('change_dataset', self.user, test_dataset) # Create 10 lemmas for use in testing @@ -1804,7 +1804,7 @@ def test_SemanticField(self): #Create a client and log in client = Client(enforce_csrf_checks=False) client.login(username='test-user', password='test-user') - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) # Create a lemma new_lemma = LemmaIdgloss(dataset=test_dataset) @@ -2546,7 +2546,7 @@ def test_analysis_frequency(self): self.client.login(username='test-user', password='test-user') - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) response = self.client.get('/analysis/frequencies/', follow=True) self.assertEqual(response.status_code,200) @@ -3424,7 +3424,7 @@ def test_analysis_minimalpairs(self): self.client.login(username='test-user', password='test-user') - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) response = self.client.get('/analysis/minimalpairs/', {'paginate_by':20}, follow=True) objects_on_page = response.__dict__['context_data']['objects_on_page'] @@ -3539,7 +3539,7 @@ def test_emptyvalues_minimalpairs(self): self.client.login(username='test-user', password='test-user') - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) response = self.client.get('/analysis/minimalpairs/', {'paginate_by':20}, follow=True) objects_on_page = response.__dict__['context_data']['objects_on_page'] @@ -3739,7 +3739,7 @@ def test_crud_Senses(self): assign_perm('change_dataset', self.user, test_dataset) assign_perm('dictionary.add_gloss', self.user) assign_perm('dictionary.change_gloss', self.user) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) assign_perm('dictionary.search_gloss', self.user) self.user.save() @@ -3910,7 +3910,7 @@ def test_Similar_Senses(self): assign_perm('dictionary.change_gloss', self.user) assign_perm('dictionary.add_sense', self.user) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) assign_perm('dictionary.search_gloss', self.user) self.user.save() @@ -4013,7 +4013,7 @@ def test_no_empty_translations_Senses(self): assign_perm('dictionary.change_gloss', self.user) assign_perm('dictionary.add_sense', self.user) - assign_perm('can_view_dataset', self.user, test_dataset) + assign_perm('view_dataset', self.user, test_dataset) assign_perm('dictionary.search_gloss', self.user) self.user.save() diff --git a/signbank/dictionary/update.py b/signbank/dictionary/update.py index c6381325a..9b703f49f 100755 --- a/signbank/dictionary/update.py +++ b/signbank/dictionary/update.py @@ -832,7 +832,7 @@ def update_gloss(request, glossid): return HttpResponse(str(newvalue), {'content-type': 'text/plain'}) import guardian - if ds in guardian.shortcuts.get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + if ds in guardian.shortcuts.get_objects_for_user(request.user, ['view_dataset'], Dataset, any_perm=True): newvalue = value setattr(gloss, field, ds) @@ -2437,7 +2437,7 @@ def update_morpheme(request, morphemeid): return HttpResponse(str(newvalue), {'content-type': 'text/plain'}) import guardian - if ds in guardian.shortcuts.get_objects_for_user(request.user, ['view_dataset', 'can_view_dataset'], + if ds in guardian.shortcuts.get_objects_for_user(request.user, ['view_dataset'], Dataset, any_perm=True): newvalue = value setattr(morpheme, field, ds) diff --git a/signbank/registration/views.py b/signbank/registration/views.py index 4cd9542de..038bfa205 100755 --- a/signbank/registration/views.py +++ b/signbank/registration/views.py @@ -137,7 +137,7 @@ class as the ``form_class`` keyword argument. The form class you if dataset_obj.is_public: # Give user access to view the database - assign_perm('can_view_dataset', new_user, dataset_obj) + assign_perm('view_dataset', new_user, dataset_obj) for owner in owners_of_dataset: @@ -314,7 +314,7 @@ def users_without_dataset(request): continue user = User.objects.get(pk=int(user.split('_')[-1])) - assign_perm('can_view_dataset', user, main_dataset) + assign_perm('view_dataset', user, main_dataset) users_with_access.append(user.first_name + ' ' + user.last_name) @@ -345,7 +345,7 @@ def user_profile(request): view_permit_datasets = [] for dataset in Dataset.objects.all(): permissions_for_dataset = get_user_perms(request.user, dataset) - if 'view_dataset' in permissions_for_dataset or 'can_view_dataset' in permissions_for_dataset: + if 'view_dataset' in permissions_for_dataset: view_permit_datasets.append(dataset) change_permit_datasets = [] for dataset_user_can_view in view_permit_datasets: diff --git a/signbank/tools.py b/signbank/tools.py index 078044f9d..d12fa81e2 100755 --- a/signbank/tools.py +++ b/signbank/tools.py @@ -1702,7 +1702,7 @@ def get_users_without_dataset(): users_with_no_dataset = [] for user in User.objects.all(): - if user.is_active and len(get_objects_for_user(user, ['view_dataset', 'can_view_dataset'], Dataset, any_perm=True)) == 0: + if user.is_active and len(get_objects_for_user(user, ['view_dataset'], Dataset, any_perm=True)) == 0: users_with_no_dataset.append(user) return users_with_no_dataset