Skip to content

Commit

Permalink
Merge pull request #8 from acederberg/fix/uuids-only
Browse files Browse the repository at this point in the history
Fix/uuids only
  • Loading branch information
acederberg authored Sep 5, 2024
2 parents 4bf2acb + 4644a72 commit 50eadb8
Show file tree
Hide file tree
Showing 32 changed files with 356 additions and 537 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/pr_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
echo "CAPTURA_CONFIG_CLIENT=$docker_config_path" >> .env
echo "CAPTURA_CONFIG_APP_TEST=$docker_config_path" >> .env
echo "CAPTURA_CONFIG_APP=$docker_config_path" >> .env
echo "CAPTURA_CONFIG_DUMMY=$docker_config_path" >> .env
echo "CAPTURA_FLAKEY=/home/captura/flakey.yaml" >> .env
- name: Start Docker Compose Project.
Expand All @@ -83,9 +84,12 @@ jobs:
echo "MySQL Version: $version" >> $GITHUB_STEP_SUMMARY
docker compose \
--file docker/compose.ci.yaml \
--env-file .env \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& echo $CAPTURA_CONFIG_DUMMY \
&& echo $CAPTURA_CONFIG_APP_TEST \
&& poetry run simulatus initialize \
&& poetry run simulatus apply'
Expand All @@ -103,6 +107,7 @@ jobs:
run: |
docker compose \
--file docker/compose.ci.yaml \
--env-file .env \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
Expand All @@ -123,6 +128,7 @@ jobs:
run: |
docker compose \
--file docker/compose.ci.yaml \
--env-file .env \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
Expand All @@ -140,6 +146,7 @@ jobs:
run: |
docker compose \
--file docker/compose.ci.yaml \
--env-file .env \
cp server:/home/captura/app/coverage-report ./coverage-report
- name: Upload Coverage Report.
Expand Down
4 changes: 2 additions & 2 deletions src/captura/controllers/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def check_one(collection: Collection) -> Collection:

match self.method:
case H.GET if allow_public:
if not collection.public and collection.id_user != token_user.id:
if not collection.public and collection.uuid_user != token_user.uuid:
raise ErrAccessCollection.httpexception(
"_msg_private",
403,
Expand All @@ -497,7 +497,7 @@ def check_one(collection: Collection) -> Collection:
)
return collection
case H.GET | H.POST | H.DELETE | H.PUT | H.PATCH:
if token_user.id != collection.id_user:
if token_user.uuid != collection.uuid_user:
raise ErrAccessCollection.httpexception(
"_msg_modify",
403,
Expand Down
26 changes: 13 additions & 13 deletions src/captura/controllers/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,14 @@ def create_assignment(
data: Data[ResolvedAssignmentDocument] | Data[ResolvedAssignmentCollection],
target: Collection | Document,
) -> Assignment:
id_source_name = f"id_{data.data.kind_source.name}"
id_target_name = f"id_{data.data.kind_target.name}"
id_source_value = data.data.source.id # type: ignore
uuid_source_name = f"uuid_{data.data.kind_source.name}"
uuid_target_name = f"uuid_{data.data.kind_target.name}"
uuid_source_value = data.data.source.uuid # type: ignore

kwargs = {
"uuid": secrets.token_urlsafe(8),
id_source_name: id_source_value,
id_target_name: target.id,
uuid_source_name: uuid_source_value,
uuid_target_name: target.uuid,
}
return Assignment(
**kwargs,
Expand Down Expand Up @@ -414,17 +414,17 @@ def create_grant(
case bad:
raise ValueError(f"Invalid source `{bad}`.")

id_source_name = f"id_{data.data.kind_source.name}"
id_target_name = f"id_{data.data.kind_target.name}"
id_source_value = data.data.source.id # type: ignore
uuid_source_name = f"uuid_{data.data.kind_source.name}"
uuid_target_name = f"uuid_{data.data.kind_target.name}"
uuid_source_value = data.data.source.uuid # type: ignore

kwargs = {
"uuid": secrets.token_urlsafe(8),
"uuid_parent": grant_parent_uuid,
"pending_from": pending_from,
"pending": True,
id_source_name: id_source_value,
id_target_name: target.id,
uuid_source_name: uuid_source_value,
uuid_target_name: target.uuid,
}
return Grant(**kwargs, **self.create_data.model_dump())

Expand Down Expand Up @@ -512,8 +512,8 @@ def document(
data.data.token_user_grants = {
user.uuid: (
Grant(
id_user=user.id,
id_document=document.id,
uuid_user=user.uuid,
uuid_document=document.uuid,
level=Level.own,
pending=False,
pending_from=PendingFrom.created,
Expand Down Expand Up @@ -748,7 +748,7 @@ def collection(self, data: Data[ResolvedCollection]) -> Data[ResolvedCollection]
session,
param.uuid_user,
)
collection.id_user = user.id
collection.uuid_user = user.uuid
data.event.children.append(
Event(
**self.event_common,
Expand Down
8 changes: 4 additions & 4 deletions src/captura/controllers/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def split_assocs(
model_assoc.uuid.in_(data.data.uuid_assoc),
and_(
model_target.uuid.in_(data.data.uuid_target),
getattr(model_assoc, "id_" + data.data.kind_source.name)
== data.data.source.id,
getattr(model_assoc, "uuid_" + data.data.kind_source.name)
== data.data.source.uuid,
),
)
)
Expand Down Expand Up @@ -474,7 +474,7 @@ def _collection(
.join(Document)
.where(
Document.uuid.in_(uuids(documents)), # type: ignore[type-var]
Assignment.id_collection == collection.id,
Assignment.uuid_collection == collection.uuid,
)
)
assignments = {
Expand Down Expand Up @@ -591,7 +591,7 @@ def _document(
select(Assignment)
.join(Collection)
.where(
Assignment.id_document == document.id,
Assignment.uuid_document == document.uuid,
Collection.uuid.in_(uuid_collections),
)
)
Expand Down
Loading

0 comments on commit 50eadb8

Please sign in to comment.