Fixing unwrap crash with site_view.rs
This commit is contained in:
parent
9d2046d5a2
commit
9878a58452
1 changed files with 11 additions and 7 deletions
|
@ -281,8 +281,7 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
|
||||||
fn perform(&self, conn: &PgConnection) -> Result<GetSiteResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetSiteResponse, Error> {
|
||||||
let _data: &GetSite = &self.data;
|
let _data: &GetSite = &self.data;
|
||||||
|
|
||||||
let site = Site::read(&conn, 1);
|
let site_view = if let Ok(_site) = Site::read(&conn, 1) {
|
||||||
let site_view = if site.is_ok() {
|
|
||||||
Some(SiteView::read(&conn)?)
|
Some(SiteView::read(&conn)?)
|
||||||
} else if let Some(setup) = Settings::get().setup.as_ref() {
|
} else if let Some(setup) = Settings::get().setup.as_ref() {
|
||||||
let register = Register {
|
let register = Register {
|
||||||
|
@ -312,11 +311,16 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut admins = UserView::admins(&conn)?;
|
let mut admins = UserView::admins(&conn)?;
|
||||||
if site_view.is_some() {
|
|
||||||
let site_creator_id = site_view.to_owned().unwrap().creator_id;
|
// Make sure the site creator is the top admin
|
||||||
let creator_index = admins.iter().position(|r| r.id == site_creator_id).unwrap();
|
if let Some(site_view) = site_view.to_owned() {
|
||||||
let creator_user = admins.remove(creator_index);
|
let site_creator_id = site_view.creator_id;
|
||||||
admins.insert(0, creator_user);
|
// TODO investigate why this is sometimes coming back null
|
||||||
|
// Maybe user_.admin isn't being set to true?
|
||||||
|
if let Some(creator_index) = admins.iter().position(|r| r.id == site_creator_id) {
|
||||||
|
let creator_user = admins.remove(creator_index);
|
||||||
|
admins.insert(0, creator_user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let banned = UserView::banned(&conn)?;
|
let banned = UserView::banned(&conn)?;
|
||||||
|
|
Loading…
Reference in a new issue