Refactor recipe editing logic to use User's method for permission check and update template accordingly
This commit is contained in:
parent
be6905cc3b
commit
c296689c6b
4 changed files with 9 additions and 7 deletions
|
|
@ -16,6 +16,12 @@ pub struct User {
|
|||
pub is_admin: bool,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn can_edit_recipe(&self, recipe: &Recipe) -> bool {
|
||||
self.is_admin || recipe.user_id == self.id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, FromRow)]
|
||||
pub struct UserLoginInfo {
|
||||
pub last_login_datetime: DateTime<Utc>,
|
||||
|
|
@ -45,10 +51,6 @@ pub struct Recipe {
|
|||
pub groups: Vec<Group>,
|
||||
}
|
||||
|
||||
pub fn can_user_edit_recipe(user: &User, recipe: &Recipe) -> bool {
|
||||
user.is_admin || recipe.user_id == user.id
|
||||
}
|
||||
|
||||
#[derive(Debug, FromRow)]
|
||||
pub struct Group {
|
||||
pub id: i64,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue