Skip to content

Commit b903372

Browse files
committed
fix: permission mistake in team
1 parent 130c63b commit b903372

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

crates/db/src/util/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ use crate::{entity::team::State, get_db};
77

88
pub async fn is_user_in_team(user_id: i64, team_id: i64) -> Result<bool, DbErr> {
99
Ok(crate::entity::team_user::Entity::find()
10-
.join(
11-
JoinType::InnerJoin,
12-
crate::entity::team_user::Relation::Team.def().rev(),
13-
)
1410
.filter(crate::entity::team_user::Column::UserId.eq(user_id))
1511
.filter(crate::entity::team_user::Column::TeamId.eq(team_id))
1612
.count(get_db())

crates/web/src/router/api/game/game_id/team/team_id/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub async fn delete_team(
8282
Extension(ext): Extension<Ext>, Path((_game_id, team_id)): Path<(i64, i64)>,
8383
) -> Result<WebResponse<()>, WebError> {
8484
let operator = ext.operator.ok_or(WebError::Unauthorized(json!("")))?;
85-
if operator.group != Group::Admin {
85+
if operator.group != Group::Admin && !cds_db::util::is_user_in_team(operator.id, team_id).await? {
8686
return Err(WebError::Forbidden(json!("")));
8787
}
8888

crates/web/src/router/api/game/game_id/team/team_id/token/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub async fn create_token(
3131
.ok_or(WebError::BadRequest(json!("team_not_found")))?,
3232
);
3333

34-
if operator.group != Group::Admin && cds_db::util::is_user_in_team(operator.id, team.id).await?
34+
if operator.group != Group::Admin && !cds_db::util::is_user_in_team(operator.id, team.id).await?
3535
{
3636
return Err(WebError::Forbidden(json!("")));
3737
}
@@ -61,7 +61,7 @@ pub async fn get_token(
6161
.ok_or(WebError::BadRequest(json!("team_not_found")))?,
6262
);
6363

64-
if operator.group != Group::Admin && cds_db::util::is_user_in_team(operator.id, team.id).await?
64+
if operator.group != Group::Admin && !cds_db::util::is_user_in_team(operator.id, team.id).await?
6565
{
6666
return Err(WebError::Forbidden(json!("")));
6767
}
@@ -89,7 +89,7 @@ pub async fn delete_token(
8989
.ok_or(WebError::BadRequest(json!("team_not_found")))?,
9090
);
9191

92-
if operator.group != Group::Admin && cds_db::util::is_user_in_team(operator.id, team.id).await?
92+
if operator.group != Group::Admin && !cds_db::util::is_user_in_team(operator.id, team.id).await?
9393
{
9494
return Err(WebError::Forbidden(json!("")));
9595
}

0 commit comments

Comments
 (0)