Repository: hydroshare/hydroshare

Issue:
Flag syntax 't' parameter is confusing



Discussion:

Resolving patch:
diff --git a/hs_core/views/__init__.py b/hs_core/views/__init__.py
--- a/hs_core/views/__init__.py
+++ b/hs_core/views/__init__.py
@@ -683,20 +683,20 @@ def publish(request, shortkey, *args, **kwargs):
 def set_resource_flag(request, shortkey, *args, **kwargs):
     # only resource owners are allowed to change resource flags
     res, _, user = authorize(request, shortkey, needed_permission=ACTION_TO_AUTHORIZE.SET_RESOURCE_FLAG)
-    t = resolve_request(request).get('t', None)
-    if t == 'make_public':
+    flag = resolve_request(request).get('flag', None)
+    if flag == 'make_public':
         _set_resource_sharing_status(request, user, res, flag_to_set='public', flag_value=True)
-    elif t == 'make_private' or t == 'make_not_discoverable':
+    elif flag == 'make_private' or flag == 'make_not_discoverable':
         _set_resource_sharing_status(request, user, res, flag_to_set='discoverable', flag_value=False)
-    elif t == 'make_discoverable':
+    elif flag == 'make_discoverable':
         _set_resource_sharing_status(request, user, res, flag_to_set='discoverable', flag_value=True)
-    elif t == 'make_not_shareable':
+    elif flag == 'make_not_shareable':
         _set_resource_sharing_status(request, user, res, flag_to_set='shareable', flag_value=False)
-    elif t == 'make_shareable':
+    elif flag == 'make_shareable':
        _set_resource_sharing_status(request, user, res, flag_to_set='shareable', flag_value=True)
-    elif t == 'make_require_lic_agreement':
+    elif flag == 'make_require_lic_agreement':
         res.set_require_download_agreement(user, value=True)
-    elif t == 'make_not_require_lic_agreement':
+    elif flag == 'make_not_require_lic_agreement':
         res.set_require_download_agreement(user, value=False)
 
     if request.META.get('HTTP_REFERER', None):


