internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: hydroshare/hydroshare

Issue:
Add "abstract" representation to resource JSON REST API results



Discussion:

Resolving patch:
diff --git a/hs_core/views/resource_rest_api.py b/hs_core/views/resource_rest_api.py
--- a/hs_core/views/resource_rest_api.py
+++ b/hs_core/views/resource_rest_api.py
@@ -48,6 +48,7 @@ def resourceToResourceListItem(self, r):
         resource_list_item = serializers.ResourceListItem(resource_type=r.resource_type,
                                                           resource_id=r.short_id,
                                                           resource_title=r.metadata.title.value,
+                                                          abstract=r.metadata.description,
                                                           creator=r.first_creator.name,
                                                           public=r.raccess.public,
                                                           discoverable=r.raccess.discoverable,
diff --git a/hs_core/views/resource_ticket_rest_api.py b/hs_core/views/resource_ticket_rest_api.py
--- a/hs_core/views/resource_ticket_rest_api.py
+++ b/hs_core/views/resource_ticket_rest_api.py
@@ -45,7 +45,7 @@ class CreateResourceTicket(APIView):
 
     Error returns 400, 403, 404 return a string with the error message instead of JSON.
     """
-    allowed_methods = ('GET')
+    allowed_methods = ('GET',)
 
     def get(self, request, pk, op, pathname):
         """
@@ -120,7 +120,7 @@ class CreateBagTicket(APIView):
 
     Error returns 400, 403, 404 return a string with the error message instead of JSON.
     """
-    allowed_methods = ('GET')
+    allowed_methods = ('GET',)
 
     def get(self, request, pk):
         """
diff --git a/hs_core/views/serializers.py b/hs_core/views/serializers.py
--- a/hs_core/views/serializers.py
+++ b/hs_core/views/serializers.py
@@ -93,6 +93,7 @@ class ResourceListItemSerializer(serializers.Serializer):
     resource_type = serializers.CharField(max_length=100)
     resource_title = serializers.CharField(max_length=200)
     resource_id = serializers.CharField(max_length=100)
+    abstract = serializers.CharField()
     creator = serializers.CharField(max_length=100)
     date_created = serializers.DateTimeField(format='%m-%d-%Y')
     date_last_updated = serializers.DateTimeField(format='%m-%d-%Y')
@@ -123,6 +124,7 @@ def __init__(self, resource_type):
                               ['resource_type',
                                'resource_id',
                                'resource_title',
+                               'abstract',
                                'creator',
                                'public',
                                'discoverable',


Test patch:
Repository: hydroshare/hydroshare

Issue:
[1.15 HOTFIX] User identifier data is not getting copied over to the first creator of the resource



Discussion:
@pkdash FYI we will be pushing RC1 to beta around 3:30pm EST today
@aphelionz I will be creating the hotfix PR tonight. Could not create the PR before due to the migration files issue that Alva resolved later.
@aphelionz This PR is going to be one liner change. Let me know if you want to make that change. I can give you the change pointers.
Sure go ahead. I will do it (more or less) now.
@aphelionz 

After this line: https://github.com/hydroshare/hydroshare/blob/1.15-RC1/hs_core/hydroshare/utils.py#L862

add this one line:
`` party_data['identifiers'] = user_profile.identifiers``

Resolving patch:
diff --git a/hs_core/hydroshare/utils.py b/hs_core/hydroshare/utils.py
--- a/hs_core/hydroshare/utils.py
+++ b/hs_core/hydroshare/utils.py
@@ -860,6 +860,7 @@ def get_party_data_from_user(user):
     party_data['description'] = '/user/{uid}/'.format(uid=user.pk)
     party_data['phone'] = user_profile.phone_1
     party_data['organization'] = user_profile.organization
+    party_data['identifiers'] = user_profile.identifiers
     return party_data
 
 


Test patch:
Repository: hydroshare/hydroshare

Issue:
Hyperlink DOIs against preferred resolver
Hello :-)

The DOI foundation recommends [this new, secure resolver](https://www.doi.org/doi_handbook/3_Resolution.html#3.8). Would a PR that updates all static links & the code that generates new ones, plus the test cases be welcome?

Cheers!


Discussion:
PS: Also in the sister repos.
@katrinleinweber - thanks for the suggestion. What would be the benefit of using your suggested resolver over just using http://dx.doi.org or even just http://doi.org in our URL-encoded DOIs?
@horsburgh The benefit is that it is encrypted + securt https instead of http.

@katrinleinweber yes PRs are welcome :)

Resolving patch:
diff --git a/hs_core/hydroshare/resource.py b/hs_core/hydroshare/resource.py
--- a/hs_core/hydroshare/resource.py
+++ b/hs_core/hydroshare/resource.py
@@ -909,7 +909,7 @@ def delete_resource_file(pk, filename_or_id, user, delete_logical_file=True):
 
 
 def get_resource_doi(res_id, flag=''):
-    doi_str = "http://dx.doi.org/10.4211/hs.{shortkey}".format(shortkey=res_id)
+    doi_str = "https://doi.org/10.4211/hs.{shortkey}".format(shortkey=res_id)
     if flag:
         return "{doi}{append_flag}".format(doi=doi_str, append_flag=flag)
     else:


Test patch:
diff --git a/hs_core/tests/api/native/test_core_metadata.py b/hs_core/tests/api/native/test_core_metadata.py
--- a/hs_core/tests/api/native/test_core_metadata.py
+++ b/hs_core/tests/api/native/test_core_metadata.py
@@ -959,7 +959,7 @@ def test_identifier(self):
         # test adding an identifier with name 'DOI' when the resource does not have a DOI - should raise an exception
         self.res.doi = None
         self.res.save()
-        url_doi = "http://dx.doi.org/10.4211/hs.{res_id}".format(res_id=self.res.short_id)
+        url_doi = "https://doi.org/10.4211/hs.{res_id}".format(res_id=self.res.short_id)
         self.assertRaises(Exception, lambda: resource.create_metadata_element(self.res.short_id,'identifier',
                                                                               name='DOI',  url=url_doi))
 
@@ -974,7 +974,7 @@ def test_identifier(self):
                                                                               doi_idf.id, name='DOI-1'))
 
         # test that 'DOI' identifier url can be changed
-        resource.update_metadata_element(self.res.short_id, 'identifier', doi_idf.id, url='http://doi.org/001')
+        resource.update_metadata_element(self.res.short_id, 'identifier', doi_idf.id, url='https://doi.org/001')
 
         # test that hydroshareidentifier can't be deleted - raise exception
         hs_idf = self.res.metadata.identifiers.all().filter(name='hydroShareIdentifier').first()
@@ -1495,7 +1495,7 @@ def test_get_xml(self):
         # add 'DOI' identifier
         self.res.doi='doi1000100010001'
         self.res.save()
-        self.res.metadata.create_element('identifier', name='DOI', url="http://dx.doi.org/001")
+        self.res.metadata.create_element('identifier', name='DOI', url="https://doi.org/001")
 
         # no need to add a language element - language element is created at the time of resource creation
Repository: hydroshare/hydroshare

Issue:
Add back Active, Date joined, and last login in mezzanine listing of users
In the 3/19/18 version of HydroShare when an admin listed users the fields listed were
![image](https://user-images.githubusercontent.com/3456833/41195757-d1268df2-6bf0-11e8-8279-a3fbe2f81f84.png)

At present when an admin lists users the fields are
![image](https://user-images.githubusercontent.com/3456833/41195790-5abcbf32-6bf1-11e8-9544-b94c25e36777.png)


The fields Active, Date joined and last login are needed so that when there are problems with users creating and activating accounts (as occurred this week) an admin can list recent account creations and account creation attempts to assess the extent of the problem, and contact users that may have been impacted.

This regression was noted in https://github.com/hydroshare/hydroshare/pull/2677#issuecomment-374183106



Discussion:

Resolving patch:
diff --git a/hs_core/admin.py b/hs_core/admin.py
--- a/hs_core/admin.py
+++ b/hs_core/admin.py
@@ -23,6 +23,10 @@ def __init__(self, *args, **kwargs):
         'fields': ('email', 'username', 'password1', 'password2',)
     }),
 )
