Skip to content

Commit

Permalink
Merge pull request #358 from localcontexts/misc-sp-bug-updates
Browse files Browse the repository at this point in the history
Misc SP bug updates
  • Loading branch information
birbjam authored Oct 7, 2024
2 parents ea79a76 + b40cd04 commit 40cdcf9
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 48 deletions.
4 changes: 2 additions & 2 deletions communities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class Community(models.Model):
boundary = models.ForeignKey(Boundary, on_delete=models.CASCADE, blank=True, null=True)
share_boundary_publicly = models.BooleanField(default=True)

show_sp_connection = models.BooleanField(default=True)
sp_privacy = models.CharField(max_length=20, default='all', choices=PRIVACY_LEVEL)
show_sp_connection = models.BooleanField(default=True, null=True)
sp_privacy = models.CharField(max_length=20, default='all', choices=PRIVACY_LEVEL, null=True)

# Managers
objects = models.Manager()
Expand Down
10 changes: 6 additions & 4 deletions communities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,12 +1519,14 @@ def reset_community_boundary(request, pk):
def api_keys(request, pk):
community = get_community(pk)
member_role = check_member_role(request.user, community)
try:

try:
if request.method == 'GET':
form = APIKeyGeneratorForm(request.GET or None)
account_keys = AccountAPIKey.objects.filter(community=community).values_list("prefix", "name", "encrypted_key")

account_keys = AccountAPIKey.objects.filter(community=community).exclude(
Q(expiry_date__lt=timezone.now()) | Q(revoked=True)
).values_list("prefix", "name", "encrypted_key")

elif request.method == "POST":
if "generate_api_key" in request.POST:
form = APIKeyGeneratorForm(request.POST)
Expand Down
4 changes: 2 additions & 2 deletions institutions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class Institution(models.Model):
created = models.DateTimeField(auto_now_add=True, null=True)
is_subscribed = models.BooleanField(default=False)

show_sp_connection = models.BooleanField(default=True)
sp_privacy = models.CharField(max_length=20, default='all', choices=PRIVACY_LEVEL)
show_sp_connection = models.BooleanField(default=True, null=True)
sp_privacy = models.CharField(max_length=20, default='all', choices=PRIVACY_LEVEL, null=True)

# Managers
objects = models.Manager()
Expand Down
18 changes: 10 additions & 8 deletions institutions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ def account_preferences(request, pk):
}
return render(request, 'account_settings_pages/_preferences.html', context)

except:
except Institution.DoesNotExist:
raise Http404()


Expand Down Expand Up @@ -1579,16 +1579,18 @@ def api_keys(request, pk):
member_role = check_member_role(request.user, institution)
remaining_api_key_count = 0
envi = dev_prod_or_local(request.get_host())

try:
if institution.is_subscribed:
subscription = Subscription.objects.get(institution=institution)
remaining_api_key_count = subscription.api_key_count

if request.method == 'GET':
form = APIKeyGeneratorForm(request.GET or None)
account_keys = AccountAPIKey.objects.filter(institution=institution).values_list("prefix", "name", "encrypted_key")

account_keys = AccountAPIKey.objects.filter(institution=institution).exclude(
Q(expiry_date__lt=timezone.now()) | Q(revoked=True)
).values_list("prefix", "name", "encrypted_key")

elif request.method == "POST":
if "generate_api_key" in request.POST:
if institution.is_subscribed and remaining_api_key_count == 0:
Expand All @@ -1613,14 +1615,14 @@ def api_keys(request, pk):
else:
messages.add_message(request, messages.ERROR, 'Please enter a valid API Key name.')
return redirect("institution-api-key", institution.id)

else:
messages.add_message(request, messages.ERROR, 'Your institution is not subscribed. '
'You must have an active subscription to create more API Keys.')
return redirect("institution-api-key", institution.id)

return redirect("institution-api-key", institution.id)

