-
Notifications
You must be signed in to change notification settings - Fork 333
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
Changes for "can_request_access" feature #10877
Changes for "can_request_access" feature #10877
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes so far look good with one small change, but we're missing the admin app functionality.
Oh, and also tests need to be fixed. |
While you're in there fixing tests, you might as well add some new ones to cover the new field. |
@brianjgeiger On the OSFadmin app, on the page of an institution, there is a possibility to change the |
Oh, very good. Could take a screenshot and put it in the PR description, please? |
Yes sure, I added a screenshot |
@bodintsov Looks like tests are still failing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of questions about an unexpected set of changes.
@brianjgeiger @bodintsov is having some failing tests due to my changing of the sendgrid method, heres the fails on the feature branch https://github.com/CenterForOpenScience/osf.io/actions/runs/12380790854/job/34557929049?pr=10884. I told him to adjust the tests because that is working on staging. |
I cant fix tests because the |
@bodintsov Okay, understood. This overall looks good, but I see some likely unrelated test failures that will need to be handled one way or another before this can be merged. I'm checking with another team on Slack to see if this is related to their work, and we'll figure out where to go from here when they respond. |
@bodintsov Okay, since you're fixing the broken tests in another PR, and we've already merged things that have those broken tests in, I will approve this once the merge conflicts are fixed, then let @Johnetordoff do a pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got the goal of the assignment correct, but there's some changes that are necessary before merging. If you have some more questions ping me on Slack, if something seems odd or too difficult, it's probably just a misunderstanding. Good first draft. Thanks!
api/institutions/serializers.py
Outdated
@@ -41,6 +41,7 @@ class InstitutionSerializer(JSONAPISerializer): | |||
ser.CharField(read_only=True), | |||
permission='view_institutional_metrics', | |||
) | |||
can_request_access = ser.CharField(read_only=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it clear this refers to a specific feature. Refactor to something like institutional_request_access_enabled
@@ -0,0 +1,18 @@ | |||
# Generated by Django 4.2.15 on 2024-12-27 14:08 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bunch this in with the other migrations on this branch, just to be tidy. Delete both this and 0025 and re-run makemigrations
and use that file.
osf_tests/factories.py
Outdated
@@ -257,10 +257,14 @@ class InstitutionFactory(DjangoModelFactory): | |||
email_domains = FakeList('domain_name', n=1) | |||
orcid_record_verified_source = '' | |||
delegation_protocol = '' | |||
can_request_access = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would default this to true, just because it's going to true going forward, but I'm not sure if it will break a bunch of tests consider using True here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave this as False, please. We don't want Product to have to turn this off for every institution to start with. We can always change it to True after launch once it goes fully into use.
osf_tests/factories.py
Outdated
|
||
class Meta: | ||
model = models.Institution | ||
|
||
@classmethod | ||
def _create(cls, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what the point of doing this is, write a comment/docstring explaining or remove it.
tests/framework_tests/test_email.py
Outdated
assert len(mock_mail.return_value.category) == 2 | ||
assert mock_mail.return_value.category[0].get() == category1 | ||
assert mock_mail.return_value.category[1].get() == category2 | ||
# Added this crutch as test fail due to improper work of method `add_category`. This method do not add categories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we cleared up all these email tests, seems like you should be able to remove this lines.
osf/models/user.py
Outdated
@@ -646,7 +646,7 @@ def osf_groups(self): | |||
|
|||
def is_institutional_admin(self, institution): | |||
group_name = institution.format_group('institutional_admins') | |||
return self.groups.filter(name=group_name).exists() | |||
return self.groups.filter(name=group_name).exists() and institution.can_request_access |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's difficult question where this AND check should be in the codebase. The institutional_admins
permission may have other uses in the future that don't involve this feature, even though this is a quick fix and probably works for now you should move this check to the permissions classes that also check for this feature's request_type. UserMessagePermissions
and InstitutionalAdminRequestTypePermission
are better places to insert a conditional for this feature. is_institutional_admin
can't "lie" about whether the user has that permission just because the feature is on/off.
@@ -89,6 +110,26 @@ def test_institutional_admin_can_create_message(self, mock_send_mail, app, insti | |||
assert 'Requesting user access for collaboration' in mock_send_mail.call_args[1]['message_text'] | |||
assert user_message._id == data['id'] | |||
|
|||
@mock.patch('osf.models.user_message.send_mail') | |||
def test_institutional_admin_can_not_create_message(self, mock_send_mail, app, institutional_admin_on_institution_without_access, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a test for the request node endpoint too.
7a7de42
to
c8e345c
Compare
d9540f3
into
CenterForOpenScience:feature/institutional_access
…terForOpenScience/osf.io into feature/institutional_access * 'feature/institutional_access' of https://github.com/CenterForOpenScience/osf.io: Changes for "can_request_access" feature (CenterForOpenScience#10877)
…terForOpenScience/osf.io into institutional-access-insti-admin-validation * 'feature/institutional_access' of https://github.com/CenterForOpenScience/osf.io: Changes for "can_request_access" feature (CenterForOpenScience#10877) # Conflicts: # api/requests/permissions.py # api/users/permissions.py # osf/migrations/0025_contributor_is_curator_and_more.py
Purpose
Add to admin "can_request_access" option to the institution
API Changes for "can_request_access" feature
Done 2 tasks (ENG-6779) and (ENG-6780) within one PR, due to tickets being related to each other
Changes
TBD
QA Notes
TBD
Documentation
TBD
Side Effects
TBD
Ticket
(https://openscience.atlassian.net/browse/ENG-6779)
(https://openscience.atlassian.net/browse/ENG-6780)