Add some configuration options for instance admins
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
use rocket::{Outcome, http::Status, request::{self, FromRequest, Request}};
|
||||
|
||||
use users::User;
|
||||
|
||||
/// Wrapper around User to use as a request guard on pages reserved to admins.
|
||||
pub struct Admin(pub User);
|
||||
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for Admin {
|
||||
type Error = ();
|
||||
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Admin, ()> {
|
||||
let user = request.guard::<User>()?;
|
||||
if user.is_admin {
|
||||
Outcome::Success(Admin(user))
|
||||
} else {
|
||||
Outcome::Failure((Status::Unauthorized, ()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,12 @@ impl Blog {
|
||||
Instance::insert(conn, NewInstance {
|
||||
public_domain: inst.clone(),
|
||||
name: inst.clone(),
|
||||
local: false
|
||||
local: false,
|
||||
// We don't really care about all the following for remote instances
|
||||
long_description: String::new(),
|
||||
short_description: String::new(),
|
||||
default_license: String::new(),
|
||||
open_registrations: true
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,7 +13,11 @@ pub struct Instance {
|
||||
pub name: String,
|
||||
pub local: bool,
|
||||
pub blocked: bool,
|
||||
pub creation_date: NaiveDateTime
|
||||
pub creation_date: NaiveDateTime,
|
||||
pub open_registrations: bool,
|
||||
pub short_description: String,
|
||||
pub long_description: String,
|
||||
pub default_license : String
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
@@ -21,7 +25,11 @@ pub struct Instance {
|
||||
pub struct NewInstance {
|
||||
pub public_domain: String,
|
||||
pub name: String,
|
||||
pub local: bool
|
||||
pub local: bool,
|
||||
pub open_registrations: bool,
|
||||
pub short_description: String,
|
||||
pub long_description: String,
|
||||
pub default_license : String
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
@@ -68,4 +76,15 @@ impl Instance {
|
||||
box_name = box_name
|
||||
))
|
||||
}
|
||||
|
||||
pub fn update(&self, conn: &PgConnection, name: String, open_registrations: bool, short_description: String, long_description: String) -> Instance {
|
||||
diesel::update(self)
|
||||
.set((
|
||||
instances::name.eq(name),
|
||||
instances::open_registrations.eq(open_registrations),
|
||||
instances::short_description.eq(short_description),
|
||||
instances::long_description.eq(long_description),
|
||||
)).get_result::<Instance>(conn)
|
||||
.expect("Couldn't update instance")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ pub fn ap_url(url: String) -> String {
|
||||
format!("{}://{}", scheme, url)
|
||||
}
|
||||
|
||||
pub mod admin;
|
||||
pub mod blog_authors;
|
||||
pub mod blogs;
|
||||
pub mod comments;
|
||||
|
||||
@@ -53,6 +53,10 @@ table! {
|
||||
local -> Bool,
|
||||
blocked -> Bool,
|
||||
creation_date -> Timestamp,
|
||||
open_registrations -> Bool,
|
||||
short_description -> Text,
|
||||
long_description -> Text,
|
||||
default_license -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,12 @@ impl User {
|
||||
Instance::insert(conn, NewInstance {
|
||||
name: inst.clone(),
|
||||
public_domain: inst.clone(),
|
||||
local: false
|
||||
local: false,
|
||||
// We don't really care about all the following for remote instances
|
||||
long_description: String::new(),
|
||||
short_description: String::new(),
|
||||
default_license: String::new(),
|
||||
open_registrations: true
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user