elif "delete_api_key" in request.POST:
prefix = request.POST['delete_api_key']
api_key = AccountAPIKey.objects.filter(prefix=prefix)
Expand All @@ -1637,7 +1639,7 @@ def api_keys(request, pk):
"form" : form,
"account_keys" : account_keys,
"member_role" : member_role,
"subscription_api_key_count" : remaining_api_key_count,
"remaining_api_key_count" : remaining_api_key_count,
"envi": envi,
}
return render(request, 'account_settings_pages/_api-keys.html', context)
Expand Down
1 change: 0 additions & 1 deletion localcontexts/static/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
.dashcard {
margin-top: 5px;
padding: 16px;
max-height: 225px;
}

.dashcard-img-container,
Expand Down
4 changes: 2 additions & 2 deletions researchers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Researcher(models.Model):
date_connected = models.DateTimeField(auto_now_add=True, null=True)
is_subscribed = models.BooleanField(default=False)

show_sp_connection = models.BooleanField(default=True)
sp_privacy = models.CharField(max_length=20, default='all', choices=PRIVACY_LEVEL)
show_sp_connection = models.BooleanField(default=True, null=True)
sp_privacy = models.CharField(max_length=20, default='all', choices=PRIVACY_LEVEL, null=True)

def get_projects(self):
return self.researcher_created_project.filter(researcher=self).exists()
Expand Down
9 changes: 4 additions & 5 deletions researchers/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import timezone
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.contrib import messages
Expand Down Expand Up @@ -1326,11 +1327,9 @@ def api_keys(request, researcher, related=None):

if request.method == 'GET':
form = APIKeyGeneratorForm(request.GET or None)
account_keys = AccountAPIKey.objects.filter(researcher=researcher).values_list(
"prefix",
"name",
"encrypted_key"
)
account_keys = AccountAPIKey.objects.filter(researcher=researcher).exclude(
Q(expiry_date__lt=timezone.now()) | Q(revoked=True)
).values_list("prefix", "name", "encrypted_key")

elif request.method == "POST":
if "generate_api_key" in request.POST:
Expand Down
6 changes: 4 additions & 2 deletions serviceproviders/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from datetime import timezone
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.http import Http404
from itertools import chain
from django.db.models import Q
from .decorators import member_required
from maintenance_mode.decorators import force_maintenance_mode_off

Expand Down Expand Up @@ -569,8 +571,8 @@ def api_keys(request, pk):
remaining_api_key_count = 0

