pub struct Permission {
pub from_role: String,
pub permission: String,
}
Fields§
§from_role: String
the role this permission is coming from
permission: String
the permission itself
Implementations§
Source§impl Permission
impl Permission
Sourcepub fn grant_to_user(
db: &mut Connection,
user_id: i32,
permission: &str,
) -> Result<()>
pub fn grant_to_user( db: &mut Connection, user_id: i32, permission: &str, ) -> Result<()>
Sourcepub fn grant_to_role(
db: &mut Connection,
role: &str,
permission: &str,
) -> Result<()>
pub fn grant_to_role( db: &mut Connection, role: &str, permission: &str, ) -> Result<()>
grant permission
to role
returns Ok(())
, if successful
§Errors
- if
RolePermission::create
fails, returns the error
Sourcepub fn grant_many_to_role(
db: &mut Connection,
role: String,
permissions: Vec<String>,
) -> Result<()>
pub fn grant_many_to_role( db: &mut Connection, role: String, permissions: Vec<String>, ) -> Result<()>
grants every permission in permissions
to role
returns Ok(())
, if successful
§Errors
- if
RolePermission::create_many
fails, returns the error
Sourcepub fn grant_many_to_user(
db: &mut Connection,
user_id: i32,
permissions: Vec<String>,
) -> Result<()>
pub fn grant_many_to_user( db: &mut Connection, user_id: i32, permissions: Vec<String>, ) -> Result<()>
grants every permission in permissions
to role
returns Ok(())
, if successful
§Errors
- If
UserPermission::create_many
fails, returns the error
Sourcepub fn revoke_from_user(
db: &mut Connection,
user_id: i32,
permission: &str,
) -> Result<()>
pub fn revoke_from_user( db: &mut Connection, user_id: i32, permission: &str, ) -> Result<()>
Sourcepub fn revoke_from_role(
db: &mut Connection,
role: String,
permission: String,
) -> Result<()>
pub fn revoke_from_role( db: &mut Connection, role: String, permission: String, ) -> Result<()>
revokes permission
from role
returns Ok(())
, if successful
§Errors
- if
RolePermission::delete
fails, returns the error
TODO: don’t return a result if we never fail, or return a result and not a bool
Sourcepub fn revoke_many_from_user(
db: &mut Connection,
user_id: i32,
permissions: Vec<String>,
) -> Result<()>
pub fn revoke_many_from_user( db: &mut Connection, user_id: i32, permissions: Vec<String>, ) -> Result<()>
Sourcepub fn revoke_many_from_role(
db: &mut Connection,
role: String,
permissions: Vec<String>,
) -> Result<()>
pub fn revoke_many_from_role( db: &mut Connection, role: String, permissions: Vec<String>, ) -> Result<()>
revokes every permission in permissions
from role
returns Ok(())
, if successful
§Errors
- if
RolePermission::delete_many
fails, returns the error
Sourcepub fn revoke_all_from_role(db: &mut Connection, role: &str) -> Result<()>
pub fn revoke_all_from_role(db: &mut Connection, role: &str) -> Result<()>
revokes every permission granted to role
returns Ok(())
, if successful
§Errors
- If
RolePermission::delete_all
fails, returns the error
Sourcepub fn revoke_all_from_user(db: &mut Connection, user_id: i32) -> Result<()>
pub fn revoke_all_from_user(db: &mut Connection, user_id: i32) -> Result<()>
Sourcepub fn fetch_all(db: &mut Connection, user_id: i32) -> Result<Vec<Self>>
pub fn fetch_all(db: &mut Connection, user_id: i32) -> Result<Vec<Self>>
returns every permission granted to the User whose id is user_id
§Errors
diesel::result::Error
if the query fails
Trait Implementations§
Source§impl Clone for Permission
impl Clone for Permission
Source§fn clone(&self) -> Permission
fn clone(&self) -> Permission
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Permission
impl Debug for Permission
Source§impl<'de> Deserialize<'de> for Permission
impl<'de> Deserialize<'de> for Permission
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Hash for Permission
impl Hash for Permission
Source§impl PartialEq for Permission
impl PartialEq for Permission
Source§impl<__DB: Backend> QueryableByName<__DB> for Permission
impl<__DB: Backend> QueryableByName<__DB> for Permission
Source§impl Serialize for Permission
impl Serialize for Permission
impl Eq for Permission
Auto Trait Implementations§
impl Freeze for Permission
impl RefUnwindSafe for Permission
impl Send for Permission
impl Sync for Permission
impl Unpin for Permission
impl UnwindSafe for Permission
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<DB, T> FromSqlRow<Untyped, DB> for Twhere
DB: Backend,
T: QueryableByName<DB>,
impl<DB, T> FromSqlRow<Untyped, DB> for Twhere
DB: Backend,
T: QueryableByName<DB>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
Convert
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
Convert
&self
to an expression for Diesel’s query builder. Read more