2019-05-05 05:20:38 +00:00
|
|
|
use super::*;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct ListCategories;
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct ListCategoriesResponse {
|
|
|
|
op: String,
|
2019-09-07 15:35:05 +00:00
|
|
|
categories: Vec<Category>,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct Search {
|
|
|
|
q: String,
|
|
|
|
type_: String,
|
|
|
|
community_id: Option<i32>,
|
|
|
|
sort: String,
|
|
|
|
page: Option<i64>,
|
|
|
|
limit: Option<i64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct SearchResponse {
|
|
|
|
op: String,
|
2019-08-22 05:17:15 +00:00
|
|
|
type_: String,
|
2019-05-05 05:20:38 +00:00
|
|
|
comments: Vec<CommentView>,
|
|
|
|
posts: Vec<PostView>,
|
2019-08-10 17:32:06 +00:00
|
|
|
communities: Vec<CommunityView>,
|
|
|
|
users: Vec<UserView>,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct GetModlog {
|
|
|
|
mod_user_id: Option<i32>,
|
|
|
|
community_id: Option<i32>,
|
|
|
|
page: Option<i64>,
|
|
|
|
limit: Option<i64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct GetModlogResponse {
|
|
|
|
op: String,
|
|
|
|
removed_posts: Vec<ModRemovePostView>,
|
|
|
|
locked_posts: Vec<ModLockPostView>,
|
2019-09-09 06:14:13 +00:00
|
|
|
stickied_posts: Vec<ModStickyPostView>,
|
2019-05-05 05:20:38 +00:00
|
|
|
removed_comments: Vec<ModRemoveCommentView>,
|
|
|
|
removed_communities: Vec<ModRemoveCommunityView>,
|
|
|
|
banned_from_community: Vec<ModBanFromCommunityView>,
|
|
|
|
banned: Vec<ModBanView>,
|
|
|
|
added_to_community: Vec<ModAddCommunityView>,
|
|
|
|
added: Vec<ModAddView>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct CreateSite {
|
|
|
|
name: String,
|
|
|
|
description: Option<String>,
|
2019-09-07 15:35:05 +00:00
|
|
|
auth: String,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct EditSite {
|
|
|
|
name: String,
|
|
|
|
description: Option<String>,
|
2019-09-07 15:35:05 +00:00
|
|
|
auth: String,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
2019-06-12 01:41:01 +00:00
|
|
|
pub struct GetSite;
|
2019-05-05 05:20:38 +00:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct SiteResponse {
|
|
|
|
op: String,
|
|
|
|
site: SiteView,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct GetSiteResponse {
|
|
|
|
op: String,
|
|
|
|
site: Option<SiteView>,
|
|
|
|
admins: Vec<UserView>,
|
|
|
|
banned: Vec<UserView>,
|
|
|
|
}
|
|
|
|
|
2019-08-24 02:40:41 +00:00
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct TransferSite {
|
|
|
|
user_id: i32,
|
2019-09-07 15:35:05 +00:00
|
|
|
auth: String,
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-05 05:20:38 +00:00
|
|
|
impl Perform<ListCategoriesResponse> for Oper<ListCategories> {
|
|
|
|
fn perform(&self) -> Result<ListCategoriesResponse, Error> {
|
2019-05-05 16:20:30 +00:00
|
|
|
let _data: &ListCategories = &self.data;
|
2019-05-05 05:20:38 +00:00
|
|
|
let conn = establish_connection();
|
|
|
|
|
|
|
|
let categories: Vec<Category> = Category::list_all(&conn)?;
|
|
|
|
|
|
|
|
// Return the jwt
|
2019-09-07 15:35:05 +00:00
|
|
|
Ok(ListCategoriesResponse {
|
|
|
|
op: self.op.to_string(),
|
|
|
|
categories: categories,
|
|
|
|
})
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Perform<GetModlogResponse> for Oper<GetModlog> {
|
|
|
|
fn perform(&self) -> Result<GetModlogResponse, Error> {
|
2019-05-05 16:20:30 +00:00
|
|
|
let data: &GetModlog = &self.data;
|
2019-05-05 05:20:38 +00:00
|
|
|
let conn = establish_connection();
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
let removed_posts = ModRemovePostView::list(
|
|
|
|
&conn,
|
|
|
|
data.community_id,
|
|
|
|
data.mod_user_id,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
|
|
|
let locked_posts = ModLockPostView::list(
|
|
|
|
&conn,
|
|
|
|
data.community_id,
|
|
|
|
data.mod_user_id,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
2019-09-09 06:14:13 +00:00
|
|
|
let stickied_posts = ModStickyPostView::list(
|
|
|
|
&conn,
|
|
|
|
data.community_id,
|
|
|
|
data.mod_user_id,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
2019-09-07 15:35:05 +00:00
|
|
|
let removed_comments = ModRemoveCommentView::list(
|
|
|
|
&conn,
|
|
|
|
data.community_id,
|
|
|
|
data.mod_user_id,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
|
|
|
let banned_from_community = ModBanFromCommunityView::list(
|
|
|
|
&conn,
|
|
|
|
data.community_id,
|
|
|
|
data.mod_user_id,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
|
|
|
let added_to_community = ModAddCommunityView::list(
|
|
|
|
&conn,
|
|
|
|
data.community_id,
|
|
|
|
data.mod_user_id,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
2019-05-05 05:20:38 +00:00
|
|
|
|
|
|
|
// These arrays are only for the full modlog, when a community isn't given
|
|
|
|
let mut removed_communities = Vec::new();
|
|
|
|
let mut banned = Vec::new();
|
|
|
|
let mut added = Vec::new();
|
|
|
|
|
|
|
|
if data.community_id.is_none() {
|
2019-09-07 15:35:05 +00:00
|
|
|
removed_communities =
|
|
|
|
ModRemoveCommunityView::list(&conn, data.mod_user_id, data.page, data.limit)?;
|
2019-05-05 05:20:38 +00:00
|
|
|
banned = ModBanView::list(&conn, data.mod_user_id, data.page, data.limit)?;
|
|
|
|
added = ModAddView::list(&conn, data.mod_user_id, data.page, data.limit)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the jwt
|
2019-09-07 15:35:05 +00:00
|
|
|
Ok(GetModlogResponse {
|
|
|
|
op: self.op.to_string(),
|
|
|
|
removed_posts: removed_posts,
|
|
|
|
locked_posts: locked_posts,
|
2019-09-09 06:14:13 +00:00
|
|
|
stickied_posts: stickied_posts,
|
2019-09-07 15:35:05 +00:00
|
|
|
removed_comments: removed_comments,
|
|
|
|
removed_communities: removed_communities,
|
|
|
|
banned_from_community: banned_from_community,
|
|
|
|
banned: banned,
|
|
|
|
added_to_community: added_to_community,
|
|
|
|
added: added,
|
|
|
|
})
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Perform<SiteResponse> for Oper<CreateSite> {
|
|
|
|
fn perform(&self) -> Result<SiteResponse, Error> {
|
2019-05-05 16:20:30 +00:00
|
|
|
let data: &CreateSite = &self.data;
|
2019-05-05 05:20:38 +00:00
|
|
|
let conn = establish_connection();
|
|
|
|
|
|
|
|
let claims = match Claims::decode(&data.auth) {
|
|
|
|
Ok(claims) => claims.claims,
|
2019-09-07 15:35:05 +00:00
|
|
|
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
2019-05-05 05:20:38 +00:00
|
|
|
};
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
if has_slurs(&data.name)
|
|
|
|
|| (data.description.is_some() && has_slurs(&data.description.to_owned().unwrap()))
|
|
|
|
{
|
|
|
|
return Err(APIError::err(&self.op, "no_slurs"))?;
|
|
|
|
}
|
2019-05-05 05:20:38 +00:00
|
|
|
|
|
|
|
let user_id = claims.id;
|
|
|
|
|
|
|
|
// Make sure user is an admin
|
|
|
|
if !UserView::read(&conn, user_id)?.admin {
|
2019-09-07 15:35:05 +00:00
|
|
|
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let site_form = SiteForm {
|
|
|
|
name: data.name.to_owned(),
|
|
|
|
description: data.description.to_owned(),
|
|
|
|
creator_id: user_id,
|
|
|
|
updated: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
match Site::create(&conn, &site_form) {
|
|
|
|
Ok(site) => site,
|
2019-09-07 15:35:05 +00:00
|
|
|
Err(_e) => return Err(APIError::err(&self.op, "site_already_exists"))?,
|
2019-05-05 05:20:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let site_view = SiteView::read(&conn)?;
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
Ok(SiteResponse {
|
|
|
|
op: self.op.to_string(),
|
|
|
|
site: site_view,
|
|
|
|
})
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Perform<SiteResponse> for Oper<EditSite> {
|
|
|
|
fn perform(&self) -> Result<SiteResponse, Error> {
|
2019-05-05 16:20:30 +00:00
|
|
|
let data: &EditSite = &self.data;
|
2019-05-05 05:20:38 +00:00
|
|
|
let conn = establish_connection();
|
|
|
|
|
|
|
|
let claims = match Claims::decode(&data.auth) {
|
|
|
|
Ok(claims) => claims.claims,
|
2019-09-07 15:35:05 +00:00
|
|
|
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
2019-05-05 05:20:38 +00:00
|
|
|
};
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
if has_slurs(&data.name)
|
|
|
|
|| (data.description.is_some() && has_slurs(&data.description.to_owned().unwrap()))
|
|
|
|
{
|
|
|
|
return Err(APIError::err(&self.op, "no_slurs"))?;
|
|
|
|
}
|
2019-05-05 05:20:38 +00:00
|
|
|
|
|
|
|
let user_id = claims.id;
|
|
|
|
|
|
|
|
// Make sure user is an admin
|
|
|
|
if UserView::read(&conn, user_id)?.admin == false {
|
2019-09-07 15:35:05 +00:00
|
|
|
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let found_site = Site::read(&conn, 1)?;
|
|
|
|
|
|
|
|
let site_form = SiteForm {
|
|
|
|
name: data.name.to_owned(),
|
|
|
|
description: data.description.to_owned(),
|
|
|
|
creator_id: found_site.creator_id,
|
|
|
|
updated: Some(naive_now()),
|
|
|
|
};
|
|
|
|
|
|
|
|
match Site::update(&conn, 1, &site_form) {
|
|
|
|
Ok(site) => site,
|
2019-09-07 15:35:05 +00:00
|
|
|
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_site"))?,
|
2019-05-05 05:20:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let site_view = SiteView::read(&conn)?;
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
Ok(SiteResponse {
|
|
|
|
op: self.op.to_string(),
|
|
|
|
site: site_view,
|
|
|
|
})
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Perform<GetSiteResponse> for Oper<GetSite> {
|
|
|
|
fn perform(&self) -> Result<GetSiteResponse, Error> {
|
2019-05-05 16:20:30 +00:00
|
|
|
let _data: &GetSite = &self.data;
|
2019-05-05 05:20:38 +00:00
|
|
|
let conn = establish_connection();
|
|
|
|
|
|
|
|
// It can return a null site in order to redirect
|
|
|
|
let site_view = match Site::read(&conn, 1) {
|
|
|
|
Ok(_site) => Some(SiteView::read(&conn)?),
|
2019-09-07 15:35:05 +00:00
|
|
|
Err(_e) => None,
|
2019-05-05 05:20:38 +00:00
|
|
|
};
|
|
|
|
|
2019-08-24 02:40:41 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-05-05 05:20:38 +00:00
|
|
|
let banned = UserView::banned(&conn)?;
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
Ok(GetSiteResponse {
|
|
|
|
op: self.op.to_string(),
|
|
|
|
site: site_view,
|
|
|
|
admins: admins,
|
|
|
|
banned: banned,
|
|
|
|
})
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Perform<SearchResponse> for Oper<Search> {
|
|
|
|
fn perform(&self) -> Result<SearchResponse, Error> {
|
2019-05-05 16:20:30 +00:00
|
|
|
let data: &Search = &self.data;
|
2019-05-05 05:20:38 +00:00
|
|
|
let conn = establish_connection();
|
|
|
|
|
|
|
|
let sort = SortType::from_str(&data.sort)?;
|
|
|
|
let type_ = SearchType::from_str(&data.type_)?;
|
|
|
|
|
|
|
|
let mut posts = Vec::new();
|
|
|
|
let mut comments = Vec::new();
|
2019-08-10 17:32:06 +00:00
|
|
|
let mut communities = Vec::new();
|
|
|
|
let mut users = Vec::new();
|
2019-05-05 05:20:38 +00:00
|
|
|
|
2019-08-14 02:52:43 +00:00
|
|
|
// TODO no clean / non-nsfw searching rn
|
|
|
|
|
2019-05-05 05:20:38 +00:00
|
|
|
match type_ {
|
|
|
|
SearchType::Posts => {
|
2019-08-10 17:32:06 +00:00
|
|
|
posts = PostView::list(
|
2019-09-07 15:35:05 +00:00
|
|
|
&conn,
|
|
|
|
PostListingType::All,
|
|
|
|
&sort,
|
|
|
|
data.community_id,
|
2019-08-10 17:32:06 +00:00
|
|
|
None,
|
|
|
|
Some(data.q.to_owned()),
|
2019-08-22 05:17:15 +00:00
|
|
|
None,
|
2019-09-07 15:35:05 +00:00
|
|
|
None,
|
2019-08-14 02:52:43 +00:00
|
|
|
true,
|
2019-09-07 15:35:05 +00:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
|
|
|
}
|
2019-05-05 05:20:38 +00:00
|
|
|
SearchType::Comments => {
|
2019-08-10 17:32:06 +00:00
|
|
|
comments = CommentView::list(
|
2019-09-07 15:35:05 +00:00
|
|
|
&conn,
|
|
|
|
&sort,
|
|
|
|
None,
|
|
|
|
None,
|
2019-08-10 17:32:06 +00:00
|
|
|
Some(data.q.to_owned()),
|
|
|
|
None,
|
2019-09-07 15:35:05 +00:00
|
|
|
false,
|
2019-08-10 17:32:06 +00:00
|
|
|
data.page,
|
2019-09-07 15:35:05 +00:00
|
|
|
data.limit,
|
|
|
|
)?;
|
|
|
|
}
|
2019-08-10 17:32:06 +00:00
|
|
|
SearchType::Communities => {
|
|
|
|
communities = CommunityView::list(
|
2019-09-07 15:35:05 +00:00
|
|
|
&conn,
|
|
|
|
&sort,
|
|
|
|
None,
|
2019-08-14 02:52:43 +00:00
|
|
|
true,
|
2019-08-10 17:32:06 +00:00
|
|
|
Some(data.q.to_owned()),
|
2019-09-07 15:35:05 +00:00
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
|
|
|
}
|
2019-08-10 17:32:06 +00:00
|
|
|
SearchType::Users => {
|
2019-09-07 15:35:05 +00:00
|
|
|
users = UserView::list(&conn, &sort, Some(data.q.to_owned()), data.page, data.limit)?;
|
|
|
|
}
|
2019-08-10 17:32:06 +00:00
|
|
|
SearchType::All => {
|
|
|
|
posts = PostView::list(
|
2019-09-07 15:35:05 +00:00
|
|
|
&conn,
|
|
|
|
PostListingType::All,
|
|
|
|
&sort,
|
|
|
|
data.community_id,
|
2019-08-10 17:32:06 +00:00
|
|
|
None,
|
|
|
|
Some(data.q.to_owned()),
|
2019-08-22 05:17:15 +00:00
|
|
|
None,
|
2019-09-07 15:35:05 +00:00
|
|
|
None,
|
2019-08-14 02:52:43 +00:00
|
|
|
true,
|
2019-09-07 15:35:05 +00:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
2019-08-10 17:32:06 +00:00
|
|
|
comments = CommentView::list(
|
2019-09-07 15:35:05 +00:00
|
|
|
&conn,
|
|
|
|
&sort,
|
|
|
|
None,
|
|
|
|
None,
|
2019-08-10 17:32:06 +00:00
|
|
|
Some(data.q.to_owned()),
|
|
|
|
None,
|
2019-09-07 15:35:05 +00:00
|
|
|
false,
|
2019-08-10 17:32:06 +00:00
|
|
|
data.page,
|
2019-09-07 15:35:05 +00:00
|
|
|
data.limit,
|
|
|
|
)?;
|
2019-08-10 17:32:06 +00:00
|
|
|
communities = CommunityView::list(
|
2019-09-07 15:35:05 +00:00
|
|
|
&conn,
|
|
|
|
&sort,
|
|
|
|
None,
|
2019-08-14 02:52:43 +00:00
|
|
|
true,
|
2019-08-10 17:32:06 +00:00
|
|
|
Some(data.q.to_owned()),
|
2019-09-07 15:35:05 +00:00
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
|
|
|
users = UserView::list(&conn, &sort, Some(data.q.to_owned()), data.page, data.limit)?;
|
|
|
|
}
|
2019-08-22 05:17:15 +00:00
|
|
|
SearchType::Url => {
|
|
|
|
posts = PostView::list(
|
2019-09-07 15:35:05 +00:00
|
|
|
&conn,
|
|
|
|
PostListingType::All,
|
|
|
|
&sort,
|
|
|
|
data.community_id,
|
2019-08-22 05:17:15 +00:00
|
|
|
None,
|
|
|
|
None,
|
|
|
|
Some(data.q.to_owned()),
|
2019-09-07 15:35:05 +00:00
|
|
|
None,
|
2019-08-22 05:17:15 +00:00
|
|
|
true,
|
2019-09-07 15:35:05 +00:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
data.page,
|
|
|
|
data.limit,
|
|
|
|
)?;
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return the jwt
|
2019-09-07 15:35:05 +00:00
|
|
|
Ok(SearchResponse {
|
|
|
|
op: self.op.to_string(),
|
|
|
|
type_: data.type_.to_owned(),
|
|
|
|
comments: comments,
|
|
|
|
posts: posts,
|
|
|
|
communities: communities,
|
|
|
|
users: users,
|
|
|
|
})
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-24 02:40:41 +00:00
|
|
|
|
|
|
|
impl Perform<GetSiteResponse> for Oper<TransferSite> {
|
|
|
|
fn perform(&self) -> Result<GetSiteResponse, Error> {
|
|
|
|
let data: &TransferSite = &self.data;
|
|
|
|
let conn = establish_connection();
|
|
|
|
|
|
|
|
let claims = match Claims::decode(&data.auth) {
|
|
|
|
Ok(claims) => claims.claims,
|
2019-09-07 15:35:05 +00:00
|
|
|
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
2019-08-24 02:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let user_id = claims.id;
|
|
|
|
|
|
|
|
let read_site = Site::read(&conn, 1)?;
|
|
|
|
|
|
|
|
// Make sure user is the creator
|
|
|
|
if read_site.creator_id != user_id {
|
2019-09-07 15:35:05 +00:00
|
|
|
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let site_form = SiteForm {
|
|
|
|
name: read_site.name,
|
|
|
|
description: read_site.description,
|
|
|
|
creator_id: data.user_id,
|
|
|
|
updated: Some(naive_now()),
|
|
|
|
};
|
|
|
|
|
|
|
|
match Site::update(&conn, 1, &site_form) {
|
|
|
|
Ok(site) => site,
|
2019-09-07 15:35:05 +00:00
|
|
|
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_site"))?,
|
2019-08-24 02:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Mod tables
|
|
|
|
let form = ModAddForm {
|
|
|
|
mod_user_id: user_id,
|
|
|
|
other_user_id: data.user_id,
|
|
|
|
removed: Some(false),
|
|
|
|
};
|
|
|
|
|
|
|
|
ModAdd::create(&conn, &form)?;
|
|
|
|
|
|
|
|
let site_view = SiteView::read(&conn)?;
|
|
|
|
|
|
|
|
let mut admins = UserView::admins(&conn)?;
|
2019-09-07 15:35:05 +00:00
|
|
|
let creator_index = admins
|
|
|
|
.iter()
|
|
|
|
.position(|r| r.id == site_view.creator_id)
|
|
|
|
.unwrap();
|
2019-08-24 02:40:41 +00:00
|
|
|
let creator_user = admins.remove(creator_index);
|
|
|
|
admins.insert(0, creator_user);
|
|
|
|
|
|
|
|
let banned = UserView::banned(&conn)?;
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
Ok(GetSiteResponse {
|
|
|
|
op: self.op.to_string(),
|
|
|
|
site: Some(site_view),
|
|
|
|
admins: admins,
|
|
|
|
banned: banned,
|
|
|
|
})
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
|
|
|
}
|