mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-22 11:31:01 +00:00
Implement models::instance::Instance.has_admin
This commit is contained in:
parent
a7774444fe
commit
f8372f6383
1 changed files with 7 additions and 2 deletions
|
@ -1,7 +1,8 @@
|
|||
use diesel;
|
||||
use diesel::{ QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection };
|
||||
use std::iter::Iterator;
|
||||
use schema::instances;
|
||||
use schema::{instances, users};
|
||||
use models::user::User;
|
||||
|
||||
#[derive(Identifiable, Queryable)]
|
||||
pub struct Instance {
|
||||
|
@ -54,6 +55,10 @@ impl Instance {
|
|||
pub fn block(&self) {}
|
||||
|
||||
pub fn has_admin(&self, conn: &PgConnection) -> bool {
|
||||
false
|
||||
users::table.filter(users::instance_id.eq(self.id))
|
||||
.filter(users::is_admin.eq(true))
|
||||
.load::<User>(conn)
|
||||
.expect("Couldn't load admins")
|
||||
.len() > 0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue