8000 Institution feature implementation. by co505 · Pull Request #670 · ubccr/coldfront · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Institution feature implementation. #670

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

Merged
merged 1 commit into from
Jul 2, 2025

Conversation

co505
Copy link
Contributor
@co505 co505 commented Apr 2, 2025

Overview

Implemented project institution feature, enabling sites with multiple institutions to easily identify which project belongs to which institution. This feature automates institution assignment based on the PI's email address.

Changes Made

  • models.py - Added institution attribute into the Project class.
  • core.py - Added environment variable, PROJECT_INSTITUTION_EMAIL_MAP.
  • view.py - Implemented logic into form_valid function to handle institution assignment.
  • /templates - project_detail, project_list, project_archived_list altered to show institution from GUI.
  • tests.py - Tests added for institution feature.
  • config.md - Added basic documentation to describe PROJECT_INSTITUTION_EMAIL_MAP
  • admin.md - Overhauled get_list_display to add multiple dynamic columns into list_display, therefore showing institution and project_code alongside one another.
  • /migrations - Migration file added.
  • /management - Management commands added to retrospectively assign institution codes to preexisting projects, --dry-run option included too.

Examples*

Feature uses PROJECT_INSTITUTION_EMAIL_MAP to check the PIs email address against a dictionary of key-value pairs, set by the user. e.g. PROJECT_INSTITUTION_EMAIL_MAP=cardiff.ac.uk=CDF,bangor.ac.uk=BGR,swansea.ac.uk=SWAN

If PIs email matches a key, the value will be stored into the database.

The screenshots below use a cardiff.ac.uk email address and make the CDF institution available in the GUI.

project_list

image

project_detail

image

Project Admin Panel

image

@co505
Copy link
Contributor Author
co505 commented Apr 30, 2025

@aebruno Overhauled this slightly, it's now finalised and ready for review. Thanks :)

@co505 co505 force-pushed the institutions_refactor branch 4 times, most recently from 60064d8 to 964bef3 Compare May 2, 2025 13:08
@co505 co505 force-pushed the institutions_refactor branch 2 times, most recently from aae0f80 to 8b47e29 Compare June 12, 2025 11:02
@co505
Copy link
Contributor Author
co505 commented Jun 12, 2025

@aebruno Rebased PR and updated formatting with ruff :)

@co505 co505 force-pushed the institutions_refactor branch from 8b47e29 to 3333060 Compare June 12, 2025 13:19
Copy link
Contributor
@Eric-Butcher Eric-Butcher left a comment

Choose a reason for hiding this comment

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

There are a few things that I think would benefit from being refactored but overrall I think this is good!

Comment on lines 284 to 285
class TestInstitution(TransactionTestCase):
"""Tear down database after each run to prevent conflicts across cases"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure from looking at this if TransactionTestCase is necessary for this test. Could you explain why you are using this over TestCase? Or did you just copy-paste from the one above this and it is not needed? I would rather not take the speed hit on tests if it is not necessary, also if this code is not doing anything with transactions it might be confusing to anyone who reads this test and thinks there is more going on than there actually is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Eric-Butcher Testing isn't my strongest area - I based this on the previous test and welcome the change to TestCase. Apologies for this, thanks for the spot.

self.user.email = "user@inst.edu.com"
self.user.save()
project_institution_three = self.create_project_with_institution("Project 3", PROJECT_INSTITUTION_EMAIL_MAP)
self.assertEqual(project_institution_three, "EDU")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since add_automated_institution_choice(project, institution_dict) (or whatever you rename it to) does not make changes to the database I believe it would be beneficial to add a test case to ensure that that is the case. If someone gets confused down the road and does not realize that and changes the function later, that test should ding the change made to the API for add_automated_institution_choice.

@co505 co505 force-pushed the institutions_refactor branch from e142807 to 3ecb604 Compare June 25, 2025 14:27
@co505
Copy link
Contributor Author
co505 commented Jun 25, 2025

Many thanks again for your thorough review @Eric-Butcher,

  • Suggested title change from add_automated_institution_choice to determine_automated_institution_choice was implemented, along with other formatting changes to the function.
  • Institution management command suggested changes were implemented too.
  • Test case implemented to confirm determine_automated_institution_choice doesn't change any values in the DB. Along with changes from TransactionTestCase to TestCase.
  • Institution character limit increased from 10 to 80

Copy link
Member
@aebruno aebruno left a comment

Choose a reason for hiding this comment

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

@co505 This looks good. Just had one small fix in the migrations for the max_length.

Signed-off-by: Connor Brock <BrockC2@cardiff.ac.uk>
@co505 co505 force-pushed the institutions_refactor branch from cca0b6c to 36a46f7 Compare July 2, 2025 20:13
@aebruno aebruno merged commit 783db50 into ubccr:main Jul 2, 2025
2 checks passed
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
0