Skip to content

Commit

Permalink
🛂 为工具接口添加配餐权限
Browse files Browse the repository at this point in the history
  • Loading branch information
phidiaLam committed Sep 3, 2024
1 parent bcef6fb commit 9432903
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use sea_orm_migration::{
prelude::*,
sea_orm::{DeriveActiveEnum, EnumIter},
};
use sql_models::admin_user::{AuthLevel, Column::Auth};

use super::m20220722_082735_change_user_table_name::AdminUser;
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str { "m20240903_224011_admin_alter_auth" }
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let mut al = sea_query::Table::alter();
al.table(AdminUser::Table).modify_column(
ColumnDef::new_with_type(Auth, AuthLevel::column_type())
.not_null(),
);
manager.alter_table(al).await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// 这边回滚需要删除一下authlevel中的Outsourcing
let mut al = sea_query::Table::alter();
al.table(AdminUser::Table).modify_column(
ColumnDef::new_with_type(Auth, OldAuthLevel::column_type())
.not_null(),
);
manager.alter_table(al).await?;

Ok(())
}
}

#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "auth")]
pub enum OldAuthLevel {
#[sea_orm(string_value = "chef")]
Chef,
#[sea_orm(string_value = "cooker")]
Cooker,
#[sea_orm(string_value = "architect")]
Architect,
#[sea_orm(string_value = "outsourcing")]
Outsourcing,
}
1 change: 1 addition & 0 deletions persistence/migrate/sql-migration/src/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod m20220429_230336_alter_user;
pub mod m20220722_082735_change_user_table_name;
pub mod m20221218_001732_charset_and_collate;
pub mod m20240519_011405_alter_auth;
pub mod m20240903_224011_alter_auth;
1 change: 1 addition & 0 deletions persistence/migrate/sql-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl MigratorTrait for Migrator {
ceobe_operation_tool_link::m20231018_162927_create::Migration
ceobe_operation_tool_link::m20240519_004238_add_infos::Migration
admin::m20240519_011405_alter_auth::Migration
admin::m20240903_224011_alter_auth::Migration
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum AuthLevel {
#[serde(rename = "architect")]
#[sea_orm(string_value = "architect")]
Architect,
#[serde(rename = "outsourcing")]
#[sea_orm(string_value = "outsourcing")]
Outsourcing,
#[serde(rename = "porter")]
#[sea_orm(string_value = "porter")]
Porter,
}
6 changes: 3 additions & 3 deletions src/router/back_end/ceobe_operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use self::{
use crate::{
middleware::authorize::AuthorizeLayer,
new_auth_level,
utils::user_authorize::auth_level::prefabs::{Chef, Cooker, Outsourcing},
utils::user_authorize::auth_level::prefabs::{Chef, Cooker, Porter},
};

mod announcement;
Expand All @@ -28,8 +28,8 @@ pub(super) fn ceobe_operation_router() -> crate::router::ServerRoute {
.nest("/video", video_router())
.nest("/version", version_router())
.nest("/resource", resource_router())
.nest("/toolLink", tool_link_router())
.route_layer(AuthorizeLayer::<CeobeOperationAuth>::new())
.nest("/toolLink", tool_link_router())
}

new_auth_level! {
Expand All @@ -42,6 +42,6 @@ new_auth_level! {
pub CeobeTools=>[
Chef
Cooker
Outsourcing
Porter
]
}
21 changes: 16 additions & 5 deletions src/router/back_end/ceobe_operation/tool_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use axum::{
Router,
};

use super::{CeobeOperationAuth, CeobeTools};
use crate::middleware::authorize::AuthorizeLayer;

pub struct CeobeOpToolLink;

pub fn tool_link_router() -> crate::router::ServerRoute {
Expand All @@ -11,9 +14,17 @@ pub fn tool_link_router() -> crate::router::ServerRoute {
.route("/update", post(CeobeOpToolLink::update_one))
.route("/delete", delete(CeobeOpToolLink::delete_one))
.route("/list", get(CeobeOpToolLink::list))
.route("/uploadAvatar", post(CeobeOpToolLink::upload_avatar))
.route("/pageShow", get(CeobeOpToolLink::all_with_paginator))
.route("/createOne", post(CeobeOpToolLink::create_one_mongo))
.route("/updateOne", post(CeobeOpToolLink::update_one_mongo))
.route("/deleteOne", delete(CeobeOpToolLink::delete_one_mongo))
.route_layer(AuthorizeLayer::<CeobeOperationAuth>::new())
.merge(
Router::new()
.route("/uploadAvatar", post(CeobeOpToolLink::upload_avatar))
.route("/pageShow", get(CeobeOpToolLink::all_with_paginator))
.route("/createOne", post(CeobeOpToolLink::create_one_mongo))
.route("/updateOne", post(CeobeOpToolLink::update_one_mongo))
.route(
"/deleteOne",
delete(CeobeOpToolLink::delete_one_mongo),
)
.route_layer(AuthorizeLayer::<CeobeTools>::new()),
)
}
8 changes: 4 additions & 4 deletions src/utils/user_authorize/auth_level_check/prefabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ impl AuthLevelVerify for Architect {
}

#[derive(Clone)]
pub struct Outsourcing;
pub struct Porter;

impl AuthLevelVerify for Outsourcing {
fn auth_name() -> &'static str { "Outsourcing" }
impl AuthLevelVerify for Porter {
fn auth_name() -> &'static str { "Porter" }

fn verify(token_auth: &AuthLevel) -> bool {
matches!(token_auth, &AuthLevel::Outsourcing)
matches!(token_auth, &AuthLevel::Porter)
}
}

Expand Down

0 comments on commit 9432903

Please sign in to comment.