Skip to content

Commit

Permalink
chore: Merge remote-tracking branch 'origin/main' into feat/transfer-…
Browse files Browse the repository at this point in the history
…site-mutation
  • Loading branch information
David Code Howard committed Oct 23, 2023
2 parents 161dc72 + 35c29ee commit 4103a3d
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 200 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ In the `.env` file

- set values for `APPLE_CLIENT_ID`, `APPLE_KEY_ID`, `APPLE_TEAM_ID`, `APPLE_PRIVATE_KEY` and based on what you have set up on developer.apple.com > Certificates, Identifiers & Profiles > Keys.

- set values for `MICROSOFT_CLIENT_ID` and either `MICROSOFT_CLIENT_SECRET` (less secure) or both `MICROSOFT_PRIVATE_KEY` and `MICROSOFT_CERTIFICATE_THUMBPRINT` based on what you have set up on portal.azure.com > App Registrations > [App Name] > Certificates & Secrets

Start building the Docker images (make sure there's `requirements.txt`
file created before building the images):

Expand Down
194 changes: 97 additions & 97 deletions requirements-dev.txt

Large diffs are not rendered by default.

194 changes: 97 additions & 97 deletions requirements.txt

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions terraso_backend/apps/auth/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,20 @@ def _build_client_secret(self):
)

def fetch_auth_tokens(self, authorization_code):
client_assertion = self._build_client_secret()
params = dict(
client_id=self.CLIENT_ID,
code=authorization_code,
grant_type="authorization_code",
redirect_uri=self.REDIRECT_URI,
client_assertion=client_assertion,
client_assertion_type="urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
)
if not self.CLIENT_SECRET:
params.update(
dict(
client_assertion=self._build_client_secret(),
client_assertion_type="urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
)
)

try:
resp = httpx.post(self.TOKEN_URI, data=params)
resp.raise_for_status()
Expand Down
2 changes: 1 addition & 1 deletion terraso_backend/apps/graphql/schema/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def mutate_and_get_payload(cls, root, info, **kwargs):
if adding_to_project:
project = cls.get_or_throw(Project, "project_id", kwargs["project_id"])
if not user.has_perm(Project.get_perm("add_site"), project):
raise cls.not_allowed(MutationTypes.ADD)
raise cls.not_allowed(MutationTypes.CREATE)
kwargs["project"] = project
else:
kwargs["owner"] = info.context.user
Expand Down
2 changes: 2 additions & 0 deletions terraso_backend/apps/project_management/models/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@


class ProjectSettings(BaseModel):
"""NOTE: Theses settings are currently ignored, and might be removed later"""

class Meta(BaseModel.Meta):
abstract = False

Expand Down
7 changes: 7 additions & 0 deletions terraso_backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,10 @@ def project_user(project: Project) -> User:
membership_status=Membership.APPROVED,
)
return user


@pytest.fixture
def project_user_w_role(request, project: Project):
user = mixer.blend(User)
project.add_user_with_role(user, request.param)
return user
5 changes: 3 additions & 2 deletions terraso_backend/tests/graphql/mutations/test_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def test_site_creation(client_query, user):
assert log_result.metadata == expected_metadata


def test_site_creation_in_project(client, project_manager, project):
@pytest.mark.parametrize("project_user_w_role", ["manager", "contributor"], indirect=True)
def test_site_creation_in_project(client, project_user_w_role, project):
kwargs = site_creation_keywords()
kwargs["projectId"] = str(project.id)
client.force_login(project_manager)
client.force_login(project_user_w_role)
response = graphql_query(CREATE_SITE_QUERY, variables={"input": kwargs}, client=client)
content = json.loads(response.content)
assert "errors" not in content and "errors" not in content["data"]
Expand Down

0 comments on commit 4103a3d

Please sign in to comment.