Skip to content

Commit

Permalink
split off more access request and institutional request behavior into…
Browse files Browse the repository at this point in the history
… parallel workflows, changes to JS user serialization to check node for request
  • Loading branch information
John Tordoff committed Jan 10, 2025
1 parent 8ef8cd6 commit 0dc2738
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
14 changes: 11 additions & 3 deletions osf/models/contributor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.db import models, IntegrityError

from osf.utils.caching import cached_property
from osf.utils.fields import NonNaiveDateTimeField
from osf.utils import permissions

Expand Down Expand Up @@ -42,10 +44,16 @@ class Meta:
# NOTE: Adds an _order column
order_with_respect_to = 'node'

@cached_property
def has_institutional_request(self):
"""
Checks if user a has requested a node using the institutional access request feature.
"""
return self.user.has_institutional_request(self.node)

def save(self, *args, **kwargs):
if self.user.is_institutional_admin():
if self.visible:
raise IntegrityError('Curators cannot be made bibliographic contributors')
if self.has_institutional_request and self.visible:
raise IntegrityError('Curators cannot be made bibliographic contributors')

return super().save(*args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion osf/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from website.util.metrics import OsfSourceTags, unregistered_created_source_tag
from importlib import import_module
from osf.utils.requests import get_headers_from_request
from osf.utils.workflows import NodeRequestTypes
from osf.utils.workflows import NodeRequestTypes, DefaultStates

SessionStore = import_module(settings.SESSION_ENGINE).SessionStore

Expand Down Expand Up @@ -680,6 +680,7 @@ def has_institutional_request(self, node):
"""
return NodeRequest.objects.filter(
request_type=NodeRequestTypes.INSTITUTIONAL_REQUEST.value,
machine_state=DefaultStates.PENDING.value,
target=node,
creator=self,
).exists()
Expand Down
6 changes: 3 additions & 3 deletions website/profile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_profile_image_url(user, size=settings.PROFILE_IMAGE_MEDIUM):
use_ssl=True,
size=size)

def serialize_user(user, node=None, admin=False, full=False, is_profile=False, include_node_counts=False):
def serialize_user(user, node=None, admin=False, full=False, is_profile=False, include_node_counts=False, contributor=True):
"""
Return a dictionary representation of a registered user.
Expand All @@ -38,7 +38,7 @@ def serialize_user(user, node=None, admin=False, full=False, is_profile=False, i
'profile_image_url': user.profile_image_url(size=settings.PROFILE_IMAGE_MEDIUM),
'active': user.is_active,
}
if node is not None:
if contributor and node is not None:
if admin:
flags = {
'visible': False,
Expand Down Expand Up @@ -196,7 +196,7 @@ def serialize_access_requests(node):
"""Serialize access requests for a node"""
return [
{
'user': serialize_user(access_request.creator),
'user': serialize_user(access_request.creator, node, contributor=False),
'comment': access_request.comment,
'requested_permissions': access_request.requested_permissions,
'id': access_request._id
Expand Down
4 changes: 2 additions & 2 deletions website/static/js/accessRequestManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var AccessRequestModel = function(accessRequest, pageOwner, isRegistration, isPa
self.permissionText = ko.observable(self.options.permissionMap[self.permission()]);

self.is_curator = ko.observable(accessRequest.user.is_curator || false);
self.is_institutional_admin = ko.observable(accessRequest.user.is_institutional_admin || false);
self.visible = ko.observable(!accessRequest.user.is_institutional_admin);
self.has_institutional_request = ko.observable(accessRequest.user.has_institutional_request || false);
self.visible = ko.observable(!accessRequest.user.has_institutional_request);
self.pageOwner = pageOwner;

self.expanded = ko.observable(false);
Expand Down

0 comments on commit 0dc2738

Please sign in to comment.