+UserAdmin.list_display = [
+    'username', 'email', 'first_name', 'last_name', 'is_staff',
+    'is_active', 'date_joined', 'last_login'
+]
 
 class InlineResourceFiles(GenericTabularInline):
     model = ResourceFile


Test patch:
Repository: hydroshare/hydroshare

Issue:
Change quota notifications to once per week.
Once a day is too often for the quota notification emails, given that they are only informational and not enforced. Change to once per week.


Discussion:

Resolving patch:
diff --git a/hs_core/tasks.py b/hs_core/tasks.py
--- a/hs_core/tasks.py
+++ b/hs_core/tasks.py
@@ -114,7 +114,7 @@ def sync_mailchimp(active_subscribed, list_id):
 
 @periodic_task(ignore_result=True, run_every=crontab(minute=0, hour=0))
 def manage_task_nightly():
-    # The nightly running task do DOI activation check and over-quota check
+    # The nightly running task do DOI activation check
 
     # Check DOI activation on failed and pending resources and send email.
     msg_lst = []
@@ -184,6 +184,9 @@ def manage_task_nightly():
         # send email for people monitoring and follow-up as needed
         send_mail(subject, email_msg, settings.DEFAULT_FROM_EMAIL, [settings.DEFAULT_SUPPORT_EMAIL])
 
+
+@periodic_task(ignore_result=True, run_every=crontab(minute=15, hour=0, day_of_week=1))
+def manage_task_weekly():
     # check over quota cases and send quota warning emails as needed
     hs_internal_zone = "hydroshare"
     if not QuotaMessage.objects.exists():


Test patch:
Repository: hydroshare/hydroshare

Issue:
Order recent activity in groups from last to first
Recent activity in groups right now starts from resources that are quite old, but scrolling down you can see recent resources added.  I think that the latest should be listed first to see recent stuff.



