Skip to content

fix: fix ID type in permission#2006

Merged
benjamin-747 merged 1 commit into
gitmono-dev:mainfrom
AllureCurtain:fix/permission-id
Mar 10, 2026
Merged

fix: fix ID type in permission#2006
benjamin-747 merged 1 commit into
gitmono-dev:mainfrom
AllureCurtain:fix/permission-id

Conversation

@AllureCurtain

Copy link
Copy Markdown
Contributor

No description provided.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27d46d3510

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Ok(note_id.to_string())
let note = state
.note_stg()
.get_note_by_public_id(normalized_resource_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Backfill stored permission IDs before switching to public_id

This change makes note permissions canonicalize resource_id to note.public_id, but existing permission rows created before this commit were keyed by numeric note.id (the previous parser normalized to i64), and permission queries/deletes in storage still match resource_id by exact string. In environments with pre-existing data, lookups for the same note will stop finding old rows and updates can create a second permission set under the new key, effectively dropping current permissions until a data migration or compatibility lookup is added.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the permission APIs to resolve resource IDs correctly (notably for note), aligning request path IDs with the backing storage format and improving API documentation around missing resources.

Changes:

  • Replace parse_resource_context with async resolve_resource_context that validates/normalizes resource IDs via storage lookup.
  • Add NoteStorage::get_note_by_public_id and use it to return 404 when a referenced note resource doesn’t exist.
  • Update OpenAPI (utoipa) response docs to include/clarify 404 “Resource not found” cases.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
mono/src/api/router/permission_router.rs Switches to async resource context resolution; documents 404 for missing resources.
mono/src/api/router/group_router.rs Switches to async resource context resolution across group permission endpoints; updates 404 descriptions.
mono/src/api/api_common/group_permission.rs Introduces resolve_resource_context and resource ID resolution via note public_id lookup.
jupiter/src/storage/note_storage.rs Adds get_note_by_public_id query helper used by the API layer.

Comment on lines +82 to +86
let note = state
.note_stg()
.get_note_by_public_id(normalized_resource_id)
.await?
.ok_or_else(|| {

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

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

resolve_resource_id loads the full notes::Model (including large text columns like description_html) just to validate existence/normalize the ID. This adds avoidable DB/IO overhead on every permission request. Consider switching to an existence check or a query that selects only a small column (e.g., id/public_id) and then return normalized_resource_id.to_owned() once the row is confirmed to exist.

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +39
pub async fn get_note_by_public_id(
&self,
public_id: &str,
) -> Result<Option<notes::Model>, MegaError> {
let model = notes::Entity::find()
.filter(notes::Column::PublicId.eq(public_id))
.one(self.get_connection())
.await?;
Ok(model)

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

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

get_note_by_public_id is newly added but has no unit tests. Other storage modules in this repo use #[cfg(test)] + crate::tests::test_storage to cover query behavior; adding a small test here would help prevent regressions (e.g., ensuring it returns Some for an inserted note and None for a missing public_id).

Copilot generated this review using guidance from repository custom instructions.
@benjamin-747 benjamin-747 added this pull request to the merge queue Mar 10, 2026
Merged via the queue into gitmono-dev:main with commit d4639d8 Mar 10, 2026
12 checks passed
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.

3 participants