feat(service): expand service layer with new domain operations

- Add IM service modules: audit, channel roles, custom emojis, forum
  tags, integrations, invitations, repo links, slash commands, stages,
  voice, webhooks
- Add PR service modules: review requests, templates
- Add repo service modules: contributors, release assets, git extras
  (archive, branch rename, commit extras, diff/merge, tag, tree)
- Add user service: social (follow/block)
- Add internal auth service
- Update existing service modules with expanded functionality
- Remove deleted IM modules: articles, delivery trace, drafts,
  follows, messages, polls, presence, reactions, threads
This commit is contained in:
zhenyi
2026-06-10 18:49:32 +08:00
parent cec6dce955
commit 420dedbc1e
100 changed files with 3797 additions and 3839 deletions
+21 -5
View File
@@ -5,7 +5,7 @@ use crate::models::issues::IssueAssignee;
use crate::service::IssueService;
use crate::session::Session;
use super::util::{clamp_limit_offset, ensure_affected};
use super::util::{clamp_limit_offset, ensure_affected, set_local_user_id};
impl IssueService {
pub async fn issue_assignees(
@@ -44,6 +44,24 @@ impl IssueService {
let issue = self.resolve_issue(wk_name, number).await?;
let issue_id = issue.id;
self.ensure_issue_editable(user_uid, &issue).await?;
// Verify assignee is a workspace member
let is_member: bool = sqlx::query_scalar(
"SELECT EXISTS(SELECT 1 FROM workspace_member \
WHERE workspace_id = $1 AND user_id = $2 AND status = 'active')",
)
.bind(issue.workspace_id)
.bind(assignee_id)
.fetch_one(self.ctx.db.reader())
.await
.map_err(AppError::Database)?;
if !is_member {
return Err(AppError::BadRequest(
"user is not a member of this workspace".into(),
));
}
let now = chrono::Utc::now();
let mut txn = self
.ctx
@@ -52,8 +70,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
@@ -102,8 +119,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
+4 -7
View File
@@ -5,7 +5,7 @@ use crate::models::issues::IssueComment;
use crate::service::IssueService;
use crate::session::Session;
use super::util::{clamp_limit_offset, ensure_affected, required_text};
use super::util::{clamp_limit_offset, ensure_affected, required_text, set_local_user_id};
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, utoipa::ToSchema)]
pub struct CreateCommentParams {
@@ -71,8 +71,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
@@ -149,8 +148,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
@@ -207,8 +205,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
+3 -5
View File
@@ -6,7 +6,7 @@ use crate::models::issues::{IssueLabel, IssueLabelRelation};
use crate::service::IssueService;
use crate::session::Session;
use super::util::{clamp_limit_offset, ensure_affected, required_text};
use super::util::{clamp_limit_offset, ensure_affected, required_text, set_local_user_id};
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, utoipa::ToSchema)]
pub struct CreateLabelParams {
@@ -182,8 +182,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
@@ -226,8 +225,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
+24 -2
View File
@@ -126,12 +126,34 @@ impl IssueService {
let repo_id = self.resolve_repo_id(wk_name, repo_name).await?;
self.ensure_repo_role(repo_id, user_uid, Role::Admin)
.await?;
let mut txn = self
.ctx
.db
.writer()
.begin()
.await
.map_err(|_| AppError::TxnError)?;
// Clear milestone_id from all issues that reference this milestone
sqlx::query(
"UPDATE issue SET milestone_id = NULL, updated_at = $1 WHERE milestone_id = $2",
)
.bind(chrono::Utc::now())
.bind(milestone_id)
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
let result = sqlx::query("DELETE FROM issue_milestone WHERE id = $1 AND repo_id = $2")
.bind(milestone_id)
.bind(repo_id)
.execute(self.ctx.db.writer())
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
ensure_affected(result.rows_affected(), "milestone not found")
ensure_affected(result.rows_affected(), "milestone not found")?;
txn.commit().await.map_err(|_| AppError::TxnError)?;
Ok(())
}
}
+3 -5
View File
@@ -6,7 +6,7 @@ use crate::models::issues::IssuePrRelation;
use crate::service::IssueService;
use crate::session::Session;
use super::util::{clamp_limit_offset, ensure_affected, parse_enum};
use super::util::{clamp_limit_offset, ensure_affected, parse_enum, set_local_user_id};
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, utoipa::ToSchema)]
pub struct LinkPrParams {
@@ -68,8 +68,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
@@ -104,8 +103,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
+3 -5
View File
@@ -6,7 +6,7 @@ use crate::models::issues::IssueRepoRelation;
use crate::service::IssueService;
use crate::session::Session;
use super::util::{clamp_limit_offset, ensure_affected, parse_enum};
use super::util::{clamp_limit_offset, ensure_affected, parse_enum, set_local_user_id};
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug, utoipa::ToSchema)]
pub struct LinkRepoParams {
@@ -64,8 +64,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
@@ -100,8 +99,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
+3 -5
View File
@@ -5,7 +5,7 @@ use crate::models::issues::IssueSubscriber;
use crate::service::IssueService;
use crate::session::Session;
use super::util::{clamp_limit_offset, ensure_affected};
use super::util::{clamp_limit_offset, ensure_affected, set_local_user_id};
impl IssueService {
pub async fn issue_subscribers(
@@ -51,8 +51,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
@@ -87,8 +86,7 @@ impl IssueService {
.begin()
.await
.map_err(|_| AppError::TxnError)?;
sqlx::query("SET LOCAL app.current_user_id = $1")
.bind(user_uid)
sqlx::query(set_local_user_id(user_uid))
.execute(&mut *txn)
.await
.map_err(AppError::Database)?;
+2 -1
View File
@@ -1,3 +1,4 @@
pub use crate::service::util::{
clamp_limit_offset, ensure_affected, merge_optional_text, parse_enum, required_text, role_level,
clamp_limit_offset, ensure_affected, merge_optional_text, parse_enum, required_text,
role_level, set_local_user_id,
};