feat: Add administrator permissions to PermissionsEnum and update related team management functionality

This commit is contained in:
MythEclipse
2025-09-25 20:57:31 +07:00
parent dd4a73e360
commit 4ecdcd12d2
6 changed files with 150 additions and 155 deletions
+33 -24
View File
@@ -241,32 +241,41 @@ impl<'a> TeamsRepository<'a> {
}
pub async fn query_is_team_member(&self, team_id: &Thing, user_id: &Thing) -> Result<bool> {
let now = Instant::now();
let db = &self.state.surrealdb_ws;
let conditions = format!(
"{} AND is_active = true",
build_multi_thing_condition(&[("team_id", team_id), ("user_id", user_id)])
);
let member_count = execute_safe_count_query(
db,
ResourceEnum::TeamMembers.to_string(),
&conditions,
).await.unwrap_or(0);
let elapsed = now.elapsed();
if std::env::var("RUST_ENV").unwrap_or_else(|_| "development".to_string())
== "development"
{
println!("Query 'query_is_team_member' found {} matching members", member_count);
println!("Query 'query_is_team_member' took: {elapsed:.2?}");
let now = Instant::now();
let db = &self.state.surrealdb_ws;
// Use direct SQL query for more control over the team member check
let sql = format!(
"SELECT COUNT() AS count FROM {}
WHERE team_id = $team_id
AND user_id = $user_id
AND is_active = true",
ResourceEnum::TeamMembers
);
let mut result = db.query(sql)
.bind(("team_id", team_id.id.to_raw()))
.bind(("user_id", user_id.id.to_raw()))
.await?;
// Use a simpler approach to get the count
let count = match result.take(0) {
Ok(Some(surrealdb::sql::Value::Number(num))) => num.to_int(),
_ => 0,
};
let elapsed = now.elapsed();
if std::env::var("RUST_ENV").unwrap_or_else(|_| "development".to_string())
== "development"
{
println!("Query 'query_is_team_member' found {} matching members", count);
println!("Query 'query_is_team_member' took: {elapsed:.2?}");
}
Ok(count > 0)
}
Ok(member_count > 0)
}
pub async fn query_create_invitation(&self, data: TeamInvitationsSchema) -> Result<String> {
let now = Instant::now();
let db = &self.state.surrealdb_ws;