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

✨(backend) add ServiceProvider #522

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

qbey
Copy link
Collaborator

@qbey qbey commented Nov 14, 2024

Purpose

We want to allow Service Providers to fetch our data but we also need a better management of the data available for each one of them.

Proposal

Not included in this PR: allow Service Provider management from the front.

⚠️ This disables the resource server globaly, to only allow it on a per-view basis because we don't want to allow any service provider to be able to query everything without filtering.

  • add the ServiceProvider model
  • allow Service Provider management from Django admin
  • restrict endpoint availability as a resource server
  • update changelog

@qbey qbey force-pushed the qbey/add-service-provider branch 7 times, most recently from d2f7a96 to a57a31d Compare November 15, 2024 15:48
This adds the ServiceProvider notion to allow to better
manage which teams is available for each service provider.
We don't want every Service Provider to be able to request
every endpoint if those are not implementing a filtering on
the data returned. To prevent any data leak we enforce the
developers to manually "whitelist" each endpoint and add
the proper filtering when needed.
When updating an Organization in the Django admin, the validator
falsly raises a "duplicated" error because it does not exclude the
current object from the database lookup.
This allow to display service providers in the frontend.
Not used yet, but will allow to manage organization and
teams related service providers.
Warning where raised because of the casing change between
`FROM` and `as`.
@qbey qbey marked this pull request as ready for review November 15, 2024 16:31
@qbey qbey requested a review from sampaccoud November 15, 2024 16:31
@qbey qbey self-assigned this Nov 15, 2024
@qbey qbey added the backend label Nov 15, 2024
HTTP_AUTHORIZATION="Bearer b64untestedbearertoken",
)

assert response.status_code == HTTP_404_NOT_FOUND
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe the 404 here is a symptom of a wrong split between filtering/annotating and permission checks? No big deal but it resonates with our discussions on impress.

client, authenticated_user_with_service_provider
):
"""
Authenticated users should not be able to delete a team for which they are directly
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Authenticated users should not be able to delete a team for which they are directly
Authenticated users should not be able to retrieve a team for which they are directly

}


def test_api_teams_retrieve_authenticated_other_resource_server(
Copy link
Contributor

Choose a reason for hiding this comment

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

should you also test that a team without any service provider can not be retrieved?

"""
Authenticated users should be able to list teams
they are an owner/administrator/member of, and
the service provider should be filtered to the one
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
the service provider should be filtered to the one
the service providers should be filtered to the one

client, resource_server_settings
):
"""
Authenticated users should be able to create teams and should automatically be declared
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be: Users authenticated via a resource server query ?
If yes, update all below tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

to differentiate from below's test, precise that the service provider should be created on the fly?

def test_api_service_providers_retrieve_authenticated_on_teams(client):
"""
Authenticated users should not be able to retrieve service providers
of because of their teams (might change later if needed).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
of because of their teams (might change later if needed).
just because it is related to one of their teams if it is not related to their organization (might change later if needed).



@responses.activate
def test_api_teams_update_authenticated_owner_resource_server(
Copy link
Contributor

Choose a reason for hiding this comment

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

I was expecting tests about adding/removing service providers from a team for authenticated admin/owners of the team?



@pytest.fixture
def authenticated_user_with_service_provider(client):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def authenticated_user_with_service_provider(client):
def user_authenticated_via_service_provider(client):

@@ -0,0 +1,148 @@
"""Defines fixtures for the tests."""
Copy link
Contributor

Choose a reason for hiding this comment

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

hope we don't abuse this pattern. I like tests to be self understandable without having to jump from file to file to try to understand each fixture.

  • the necessity to define edge cases tends to create complicated code when you try to mutualize test code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants