Skip to content

Conversation

@AidCheng
Copy link
Contributor

  • Added system_required field for reviewer
  • Set system_required field false by default
  • Modified corresponding logic to forbid the removal of system_required reviewer
  • Created API endpoints reviewer/system/set to modify system_required status

@genedna genedna requested a review from Copilot November 18, 2025 15:41
@genedna genedna requested a review from benjamin-747 November 18, 2025 15:41
Copilot finished reviewing on behalf of genedna November 18, 2025 15:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a system_required field to the reviewer system, enabling reviewers to be marked as system-required and preventing their removal through normal deletion operations. The implementation includes database schema changes, storage layer methods, API endpoints, and model updates.

Key Changes:

  • Database migration adds system_required boolean field to mega_cl_reviewer table with a default value of false
  • Storage layer provides methods to set/remove system-required status and prevents deletion of system-required reviewers
  • New API endpoint /{link}/reviewer/system/set allows modification of system-required status

Reviewed Changes

Copilot reviewed 53 out of 53 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
mono/src/api/router/cl_router.rs Adds new API endpoint for setting/removing system-required reviewer status and includes the field in reviewer listing responses
jupiter/src/storage/cl_reviewer_storage.rs Implements storage methods for managing system-required status and modifies remove_reviewers to filter out system-required reviewers
jupiter/src/migration/mod.rs Registers the new migration module for the system_required field
jupiter/src/migration/m20251117_181240_add_system_required_field_for_reviewer.rs Creates database migration to add system_required boolean column with default false
jupiter/callisto/src/mega_cl_reviewer.rs Updates entity model to include system_required field
ceres/src/model/change_list.rs Adds SetSystemReviewersPayload for API requests and includes system_required in ReviewerInfo response
jupiter/callisto/src/*.rs (multiple files) Generated entity files showing sea-orm-codegen version changes (unrelated to feature)

@genedna genedna requested a review from Copilot November 18, 2025 23:46
Copilot finished reviewing on behalf of genedna November 18, 2025 23:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 54 out of 54 changed files in this pull request and generated 5 comments.

pub async fn update_system_required_reviewers(
&self,
cl_link: &str,
reviewers: &Vec<String>,
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The parameter reviewers should be &[String] instead of &Vec<String>. Taking a reference to a Vec is an anti-pattern; use a slice reference instead for better API design and performance.

Copilot uses AI. Check for mistakes.
Comment on lines 675 to 681
async fn set_system_required_reviewers(
_user: LoginUser,
state: State<MonoApiServiceState>,
Path(link): Path<String>,
Json(payload): Json<SetSystemReviewersPayload>,
) -> Result<Json<CommonResult<String>>, ApiError> {
// TODO: Add permission check with cedar policy
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The endpoint lacks any permission/authorization check to restrict who can modify the system-required status of reviewers. While there's a TODO comment acknowledging this, this is a security concern that should be addressed before merging. Setting system-required status is a privileged operation that should only be available to administrators or users with specific permissions. Consider implementing at least basic role-based access control here, or ensure this is blocked from public access until proper Cedar policy checks are implemented.

Copilot uses AI. Check for mistakes.
Comment on lines 680 to 691
) -> Result<Json<CommonResult<String>>, ApiError> {
// TODO: Add permission check with cedar policy
state
.storage
.reviewer_storage()
.update_system_required_reviewers(
&link,
&payload.target_reviewer_usernames,
payload.is_system_required,
)
.await?;
Ok(Json(CommonResult::success(None)))
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The API endpoint returns CommonResult<String> but passes None to the success response. The return type should be CommonResult<()> instead to accurately reflect that no data is being returned. This makes the API contract clearer.

Copilot uses AI. Check for mistakes.
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.17
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.15
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

All the entity files in jupiter/callisto/src/ show the version comment changed from sea-orm-codegen 1.1.17 to sea-orm-codegen 1.1.15, which is a downgrade. However, the workspace Cargo.toml specifies sea-orm = "1.1.17". This inconsistency suggests these files were regenerated with an older version of sea-orm-codegen. Please regenerate these entity files using the correct version (1.1.17) that matches the project dependencies to ensure consistency and avoid potential compatibility issues.

Copilot uses AI. Check for mistakes.
@genedna genedna requested a review from Copilot November 19, 2025 01:12
Copilot finished reviewing on behalf of genedna November 19, 2025 01:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 54 out of 54 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

jupiter/src/storage/cl_reviewer_storage.rs:102

  • The remove_reviewers function silently skips system-required reviewers due to the .filter(mega_cl_reviewer::Column::SystemRequired.eq(false)) condition. This could confuse API consumers who attempt to remove a system-required reviewer, as they will receive a successful response even though the reviewer was not removed.

Consider either:

  1. Checking if any of the target reviewers are system-required before deletion and returning an error with a clear message like "Cannot remove system-required reviewer: {username}"
  2. Returning information about which reviewers were actually removed vs. skipped

This would provide better feedback to API consumers and avoid silent failures.

@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.17
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.15
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

All callisto entity files show a version downgrade in the generation comment from 1.1.17 to 1.1.15. This appears to indicate the entities were regenerated with an older version of sea-orm-codegen.

This could lead to inconsistencies if different parts of the codebase were generated with different versions. Please verify:

  1. Whether this downgrade is intentional
  2. If not, regenerate the entities with the consistent version (preferably the latest: 1.1.17)
  3. Ensure all team members use the same version of sea-orm-codegen for entity generation
Suggested change
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.15
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.17

Copilot uses AI. Check for mistakes.
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

This boilerplate comment should be removed or replaced with a description of what this migration does. The comment "Replace the sample below with your own migration scripts" is a leftover template comment that doesn't belong in production code.

Copilot uses AI. Check for mistakes.
Comment on lines 675 to 692
async fn set_system_required_reviewers(
_user: LoginUser,
state: State<MonoApiServiceState>,
Path(link): Path<String>,
Json(payload): Json<SetSystemReviewersPayload>,
) -> Result<Json<CommonResult<String>>, ApiError> {
// TODO: Add permission check with cedar policy
state
.storage
.reviewer_storage()
.update_system_required_reviewers(
&link,
&payload.target_reviewer_usernames,
payload.is_system_required,
)
.await?;
Ok(Json(CommonResult::success(None)))
}
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The set_system_required_reviewers endpoint lacks authorization checks. This is a security concern as marking reviewers as "system required" is a privileged operation that should be restricted to administrators or users with appropriate permissions.

The TODO comment acknowledges this, but the endpoint is exposed without any access control. Consider implementing the Cedar policy check before merging this PR, or at minimum, add a temporary permission check (e.g., checking if the user is an admin) to prevent unauthorized modifications.

Copilot uses AI. Check for mistakes.
@benjamin-747
Copy link
Collaborator

link #1632

@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.17
Copy link
Collaborator

Choose a reason for hiding this comment

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

请升级cli 到最新的版本并提交

@benjamin-747
Copy link
Collaborator

@AidCheng 需要同时解决合并冲突问题

@genedna genedna requested a review from Copilot November 23, 2025 16:09
Copilot finished reviewing on behalf of genedna November 23, 2025 16:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comments suppressed due to low confidence (1)

jupiter/src/storage/cl_reviewer_storage.rs:102

  • The remove_reviewers function silently skips system-required reviewers without notifying the caller. Consider returning information about which reviewers were actually removed vs. which were skipped due to being system-required, or at least logging when a removal attempt is skipped. This would provide better feedback to API consumers.

Example approach:

pub async fn remove_reviewers(
    &self,
    cl_link: &str,
    reviewers: Vec<String>,
) -> Result<Vec<String>, MegaError> {
    let mut removed = Vec::new();
    for reviewer in reviewers {
        let result = mega_cl_reviewer::Entity::delete_many()
            .filter(mega_cl_reviewer::Column::ClLink.eq(cl_link))
            .filter(mega_cl_reviewer::Column::Username.eq(reviewer.clone()))
            .filter(mega_cl_reviewer::Column::SystemRequired.eq(false))
            .exec(self.get_connection())
            .await
            .map_err(|e| {
                tracing::error!("{}", e);
                MegaError::with_message(format!("fail to remove reviewer {}", reviewer))
            })?;
        
        if result.rows_affected > 0 {
            removed.push(reviewer);
        } else {
            tracing::info!("Skipped removal of system-required reviewer: {}", reviewer);
        }
    }
    Ok(removed)
}

Comment on lines +52 to +82
pub async fn update_system_required_reviewers(
&self,
cl_link: &str,
reviewers: &Vec<String>,
system_required: bool,
) -> Result<(), MegaError> {
for reviewer in reviewers {
let mut rev: mega_cl_reviewer::ActiveModel = mega_cl_reviewer::Entity::find()
.filter(mega_cl_reviewer::Column::ClLink.eq(cl_link))
.filter(mega_cl_reviewer::Column::Username.eq(reviewer))
.one(self.get_connection())
.await
.map_err(|e| {
tracing::error!("{}", e);
MegaError::with_message(format!("fail to find reviewer {}", reviewer))
})?
.ok_or_else(|| MegaError::with_message(format!("reviewer {} not found", reviewer)))?
.into_active_model();

rev.system_required = Set(system_required);
rev.updated_at = Set(chrono::Utc::now().naive_utc());
rev.update(self.get_connection()).await.map_err(|e| {
tracing::error!("{}", e);
MegaError::with_message(format!(
"fail to update system required for reviewer {}",
reviewer
))
})?;
}
Ok(())
}
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The PR description mentions creating API endpoints reviewer/system/set to modify system_required status, but this endpoint is not present in the code changes. The update_system_required_reviewers method is defined in the storage layer but there's no corresponding API endpoint to expose this functionality. Consider adding the missing endpoint or updating the PR description to reflect what was actually implemented.

Copilot uses AI. Check for mistakes.

pub enum ActionEnum {
// ** Anyone
UnprotectedRequest,
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The UnprotectedRequest action variant is added but never used in this codebase. It's not mapped in the CL_ROUTER_ACTIONS HashMap or the Display implementation. If this is intended for future use, consider documenting that with a comment. Otherwise, remove it to avoid dead code.

Copilot uses AI. Check for mistakes.
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