try:
account_keys = AccountAPIKey.objects.filter(
service_provider=service_provider
account_keys = AccountAPIKey.objects.filter(service_provider=service_provider).exclude(
Q(expiry_date__lt=timezone.now()) | Q(revoked=True)
).values_list("prefix", "name", "encrypted_key")

if service_provider.is_certified and account_keys.count() == 0:
Expand Down
10 changes: 5 additions & 5 deletions templates/account_settings_pages/_api-keys.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p class="mt-0">Generating API Keys enables access to the Local Contexts Hub database. Keep these keys confidential. For more information see our <a class="default-a" href="https://localcontexts.org/api-guide/" target="_blank">API Guide</a>.</p>

<div class="flex-this">
<p class="subscription-counter"><span class="bold">API Keys Remaining:</span>
<p class="subscription-counter"><span class="bold">API Keys Remaining:</span>
{% if institution and institution.is_subscribed %}
{% if remaining_api_key_count == -1 %}Unlimited{% else %}{{ remaining_api_key_count }}{% endif %}
{% elif researcher and researcher.is_subscribed %}
Expand Down Expand Up @@ -91,7 +91,7 @@ <h2 class="primary-black-text mt-0">Generate API Key</h2>
</div>
<div>
<div id='closegenerateAPIKeymodal' class="close-modal-btn pointer"><i class="fa-regular fa-xmark fa-xl"></i></div>
</div>
</div>
</div>

<div class="w-100">
Expand All @@ -113,7 +113,7 @@ <h2 class="primary-black-text mt-0">Generate API Key</h2>
<div class="flex-this space-between w-100">
<div class="w-100">
<button type="submit" class="primary-btn action-btn mt-2p w-100" name="generate_api_key">Generate API Key</button>
</div>
</div>
</div>

</form>
Expand All @@ -130,7 +130,7 @@ <h2 class="primary-black-text mt-0">Generate API Key</h2>
<div class="flex-this space-between">
<div class="flex-this">
<h2 class="primary-black-text mt-0">Are you sure?</h2>
</div>
</div>
</div>

<div class="w-100">
Expand Down Expand Up @@ -165,7 +165,7 @@ <h2 class="primary-black-text mt-0">Are you sure?</h2>
const deleteAPIKeymodal = document.getElementById('deleteAPIKeymodal')
deleteBtns.forEach(btn => {
btn.addEventListener('click', () => {
if (deleteAPIKeymodal.classList.contains('hide')) {
if (deleteAPIKeymodal.classList.contains('hide')) {
deleteAPIKeymodal.classList.replace('hide', 'show');
continueAPIKeyDeletionBtn.value = btn.dataset.target;
deleteKeyname.innerHTML = btn.dataset.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h3 class="mr-8 pointer" onclick="toggleSectionInfo(this, 'addServiceProvidersDi
href="{{ service_provider.documentation }}"
target="_blank"
>
More Info <i class="fa fa-arrow-right"></i>
More Info <i class="fa-solid fa-arrow-up-right-from-square fa-xs"></i>
</a>
{% endif %}
{% else %}
Expand All @@ -126,7 +126,7 @@ <h3 class="mr-8 pointer" onclick="toggleSectionInfo(this, 'addServiceProvidersDi
href="{{ service_provider.documentation }}"
target="_blank"
>
More Info <i class="fa fa-arrow-right"></i>
More Info <i class="fa-solid fa-arrow-up-right-from-square fa-xs"></i>
</a>
{% endif %}
{% endif %}
Expand Down
111 changes: 96 additions & 15 deletions templates/public.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,25 @@ <h3 class="dashcard-h3">{{ community }}</h3>
<i class="fa-sharp fa-solid fa-circle-check subscribed-icon fa-lg" title="Active"></i>
{% endif %}
</div>
<div>
<p class="dashcard-subheader">Community {% with community.get_location as location %}{% if location %} | Location: {{ location }}{% endif %}{% endwith %}</p>
</div>
<div><p class="dashcard-description description-sm">{% if community.description %}{{ community.description }}{% else %} No description provided. {% endif %}</p></div>
<p class="dashcard-subheader">
Community {% with community.get_location as location %}{% if location %} | Location: {{ location }}{% endif %}{% endwith %}
</p>
<p class="dashcard-description description-sm">
{% if community.description %}{{ community.description }}{% else %} No description provided.{% endif %}
</p>
{% if community.website %}
<div class="flex-this mt-8 description-sm">
<p class="mt-0 mb-0 mr-16">
<i class="fa-solid fa-globe" title="Website"></i>
<a
class="default-a ml-5"
href="{{ community.website }}"
>
{{ community.community_name }} Website
</a>
</p>
</div>
{% endif %}

{% include 'partials/_alerts.html' %}

Expand Down Expand Up @@ -237,10 +252,25 @@ <h3 class="dashcard-h3">{{ institution }}</h3>
<i class="fa-sharp fa-solid fa-circle-check subscribed-icon fa-lg" title="Subscribed"></i>
{% endif %}
</div>
<div>
<p class="dashcard-subheader">Institution {% with institution.get_location as location %}{% if location %} | Location: {{ location }}{% endif %}{% endwith %}</p>
</div>
<div><p class="dashcard-description description-sm">{% if institution.description %}{{ institution.description }}{% else %} No description provided. {% endif %}</p></div>
<p class="dashcard-subheader">
Institution {% with institution.get_location as location %}{% if location %} | Location: {{ location }}{% endif %}{% endwith %}
</p>
<p class="dashcard-description description-sm">
{% if institution.description %}{{ institution.description }}{% else %} No description provided.{% endif %}
</p>
{% if institution.website %}
<div class="flex-this mt-8 description-sm">
<p class="mt-0 mb-0 mr-16">
<i class="fa-solid fa-globe" title="Website"></i>
<a
class="default-a ml-5"
href="{{ institution.website }}"
>
{{ institution.institution_name }} Website
</a>
</p>
</div>
{% endif %}

{% include 'partials/_alerts.html' %}
</div>
Expand Down Expand Up @@ -358,7 +388,7 @@ <h3 class="dashcard-h3">{{ service_provider }}</h3>
<p class="dashcard-description description-sm">
{% if service_provider.description %}{{ service_provider.description }}{% else %}No description provided.{% endif %}
</p>
{% if service_provider.website or service_provider.documentation%}
{% if service_provider.website or service_provider.documentation %}
<div class="flex-this mt-8 description-sm">
{% if service_provider.website %}
<p class="mt-0 mb-0 mr-16">
Expand All @@ -367,7 +397,7 @@ <h3 class="dashcard-h3">{{ service_provider }}</h3>
class="default-a ml-5"
href="{{ service_provider.website }}"
>
{{ service_provider.website }}
{{ service_provider.name }} Website
</a>
</p>
{% endif %}
Expand All @@ -379,7 +409,7 @@ <h3 class="dashcard-h3">{{ service_provider }}</h3>
class="default-a ml-5"
href="{{ service_provider.documentation }}"
>
{{ service_provider.documentation }}
{{ service_provider.name }} Documentation
</a>
</p>
{% endif %}
Expand Down Expand Up @@ -469,10 +499,61 @@ <h3 class="dashcard-h3">{% firstof researcher.user.get_full_name researcher.user
<i class="fa-sharp fa-solid fa-circle-check subscribed-icon fa-lg" title="Subscribed"></i>
{% endif %}
</div>
<div>
<p class="dashcard-subheader">Researcher {% with researcher.user.user_profile.get_location as location %}{% if location %} | Location: {{ location }}{% endif %}{% endwith %} </p>
</div>
<div><p class="dashcard-description description-sm">{% if researcher.description %}{{ researcher.description }}{% else %} No description provided. {% endif %}</p></div>
<p class="dashcard-subheader">
Researcher {% with researcher.user.user_profile.get_location as location %}{% if location %} | Location: {{ location }}{% endif %}{% endwith %}
</p>
<p class="dashcard-description description-sm">
{% if researcher.description %}{{ researcher.description }}{% else %} No description provided.{% endif %}
</p>
{% if researcher.website or researcher.orcid %}
<div class="flex-this mt-8 description-sm">
{% if researcher.orcid %}
<div class="flex-this" itemscope itemtype="https://schema.org/Person">
<img
loading="lazy"
class="m-auto ml-0 mr-5"
src="https://orcid.org/sites/default/files/images/orcid_16x16.png"
width="16px"
height="16px"
alt="ORCID iD icon"
>
<a
class="default-a flex-this"
itemprop="sameAs"
target="orcid.widget"
rel="me noopener noreferrer"
style="width: max-content;"
{% if 'https://sandbox.orcid.org/' in researcher.orcid or 'https://orcid.org/' in researcher.orcid %}
content="{{ researcher.orcid }}"
href="{{ researcher.orcid }}"
{% elif 'X' in researcher.orcid %}
content="https://sandbox.orcid.org/{{ researcher.orcid }}"
href="https://sandbox.orcid.org/{{ researcher.orcid }}"
{% else %}
content="https://orcid.org/{{ researcher.orcid }}"
href="https://orcid.org/{{ researcher.orcid }}"
{% endif %}
>
{% if 'https://sandbox.orcid.org/' in researcher.orcid or 'https://orcid.org/' in researcher.orcid %}{{ researcher.orcid }}
{% elif 'X' in researcher.orcid %}https://sandbox.orcid.org/{{ researcher.orcid }}
{% else %}https://orcid.org/{{ researcher.orcid }}{% endif %}
</a>
</div>
{% endif %}

{% if researcher.website %}
<p class="mt-0 mb-0 ml-16">
<i class="fa-solid fa-globe" title="Website"></i>
<a
class="default-a ml-5"
href="{{ researcher.website }}"
>
{% firstof researcher.user.get_full_name researcher.user.username %} Website
</a>
</p>
{% endif %}
</div>
{% endif %}
{% include 'partials/_alerts.html' %}
</div>

Expand Down

0 comments on commit 40cdcf9

Please sign in to comment.