Test patch:
diff --git a/hs_core/tests/api/rest/test_resource_flags.py b/hs_core/tests/api/rest/test_resource_flags.py
--- a/hs_core/tests/api/rest/test_resource_flags.py
+++ b/hs_core/tests/api/rest/test_resource_flags.py
@@ -48,47 +48,47 @@ def setUp(self):
     def test_set_resource_flag_make_public(self):
         flag_url = "/hsapi/resource/%s/flag/" % self.pid
         response = self.client.post(flag_url, {
-            "t": "make_public"
+            "flag": "make_public"
         }, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         flag_url = "/hsapi/resource/%s/flag/" % self.pid_two
         response = self.client.post(flag_url, {
-            "t": "make_public"
+            "flag": "make_public"
         }, format='json')
         self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
 
     def test_set_resource_flag_make_private(self):
         flag_url = "/hsapi/resource/%s/flag/" % self.pid
         response = self.client.post(flag_url, {
-            "t": "make_private"
+            "flag": "make_private"
         }, format='json')
         self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
 
     def test_set_resource_flag_make_discoverable(self):
         flag_url = "/hsapi/resource/%s/flag/" % self.pid_two
         response = self.client.post(flag_url, {
-            "t": "make_discoverable"
+            "flag": "make_discoverable"
         }, format='json')
         self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
 
     def test_set_resource_flag_make_not_discoverable(self):
         flag_url = "/hsapi/resource/%s/flag/" % self.pid
         response = self.client.post(flag_url, {
-            "t": "make_not_discoverable"
+            "flag": "make_not_discoverable"
         }, format='json')
         self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
 
     def test_set_resource_flag_make_not_shareable(self):
         flag_url = "/hsapi/resource/%s/flag/" % self.pid
         response = self.client.post(flag_url, {
-            "t": "make_not_shareable"
+            "flag": "make_not_shareable"
         }, format='json')
         self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
 
     def test_set_resource_flag_make_shareable(self):
         flag_url = "/hsapi/resource/%s/flag/" % self.pid
         response = self.client.post(flag_url, {
-            "t": "make_shareable"
+            "flag": "make_shareable"
         }, format='json')
         self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
diff --git a/hs_core/tests/api/views/test_set_resource_flag.py b/hs_core/tests/api/views/test_set_resource_flag.py
--- a/hs_core/tests/api/views/test_set_resource_flag.py
+++ b/hs_core/tests/api/views/test_set_resource_flag.py
@@ -68,7 +68,7 @@ def test_set_resource_flag_make_public(self):
         # test that the resource is not public
         self.assertEqual(self.gen_res_one.raccess.public, False)
         url_params = {'shortkey': self.gen_res_one.short_id}
-        post_data = {'t': 'make_public'}
+        post_data = {'flag': 'make_public'}
         url = reverse('set_resource_flag', kwargs=url_params)
         request = self.factory.post(url, data=post_data)
         request.user = self.user
@@ -87,7 +87,7 @@ def test_set_resource_flag_make_public(self):
         # test that the resource is not public
         self.assertEqual(self.gen_res_two.raccess.public, False)
         url_params = {'shortkey': self.gen_res_two.short_id}
-        post_data = {'t': 'make_public'}
+        post_data = {'flag': 'make_public'}
         url = reverse('set_resource_flag', kwargs=url_params)
         request = self.factory.post(url, data=post_data)
         request.user = self.user
@@ -117,7 +117,7 @@ def test_set_resource_flag_make_private(self):
         self.gen_res_one.raccess.save()
 
         url_params = {'shortkey': self.gen_res_one.short_id}
-        post_data = {'t': 'make_private'}
+        post_data = {'flag': 'make_private'}
         url = reverse('set_resource_flag', kwargs=url_params)
         request = self.factory.post(url, data=post_data)
         request.user = self.user
@@ -145,7 +145,7 @@ def test_set_resource_flag_make_discoverable(self):
         # test that the resource is not discoverable
         self.assertEqual(self.gen_res_one.raccess.discoverable, False)
         url_params = {'shortkey': self.gen_res_one.short_id}
-        post_data = {'t': 'make_discoverable'}
+        post_data = {'flag': 'make_discoverable'}
         url = reverse('set_resource_flag', kwargs=url_params)
         request = self.factory.post(url, data=post_data)
         request.user = self.user
@@ -164,7 +164,7 @@ def test_set_resource_flag_make_discoverable(self):
         # test that the resource is not discoverable
         self.assertEqual(self.gen_res_two.raccess.discoverable, False)
         url_params = {'shortkey': self.gen_res_two.short_id}
-        post_data = {'t': 'make_discoverable'}
+        post_data = {'flag': 'make_discoverable'}
         url = reverse('set_resource_flag', kwargs=url_params)
         request = self.factory.post(url, data=post_data)
         request.user = self.user
@@ -195,7 +195,7 @@ def test_set_resource_flag_make_not_discoverable(self):
         self.gen_res_one.raccess.save()
 
         url_params = {'shortkey': self.gen_res_one.short_id}
-        post_data = {'t': 'make_not_discoverable'}
+        post_data = {'flag': 'make_not_discoverable'}
         url = reverse('set_resource_flag', kwargs=url_params)
         request = self.factory.post(url, data=post_data)
         request.user = self.user
@@ -225,7 +225,7 @@ def test_set_resource_flag_make_shareable(self):
         self.gen_res_one.raccess.save()
 
         url_params = {'shortkey': self.gen_res_one.short_id}
-        post_data = {'t': 'make_shareable'}
+        post_data = {'flag': 'make_shareable'}
         url = reverse('set_resource_flag', kwargs=url_params)
         request = self.factory.post(url, data=post_data)
         request.user = self.user
@@ -251,7 +251,7 @@ def test_set_resource_flag_make_not_shareable(self):
         self.assertEqual(self.gen_res_one.raccess.shareable, True)
 
         url_params = {'shortkey': self.gen_res_one.short_id}
-        post_data = {'t': 'make_not_shareable'}
+        post_data = {'flag': 'make_not_shareable'}
         url = reverse('set_resource_flag', kwargs=url_params)
         request = self.factory.post(url, data=post_data)
         request.user = self.user