diff --git a/scipost_django/organizations/management/commands/organization_fetch_ror_data.py b/scipost_django/organizations/management/commands/organization_fetch_ror_data.py new file mode 100644 index 0000000000000000000000000000000000000000..0121e13fa8148dad1b16b7a5395b689421e42dcd --- /dev/null +++ b/scipost_django/organizations/management/commands/organization_fetch_ror_data.py @@ -0,0 +1,35 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +from django.core.management.base import BaseCommand + +from organizations.models import Organization +from organizations.utils import RORAPIHandler + + +class Command(BaseCommand): + help = ( + "For all Organization model instances, " + "this command updates the `ror_json` field by fetching the latest data " + "using the `id` property of the `ror_json` field." + ) + + def handle(self, *args, **kwargs): + ror_api_handler = RORAPIHandler() + + updated = 0 + missing = 0 + for org in Organization.objects.all(): + if ror_id := org.ror_json.get("id", None): + org.ror_json = ror_api_handler.from_id(ror_id) + org.save() + updated += 1 + else: + missing += 1 + + self.stdout.write( + self.style.SUCCESS( + f"Successfully updated {updated} organizations, {missing} organizations missing `id`" + ) + ) diff --git a/scipost_django/organizations/templates/organizations/_organization_detail_contents.html b/scipost_django/organizations/templates/organizations/_organization_detail_contents.html index 682555dbb4432259970fcbf821b026297bf1b9c8..e37f913f68feac1caa6d191015a2d1b79e0a32fb 100644 --- a/scipost_django/organizations/templates/organizations/_organization_detail_contents.html +++ b/scipost_django/organizations/templates/organizations/_organization_detail_contents.html @@ -47,12 +47,14 @@ No ROR id found. {% endif %} - <button class="btn btn-sm btn-primary ms-auto" - hx-get="{% url "organizations:ror_search_form" pk=org.id %}" - hx-target="#ror-container">Edit</button> - <button class="btn btn-sm btn-secondary ms-2" - hx-get="{% url "organizations:ror_add" pk=org.id ror_id="None" %}" - hx-target="#organization-info">Remove</button> + {% if perms.scipost.can_manage_organizations %} + <button class="btn btn-sm btn-primary ms-auto" + hx-get="{% url "organizations:ror_search_form" pk=org.id %}" + hx-target="#ror-container">Edit</button> + <button class="btn btn-sm btn-secondary ms-2" + hx-get="{% url "organizations:ror_add" pk=org.id ror_id="None" %}" + hx-target="#organization-info">Remove</button> + {% endif %} </td> </tr>