Discussion:
@cuahsimarko will this impact the CZO work? I'm not sure if you caught this when coding for community. The recent activity lists is not in order of date.
That may share a backend and UI component with all Resources views. This is on my radar.
good good
![image](https://user-images.githubusercontent.com/45397838/56303404-d5bc5400-6109-11e9-84a2-c28d2e98feb8.png)

![image](https://user-images.githubusercontent.com/45397838/56749750-530e4700-6750-11e9-9004-dbe54361250d.png)


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
@@ -1819,6 +1819,7 @@ def get_context_data(self, **kwargs):
             res.grantor = grp.grantor
             res.date_granted = grp.start
             group_resources.append(res)
+        group_resources = sorted(group_resources, key=lambda  x:x.date_granted, reverse=True)
 
         # TODO: need to sort this resource list using the date_granted field
 


Test patch:
Repository: hydroshare/hydroshare

Issue:
When rating resource and not logged in, system doesn't redirect after login
If a user wanted to rate a resource (for example), they would click the link to login.  It seems like after the login, the system should redirect back to where the user wanted to make a login-dependent action.

[180709-test-files-013v.zip](https://github.com/hydroshare/hydroshare/files/2177859/180709-test-files-013v.zip)



Discussion:
There has been some progress on this, but behavior varies.   For example, posting a comment redirects to resource after commenting, but rating a resource redirects to https://beta.hydroshare.org/home/.  Keeping open.

Resolving patch:
diff --git a/theme/views.py b/theme/views.py
--- a/theme/views.py
+++ b/theme/views.py
@@ -159,7 +159,7 @@ def comment(request, template="generic/comments.html"):
 
 
 # added by Hong Yi to address issue #186 to customize Mezzanine-based rating form and view
-def rating(request):
+def rating(request, template="generic/rating.html"):
     """
     Handle a ``RatingForm`` submission and redirect back to its
     related object.
@@ -175,16 +175,8 @@ def rating(request):
     rating_form = RatingForm(request, obj, post_data)
     if rating_form.is_valid():
         rating_form.save()
-        if request.is_ajax():
-            # Reload the object and return the rating fields as json.
-            obj = obj.__class__.objects.get(id=obj.id)
-            rating_name = obj.get_ratingfield_name()
-            json = {}
-            for f in ("average", "count", "sum"):
-                json["rating_" + f] = getattr(obj, "%s_%s" % (rating_name, f))
-            response = HttpResponse(dumps(json))
-        ratings = ",".join(rating_form.previous + [rating_form.current])
-        set_cookie(response, "mezzanine-rating", ratings)
+        return response
+    response = render(request, template)
     return response
 
 


Test patch:
Repository: hydroshare/hydroshare

Issue:
No phone number validation on profile page
There seems to be no limits/validation for phone numbers on the profile page.  It seems like allowing the users to use characters like Ü could cause problems downstream in the system.  Additionally, analysis/parsing of user data might be messy when the phone number could take virtually any form.

[Video and Other Bug Report Files](https://github.com/hydroshare/hydroshare/files/2288939/003.zip)



Discussion:
TODO: Add Django field validators for telephone numbers

Resolving patch:
diff --git a/theme/migrations/0016_userprofile_phone_validations.py b/theme/migrations/0016_userprofile_phone_validations.py
new file mode 100644
--- /dev/null
+++ b/theme/migrations/0016_userprofile_phone_validations.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.29 on 2021-04-26 20:14
+from __future__ import unicode_literals
+
+import django.core.validators
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('theme', '0015_auto_20200603_2110'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='userprofile',
+            name='phone_1',
+            field=models.CharField(blank=True, max_length=16, null=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '999999999'. Up to 16 digits allowed.", regex='^\\d{8,15}$')]),
+        ),
+        migrations.AlterField(
+            model_name='userprofile',
+            name='phone_2',
+            field=models.CharField(blank=True, max_length=16, null=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '999999999'. Up to 16 digits allowed.", regex='^\\d{8,15}$')]),
+        ),
+    ]
diff --git a/theme/models.py b/theme/models.py
--- a/theme/models.py
+++ b/theme/models.py
@@ -1,4 +1,6 @@
 import datetime
+
+from django.core.validators import RegexValidator
 from django.utils import timezone
 
 from django.contrib.auth.models import User
@@ -266,13 +268,15 @@ class UserProfile(models.Model):
         blank=True,
         help_text="The name of the organization you work for."
     )
-    phone_1 = models.CharField(max_length=1024, null=True, blank=True)
+    phone_regex = RegexValidator(regex=r'^\d{8,15}$',
+                                 message="Phone number must be entered in the format: '999999999'. Up to 16 digits allowed.")
+    phone_1 = models.CharField(validators=[phone_regex], max_length=16, null=True, blank=True)
     phone_1_type = models.CharField(max_length=1024, null=True, blank=True, choices=(
         ('Home', 'Home'),
         ('Work', 'Work'),
         ('Mobile', 'Mobile'),
     ))
-    phone_2 = models.CharField(max_length=1024, null=True, blank=True)
+    phone_2 = models.CharField(validators=[phone_regex], max_length=16, null=True, blank=True)
     phone_2_type = models.CharField(max_length=1024, null=True, blank=True, choices=(
         ('Home', 'Home'),
         ('Work', 'Work'),


Test patch:
Repository: hydroshare/hydroshare

Issue:
Cannot edit geographic feature aggregation metadata
**Description of the bug**
A clear and concise description of what the bug is.

I cannot see or edit the aggregation level metadata for a geographic feature aggregation (shapefile) within a resource. This is a regression - this used to work fine. Here is a screenshot of the error that I receive.

![image](https://user-images.githubusercontent.com/3485902/127062210-34557fb3-2085-47e9-99f4-612481c9011e.png)

Steps to reproduce the bug:
1. Create a new resource
2. Set title, abstract and keyword (I don't think this step is really needed)
3. Add a shapefile to the resource
4. Click on the shapefile in the file browser panel to select it
5. The error is displayed in the aggregation metadata panel on the right

**Expected behavior**
A clear and concise description of what you expected to happen.

I should be able to see and edit the metadata for the geographic feature aggregation within the right panel of the file browser panel.

**Additional information**
Add any other context about the problem here such as screenshots, software versions, and browser information.

Testing using Chrome on my Macbook Pro. This was reported by another HydroShare user who was using Firefox on Windows 10.



Discussion:
This error was introduced with the [model program/instance merge](https://github.com/hydroshare/hydroshare/blame/develop/hs_file_types/views.py#L1218).

That line previously did not pass in a user parameter and the geofeature metadata method for get_html_forms does not have a user parameter defined.  The other aggregations included a `**kwargs` parameter with the merge.  It looks like GeoFeature was missed.

This is a very minor change to include `**kwargs` in the parameter for get_html_forms on the GeoFeatureFileMetaData class.

Resolving patch:
diff --git a/hs_file_types/models/geofeature.py b/hs_file_types/models/geofeature.py
--- a/hs_file_types/models/geofeature.py
+++ b/hs_file_types/models/geofeature.py
@@ -79,7 +79,7 @@ def _get_field_informations_html(self):
 
         return root_div.render()
 
-    def get_html_forms(self, datatset_name_form=True):
+    def get_html_forms(self, datatset_name_form=True, **kwargs):
         """overrides the base class function to generate html needed for metadata editing"""
 
         root_div = div("{% load crispy_forms_tags %}")


Test patch:
Repository: hydroshare/hydroshare

Issue:
API endpoint /scimeta/custom currently requires edit permissions to GET
**Description of the bug**
[update_key_value_metadata_public](https://github.com/hydroshare/hydroshare/blob/develop/hs_core/views/__init__.py#L390) handles both the POST and GET.  The authorization scope for POST is correct and requires edit permissions.  The authorization scope for GET also requires edit permissions but it should only require view permissions.

Steps to reproduce the bug:
1. curl https://www.hydroshare.org/hsapi/resource/0825db8e3bed4b18b77f214b5630f3d7/scimeta/custom/
2. Observe a 403 for viewing additional metadata on a public resource.

**Expected behavior**
GET /scimeta/custom should require view permissions, not edit permissions.



Discussion:
@horsburgh - I believe this is a programming error but I'd like you to confirm that viewing additional metadata via the API should only require VIEW permissions and not EDIT permisssions.

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
@@ -385,13 +385,15 @@ def update_key_value_metadata(request, shortkey, *args, **kwargs):
 
     return HttpResponseRedirect(request.META['HTTP_REFERER'])
 
+
 @api_view(['POST', 'GET'])
 def update_key_value_metadata_public(request, pk):
-    res, _, _ = authorize(request, pk, needed_permission=ACTION_TO_AUTHORIZE.EDIT_RESOURCE)
-
     if request.method == 'GET':
+        res, _, _ = authorize(request, pk, needed_permission=ACTION_TO_AUTHORIZE.VIEW_RESOURCE)
         return HttpResponse(status=200, content=json.dumps(res.extra_metadata))
 
+    res, _, _ = authorize(request, pk, needed_permission=ACTION_TO_AUTHORIZE.EDIT_RESOURCE)
+
     post_data = request.data.copy()
     res.extra_metadata = post_data
 


Test patch:
diff --git a/hs_core/tests/api/rest/test_resource_science_meta.py b/hs_core/tests/api/rest/test_resource_science_meta.py
--- a/hs_core/tests/api/rest/test_resource_science_meta.py
+++ b/hs_core/tests/api/rest/test_resource_science_meta.py
@@ -28,6 +28,11 @@ def setUp(self):
         self.resources_to_delete.append(self.pid2)
 
     def test_get_scimeta(self):
+        # set resource public
+        self.resource.raccess.public = True
+        self.resource.raccess.save()
+        # remove authentication to test public view
+        self.client.logout()
         # Get the resource system metadata
         sysmeta_url = "/hsapi/resource/{res_id}/scimeta/elements/".format(res_id=self.pid)
         response = self.client.get(sysmeta_url)
Repository: hydroshare/hydroshare

Issue:
SOLR index is not removed when a public resource is deleted through the API
**Description of the bug**
The SOLR index is not removed when a public resource is deleted through the API

Steps to reproduce the bug:
1. Create a public resource
2. DELETE `/hsapi/resource/{id}` (use the swagger interface)
3. Find your deleted resource in discover

**Expected behavior**
The deleted resource should not show in discover



Discussion:

Resolving patch:
diff --git a/hs_core/hydroshare/resource.py b/hs_core/hydroshare/resource.py
--- a/hs_core/hydroshare/resource.py
+++ b/hs_core/hydroshare/resource.py
@@ -800,6 +800,8 @@ def delete_resource(pk, request_username=None):
     Note:  Only HydroShare administrators will be able to delete formally published resource
     """
     from hs_core.tasks import delete_resource_task
+    resource = utils.get_resource_by_shortkey(pk)
+    resource.set_discoverable(False)
     delete_resource_task(pk, request_username)
 
     return pk


Test patch:
diff --git a/hs_core/tests/api/native/test_delete_resource.py b/hs_core/tests/api/native/test_delete_resource.py
--- a/hs_core/tests/api/native/test_delete_resource.py
+++ b/hs_core/tests/api/native/test_delete_resource.py
@@ -1,6 +1,11 @@
+import os
+import tempfile
+
 from django.contrib.auth.models import Group
 from django.test import TestCase
+from haystack.query import SearchQuerySet
 
+from hs_composite_resource.models import CompositeResource
 from hs_core.hydroshare import resource
 from hs_core.hydroshare import users
 from hs_core.models import GenericResource
@@ -12,6 +17,7 @@ class TestDeleteResource(MockIRODSTestCaseMixin, TestCase):
     def setUp(self):
         super(TestDeleteResource, self).setUp()
         self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
+        self.tmp_dir = tempfile.mkdtemp()
         # create a user
         self.user = users.create_account(
             'test_user@email.com',
@@ -37,6 +43,33 @@ def test_delete_resource(self):
         # there should be no resource at this point
         self.assertEqual(GenericResource.objects.all().count(), 0, msg="Number of resources not equal to 0")
 
+    def test_delete_resource_public(self):
+        # create files
+        file_one = os.path.join(self.tmp_dir, "test1.txt")
+
+        file_one_write = open(file_one, "w")
+        file_one_write.write("Putting something inside")
+        file_one_write.close()
+
+        # open files for read and upload
+        self.file_one = open(file_one, "rb")
+
+        new_res = resource.create_resource(
+            'GenericResource',
+            self.user,
+            'My Test Resource',
+            files=(self.file_one,),
+            keywords=("one", "two",),
+            metadata=[{"description": {"abstract": "myabstract"}}]
+        )
+        current_index_count = len(SearchQuerySet().all())
+
+        new_res.set_public(True)
+        self.assertEqual(len(SearchQuerySet().all()), current_index_count + 1)
+
+        resource.delete_resource(new_res.short_id)
+        self.assertEqual(len(SearchQuerySet().all()), current_index_count)
+