Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-6668] Add Contributor Page Improvements for Institutional Access #10825

12 changes: 12 additions & 0 deletions osf/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from .spam import SpamMixin
from .session import UserSessionMap
from .tag import Tag
from .request import NodeRequest
from .validators import validate_email, validate_social, validate_history_item
from osf.utils.datetime_aware_jsonfield import DateTimeAwareJSONField
from osf.utils.fields import NonNaiveDateTimeField, LowercaseEmailField, ensure_str
Expand All @@ -57,6 +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

SessionStore = import_module(settings.SESSION_ENGINE).SessionStore

Expand Down Expand Up @@ -672,6 +674,16 @@ def is_institutional_curator(self, node):
is_curator=True,
).exists()

def has_institutional_request(self, node):
"""
Checks if user a has requested a node using the institutional access request feature.
"""
return NodeRequest.objects.filter(
request_type=NodeRequestTypes.INSTITUTIONAL_REQUEST.value,
target=node,
creator=self,
).exists()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, is there any place we can cache this info, such as a request object, rather than relying on this query, the same way we did with caching on the contributor object if it's a curator? Same reason as before, to avoid making this query for every contributor that gets serialized.


def group_role(self, group):
"""
For the given OSFGroup, return the user's role - either member or manager
Expand Down
2 changes: 1 addition & 1 deletion website/profile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def serialize_user(user, node=None, admin=False, full=False, is_profile=False, i
'surname': user.family_name,
'fullname': fullname,
'shortname': fullname if len(fullname) < 50 else fullname[:23] + '...' + fullname[-23:],
'is_institutional_admin': user.is_institutional_admin(),
'has_institutional_request': user.has_institutional_request(node),
'is_curator': user.is_institutional_curator(node),
'profile_image_url': user.profile_image_url(size=settings.PROFILE_IMAGE_MEDIUM),
'active': user.is_active,
Expand Down
2 changes: 1 addition & 1 deletion website/project/views/contributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def project_manage_contributors(auth, node, **kwargs):
raise HTTPError(http_status.HTTP_400_BAD_REQUEST, data={'message_long': error.args[0]})
except IntegrityError as error:
status.push_status_message(
'You can not make an institutional admin a bibliographic contributor.',
'You can not make an institutional curator a bibliographic contributor.',
kind='error',
trust=False
)
Expand Down
9 changes: 4 additions & 5 deletions website/templates/project/contributors.mako
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@
aria-label='Curator Disabled Bibliographic User Checkbox'
style='background-color: lightgray;'
disabled
checked
>
</div>
</td>
Expand Down Expand Up @@ -406,23 +405,23 @@
<td>
<div class="header" data-bind="visible: accessRequest.expanded() && $root.collapsed()"></div>
<div class="td-content" data-bind="visible: !$root.collapsed() || accessRequest.expanded()">
<div data-bind="ifnot: accessRequest.user.is_institutional_admin">
<div data-bind="ifnot: accessRequest.user.has_institutional_request">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here, for example, could be accessRequest.is_curator or similar.

<input
type="checkbox" class="biblio"
data-bind="checked: visible"
/>
</div>
<div data-bind="if: accessRequest.user.is_institutional_admin">
<div data-bind="if: accessRequest.user.has_institutional_request">
<input type="checkbox" aria-label="Curator Confirmation Checkbox" disabled>
</div>
</td>
<td>
<div class="header" data-bind="visible: accessRequest.expanded() && $root.collapsed()"></div>
<div class="td-content" data-bind="visible: !$root.collapsed() || accessRequest.expanded()">
<div data-bind="ifnot: accessRequest.user.is_institutional_admin">
<div data-bind="ifnot: accessRequest.user.has_institutional_request">
<input type="checkbox" aria-label="Curator Confirmation Checkbox" disabled>
</div>
<div data-bind="if: accessRequest.user.is_institutional_admin">
<div data-bind="if: accessRequest.user.has_institutional_request">
<input type="checkbox" aria-label="Curator Confirmation Checkbox" disabled checked>
</div>
</div>
Expand Down
Loading