From: Dessalines Date: Tue, 14 Apr 2020 16:24:05 +0000 (-0400) Subject: Fixing unwrap crash with site_view.rs X-Git-Url: http://these/git/%7B%60%24%7BghostArchiveUrl%7D/static/%24%7BappleTouchIcon%7D?a=commitdiff_plain;h=9878a58452dad21ce914e84160ada7833058955d;p=lemmy.git Fixing unwrap crash with site_view.rs --- diff --git a/server/src/api/site.rs b/server/src/api/site.rs index 6bd90149..ad45e8d1 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -281,8 +281,7 @@ impl Perform for Oper { fn perform(&self, conn: &PgConnection) -> Result { let _data: &GetSite = &self.data; - let site = Site::read(&conn, 1); - let site_view = if site.is_ok() { + let site_view = if let Ok(_site) = Site::read(&conn, 1) { Some(SiteView::read(&conn)?) } else if let Some(setup) = Settings::get().setup.as_ref() { let register = Register { @@ -312,11 +311,16 @@ impl Perform for Oper { }; let mut admins = UserView::admins(&conn)?; - if site_view.is_some() { - let site_creator_id = site_view.to_owned().unwrap().creator_id; - let creator_index = admins.iter().position(|r| r.id == site_creator_id).unwrap(); - let creator_user = admins.remove(creator_index); - admins.insert(0, creator_user); + + // Make sure the site creator is the top admin + if let Some(site_view) = site_view.to_owned() { + let site_creator_id = site_view.creator_id; + // 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)?;