Ok(())
}
}
+
+/// Checks the site description length
+pub fn site_description_length_check(description: &str) -> Result<(), LemmyError> {
+ if description.len() > 150 {
+ Err(ApiError::err("site_description_length_overflow").into())
+ } else {
+ Ok(())
+ }
+}
mod_sticky_post_view::ModStickyPostView,
};
use serde::{Deserialize, Serialize};
-use url::Url;
#[derive(Deserialize, Debug)]
pub struct Search {
#[derive(Deserialize)]
pub struct CreateSite {
pub name: String,
+ pub sidebar: Option<String>,
pub description: Option<String>,
- pub icon: Option<Url>,
- pub banner: Option<Url>,
+ pub icon: Option<String>,
+ pub banner: Option<String>,
pub enable_downvotes: bool,
pub open_registration: bool,
pub enable_nsfw: bool,
#[derive(Deserialize)]
pub struct EditSite {
pub name: String,
+ pub sidebar: Option<String>,
pub description: Option<String>,
pub icon: Option<String>,
pub banner: Option<String>,
use crate::PerformCrud;
use actix_web::web::Data;
-use lemmy_api_common::{blocking, get_local_user_view_from_jwt, is_admin, site::*};
-use lemmy_db_queries::{source::site::Site_, Crud};
+use lemmy_api_common::{
+ blocking,
+ get_local_user_view_from_jwt,
+ is_admin,
+ site::*,
+ site_description_length_check,
+};
+use lemmy_db_queries::{
+ diesel_option_overwrite,
+ diesel_option_overwrite_to_url,
+ source::site::Site_,
+ Crud,
+};
use lemmy_db_schema::source::site::{Site, *};
use lemmy_db_views::site_view::SiteView;
use lemmy_utils::{
// Make sure user is an admin
is_admin(&local_user_view)?;
+ let sidebar = diesel_option_overwrite(&data.sidebar);
+ let description = diesel_option_overwrite(&data.description);
+ let icon = diesel_option_overwrite_to_url(&data.icon)?;
+ let banner = diesel_option_overwrite_to_url(&data.banner)?;
+
+ if let Some(Some(desc)) = &description {
+ site_description_length_check(desc)?;
+ }
+
let site_form = SiteForm {
name: data.name.to_owned(),
- description: data.description.to_owned(),
- icon: Some(data.icon.to_owned().map(|url| url.into())),
- banner: Some(data.banner.to_owned().map(|url| url.into())),
+ sidebar,
+ description,
+ icon,
+ banner,
creator_id: local_user_view.person.id,
enable_downvotes: data.enable_downvotes,
open_registration: data.open_registration,
let create_site = CreateSite {
name: setup.site_name.to_owned(),
+ sidebar: None,
description: None,
icon: None,
banner: None,
get_local_user_view_from_jwt,
is_admin,
site::{EditSite, SiteResponse},
+ site_description_length_check,
+};
+use lemmy_db_queries::{
+ diesel_option_overwrite,
+ diesel_option_overwrite_to_url,
+ source::site::Site_,
+ Crud,
};
-use lemmy_db_queries::{diesel_option_overwrite_to_url, source::site::Site_, Crud};
use lemmy_db_schema::{
naive_now,
source::site::{Site, SiteForm},
let found_site = blocking(context.pool(), move |conn| Site::read_simple(conn)).await??;
+ let sidebar = diesel_option_overwrite(&data.sidebar);
+ let description = diesel_option_overwrite(&data.description);
let icon = diesel_option_overwrite_to_url(&data.icon)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?;
+ if let Some(Some(desc)) = &description {
+ site_description_length_check(desc)?;
+ }
+
let site_form = SiteForm {
name: data.name.to_owned(),
- description: data.description.to_owned(),
+ sidebar,
+ description,
icon,
banner,
creator_id: found_site.creator_id,
let site_form = SiteForm {
name: "test_site".into(),
+ sidebar: None,
description: None,
icon: None,
banner: None,
site (id) {
id -> Int4,
name -> Varchar,
- description -> Nullable<Text>,
+ sidebar -> Nullable<Text>,
creator_id -> Int4,
published -> Timestamp,
updated -> Nullable<Timestamp>,
enable_nsfw -> Bool,
icon -> Nullable<Varchar>,
banner -> Nullable<Varchar>,
+ description -> Nullable<Text>,
}
}
pub struct Site {
pub id: i32,
pub name: String,
- pub description: Option<String>,
+ pub sidebar: Option<String>,
pub creator_id: PersonId,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub enable_nsfw: bool,
pub icon: Option<DbUrl>,
pub banner: Option<DbUrl>,
+ pub description: Option<String>,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "site"]
pub struct SiteForm {
pub name: String,
- pub description: Option<String>,
+ pub sidebar: Option<Option<String>>,
pub creator_id: PersonId,
pub updated: Option<chrono::NaiveDateTime>,
pub enable_downvotes: bool,
// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
pub icon: Option<Option<DbUrl>>,
pub banner: Option<Option<DbUrl>>,
+ pub description: Option<Option<String>>,
}
--- /dev/null
+alter table site drop column description;
+alter table site rename column sidebar to description;
--- /dev/null
+-- Renaming description to sidebar
+alter table site rename column description to sidebar;
+
+-- Adding a short description column
+alter table site add column description varchar(150);