Skip to content

Conversation

@xkello
Copy link

@xkello xkello commented Jan 26, 2026

@coveralls
Copy link

coveralls commented Jan 26, 2026

Pull Request Test Coverage Report for Build 21519816080

Details

  • 100 of 106 (94.34%) changed or added relevant lines in 5 files are covered.
  • 21 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.04%) to 94.367%

Changes Missing Coverage Covered Lines Changed/Added Lines %
server/mergin/sync/public_api_v2_controller.py 12 14 85.71%
server/mergin/sync/permissions.py 17 21 80.95%
Files with Coverage Reduction New Missed Lines %
server/mergin/tests/test_utils.py 1 99.01%
server/mergin/utils.py 20 67.5%
Totals Coverage Status
Change from base Build 21353134513: -0.04%
Covered Lines: 8192
Relevant Lines: 8681

💛 - Coveralls

Copy link
Collaborator

@MarcelGeo MarcelGeo left a comment

Choose a reason for hiding this comment

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

Nice 🎉

  • we need to double check if 404 is ok if you have empty projects list or return error: 404

  • check def get_projects_by_uuids(uuids) method in project_api_controller.py if everything with permissions is ok here

Copy link
Contributor

@harminius harminius left a comment

Choose a reason for hiding this comment

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

Very good job!

I think two things need to be discussed (to fulfill clients' requirements):
1, Shall all (valid) uuids coming from the request be part of the response or can we skip them as suggested here?
2, Do we need to differentiate between 404 and 403 here with the expose flag? I tend to make things easier by keeping only 404 error.

@harminius
Copy link
Contributor

@xkello Although your approach returns a correct response, I think we need to slightly change the approach.
You can keep the require_project_by_many_uuids() function, but when making the response, I would compare the incoming uuids with ones we have found projects for. All the rest should get the error code.
That's how I understand this requirement: https://github.com/MerginMaps/server-private/issues/3155#issuecomment-3804048237

Copy link
Contributor

@harminius harminius left a comment

Choose a reason for hiding this comment

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

Great job, we're almost there! 👍

I have only one major comment.
I have doubts about the usefulness of require_project_by_many_uuids(). At least it should return a list of projects, and the rest (by_id dict creation) should be done in the controller. However, since this function needs to list even removed projects, it doesn't seem reusable.
The idea of the help function is that it can be used in a different use case, while this function is designed for this specific usecase.

def require_project_by_many_uuids(
uuids: list[str], permission: ProjectPermissions, scheduled=False, expose=True
uuids: list[str], permission: ProjectPermissions
) -> list[dict]:
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 nice if it returned list[Project]

Copy link
Author

Choose a reason for hiding this comment

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

Cant be done I believe since we are returning Project objects as well as per UUID errors. The Logic would have to be split somehow

Copy link
Contributor

Choose a reason for hiding this comment

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

Dict juggling on lines 272 to 296 can nicely be done in the controller.
Now I see it can also filter out those removed projects which is desirable.
Just a bit of code moving, no logic change to make the output of this function generic and reusable.

projects = (
Project.query
.filter(Project.id.in_(valid_uuids))
.filter(Project.storage_params.isnot(None))
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 also these should be included in the response with 404 error

Copy link
Author

Choose a reason for hiding this comment

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

This is already handled at line 277-284. When uuid is not present in project lists it returns 404 automatically regardless of the reason. So in a way the information why was 404 returned is lost but I dont see a reason to store that info since we dont use it - just a side note though

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I'd also filter out Project.removed_at.is_(None) then.

# First user with access to both projects
login(client, DEFAULT_USER[0], DEFAULT_USER[1])

with client:
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm.. this is to pass current user?

Copy link
Author

Choose a reason for hiding this comment

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

Yes and no, the line under is also needed. without these 2 test failure was returning error where user was none. I believe it has something to do with active request context.


# must be logged in (matches suite behavior)
login(client, DEFAULT_USER[0], DEFAULT_USER[1])
#login(client, DEFAULT_USER[0], DEFAULT_USER[1]) TODO: why needed?
Copy link
Contributor

Choose a reason for hiding this comment

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

rm

type: array
description: List of project UUIDs to fetch
items:
$ref: "#/components/parameters/ProjectId"
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 probably due to my previous comment - sorry for that, but here is the path parameter referenced
A clean solution would be to decouple the definition from the location - to move the definition under the Schema component and put the reference in the Parameters components.
Then you can safely reference the schema here in the request body definition

components:
  parameters:
    ProjectIdParam:
      name: id
      in: path
      required: true
      schema:
        $ref: '#/components/schemas/ProjectIdSchema'

type: object
properties:
id:
$ref: "#/components/parameters/ProjectId"
Copy link
Contributor

Choose a reason for hiding this comment

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

the same previous comment - reference a ProjectId schema here, not parameter

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.

5 participants