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

Changes for "can_request_access" feature #10877

Conversation

bodintsov
Copy link
Contributor

@bodintsov bodintsov commented Dec 30, 2024

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
Знімок екрана 2024-12-30 о 17 56 35

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)

@bodintsov bodintsov marked this pull request as ready for review December 30, 2024 10:34
Copy link
Collaborator

@brianjgeiger brianjgeiger left a 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.

osf/models/institution.py Outdated Show resolved Hide resolved
@brianjgeiger
Copy link
Collaborator

Oh, and also tests need to be fixed.

@brianjgeiger
Copy link
Collaborator

While you're in there fixing tests, you might as well add some new ones to cover the new field.

@bodintsov
Copy link
Contributor Author

The changes so far look good with one small change, but we're missing the admin app functionality.

@brianjgeiger On the OSFadmin app, on the page of an institution, there is a possibility to change the can_request_access field. Maybe I missed something, and it needs to be done elsewhere?

@brianjgeiger
Copy link
Collaborator

On the OSFadmin app, on the page of an institution, there is a possibility to change the can_request_access field.

Oh, very good. Could take a screenshot and put it in the PR description, please?

@bodintsov
Copy link
Contributor Author

Oh, very good. Could take a screenshot and put it in the PR description, please?

Yes sure, I added a screenshot

@brianjgeiger
Copy link
Collaborator

@bodintsov Looks like tests are still failing.

Copy link
Collaborator

@brianjgeiger brianjgeiger left a 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.

framework/email/tasks.py Outdated Show resolved Hide resolved
framework/email/tasks.py Outdated Show resolved Hide resolved
@Johnetordoff
Copy link
Contributor

@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.

@bodintsov
Copy link
Contributor Author

bodintsov commented Jan 4, 2025

I cant fix tests because the add_category method does not work. It is not assigning categories to the Mail object. Without fixing _send_with_sendgrid it is impossible to set proper tests.
Have also needed to add crutch to assert Email object to str.

@brianjgeiger
Copy link
Collaborator

@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.

@brianjgeiger
Copy link
Collaborator

@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.

Copy link
Contributor

@Johnetordoff Johnetordoff left a 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!

@@ -41,6 +41,7 @@ class InstitutionSerializer(JSONAPISerializer):
ser.CharField(read_only=True),
permission='view_institutional_metrics',
)
can_request_access = ser.CharField(read_only=True)
Copy link
Contributor

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
Copy link
Contributor

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.

@@ -257,10 +257,14 @@ class InstitutionFactory(DjangoModelFactory):
email_domains = FakeList('domain_name', n=1)
orcid_record_verified_source = ''
delegation_protocol = ''
can_request_access = False
Copy link
Contributor

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.

Copy link
Collaborator

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.


class Meta:
model = models.Institution

@classmethod
def _create(cls, *args, **kwargs):
Copy link
Contributor

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.

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
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

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,
Copy link
Contributor

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.

@bodintsov bodintsov force-pushed the feature/add_field_to_institutional_model branch from 7a7de42 to c8e345c Compare January 8, 2025 18:59
@brianjgeiger brianjgeiger merged commit d9540f3 into CenterForOpenScience:feature/institutional_access Jan 9, 2025
6 checks passed
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request Jan 9, 2025
…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)
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request Jan 9, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants