Implement models::instance::Instance.has_admin
This commit is contained in:
parent
a7774444fe
commit
f8372f6383
@ -1,7 +1,8 @@
|
|||||||
use diesel;
|
use diesel;
|
||||||
use diesel::{ QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection };
|
use diesel::{ QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection };
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use schema::instances;
|
use schema::{instances, users};
|
||||||
|
use models::user::User;
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable)]
|
#[derive(Identifiable, Queryable)]
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
@ -54,6 +55,10 @@ impl Instance {
|
|||||||
pub fn block(&self) {}
|
pub fn block(&self) {}
|
||||||
|
|
||||||
pub fn has_admin(&self, conn: &PgConnection) -> bool {
|
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 New Issue
Block a user