From f8372f6383c7bf4378c0b535290d55bba55a5535 Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 22 Apr 2018 19:17:40 +0100 Subject: [PATCH] Implement models::instance::Instance.has_admin --- src/models/instance.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/models/instance.rs b/src/models/instance.rs index 7d0944fc..d6f4fb8d 100644 --- a/src/models/instance.rs +++ b/src/models/instance.rs @@ -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::(conn) + .expect("Couldn't load admins") + .len() > 0 } }