Skip to content

fix: bug for searching by proposal ID failing to find proposal due to whitespace#1345

Open
YufanKambang wants to merge 12 commits intodevelopfrom
1211-bug-when-whitespace-in-proposal-id-search
Open

fix: bug for searching by proposal ID failing to find proposal due to whitespace#1345
YufanKambang wants to merge 12 commits intodevelopfrom
1211-bug-when-whitespace-in-proposal-id-search

Conversation

@YufanKambang
Copy link
Contributor

@YufanKambang YufanKambang commented Feb 9, 2026

Description

This pr is in response to the issue : UserOfficeProject/issue-tracker#1211

Motivation and Context

This is to improve user experience as well as to not cause confusion if they copied a proposal ID with a white space and see no proposals being shown

How Has This Been Tested

I have tested it using the localhost proposal portal, I first checked to see if the given proposal ID had a proposal in the system, when confirmed I tested it by adding whitespace to the start of the proposal ID, and the at the end of the ID.

Fixes

Changes

Depends on

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@YufanKambang
Copy link
Contributor Author

Found a query function that is related to bug, I think making sure that the input string if considered to be proposal IDs should be trimmed/normalised/validated before being passed as a query parameter in search proposals function

@YufanKambang YufanKambang changed the title investigation result, found query function related to bug Fix bug for searching by proposal ID failing to find proposal due to whitespace Feb 10, 2026
@YufanKambang YufanKambang changed the title Fix bug for searching by proposal ID failing to find proposal due to whitespace Fix: bug for searching by proposal ID failing to find proposal due to whitespace Feb 10, 2026
@YufanKambang
Copy link
Contributor Author

YufanKambang commented Feb 10, 2026

Found the function getProposalById(){} in three different locations, it was confusing.
This is where the query is happening: line 1036 of /apps/backend/src/datasources/postgres/ProposalDataSource.ts

However the getProposalById(){} here if of a higher level, as it includes the authorisation, and I think we should add the check and fix for the bug here

@YufanKambang
Copy link
Contributor Author

Have made the fix, but yet to test it. Having issues with logging into office.localhost and user.localhost.

@YufanKambang
Copy link
Contributor Author

Fixing my local set up of the ICD system to be able to test the code changes, and assess that it actually fixes the whitespace bug

@YufanKambang YufanKambang changed the title Fix: bug for searching by proposal ID failing to find proposal due to whitespace fix: bug for searching by proposal ID failing to find proposal due to whitespace Feb 16, 2026
@YufanKambang YufanKambang marked this pull request as ready for review February 17, 2026 10:10
@YufanKambang YufanKambang requested a review from a team as a code owner February 17, 2026 10:10
@YufanKambang YufanKambang requested review from ellen-wright and mutambaraf and removed request for a team February 17, 2026 10:10
Copy link
Contributor

@mutambaraf mutambaraf 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 some few comments and can we also have tests e2e to this bug or backend unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good if this change was done for the instrument scientist table too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not have the instrument scientist role. Is it the same as the experiment scientists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was looking into this and the way the proposal id get passed to be turned into a query is a bit different for instrument-scientist compared to user-officers. I think it would help to put this into a different issue, that I can pick up

Copy link
Contributor Author

@YufanKambang YufanKambang Feb 18, 2026

Choose a reason for hiding this comment

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

I have made the update so that the instrument/experimental scientist table also does not get effected by whitespace. tested it on localhost using the role experimental scientist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the roles user-officer, the searchText that they put into the search bar int he proposal tables is directly used for the view query.
However, for the role instrument-scientist the searchText is put into a filter class called ProposalsFilter, and this ProposalsFilter is passed into the method getInstrumentScientistProposals and so we have to update the ProposalsFilter.text field with the trimmed searchtext that the intrument/experimental scientist will input into the intrument/experimental scientist proposal tables.

@YufanKambang
Copy link
Contributor Author

Fixing my local set up of the ICD system to be able to test the code changes, and assess that it actually fixes the whitespace bug

I have added a unit test for the role user-officer, for the whitespace bug.

@YufanKambang
Copy link
Contributor Author

The unit test produced actually tests the wrong function that is being called, as we are not trying to get a proposal from the database, but to get filter the view from the user-officer table using the proposalId.

@YufanKambang
Copy link
Contributor Author

I have tried to test this locally but I have failed facing an import error with muhammara.
I am pushing the test so that the github workflow can run it

@YufanKambang YufanKambang requested review from a team and Junjiequan and removed request for a team and martin-trajanovski February 18, 2026 09:14
@YufanKambang
Copy link
Contributor Author

I also noticed no instructions on how to run unit and e2e tests locally on your work machine in user-office-core readme.md, or in the user office dev documentation. Updating this so that new developers to the repository will know how to run the tests.

first?: number,
offset?: number
) {
const cleanText = filter?.text?.trim();
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 recommend trim to happen in datasource layer during sql query rather than the business logic layer here.

Let me know if you have any concerns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is I have not been able to successfully move it to the datasource layer

image

I placed console.logs but have not been able to see them in any container logs.

How should I be handling this object filter for the @Authorized([Roles.INSTRUMENT_SCIENTIST, Roles.INTERNAL_REVIEWER]) proposal view as they have a whole object that gets passed compared to the string for @Authorized([Roles.USER_OFFICER])?

@YufanKambang
Copy link
Contributor Author

I have been unable to push these changes due to the pre-commit linter. That is the reason why I have snipped my code changes

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.

4 participants