mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-17 09:25:50 +00:00
* Adding a short site description. Fixes #1496 - Renaming old description to sidebar * Adding a back end site desc length check.
This commit is contained in:
parent
5fff927dc4
commit
7bd474a843
@ -418,3 +418,12 @@ pub fn password_length_check(pass: &str) -> Result<(), LemmyError> {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ use lemmy_db_views_moderator::{
|
||||
mod_sticky_post_view::ModStickyPostView,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Search {
|
||||
@ -65,9 +64,10 @@ pub struct GetModlogResponse {
|
||||
#[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,
|
||||
@ -77,6 +77,7 @@ pub struct CreateSite {
|
||||
#[derive(Deserialize)]
|
||||
pub struct EditSite {
|
||||
pub name: String,
|
||||
pub sidebar: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub icon: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
|
@ -1,7 +1,18 @@
|
||||
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::{
|
||||
@ -36,11 +47,21 @@ impl PerformCrud for CreateSite {
|
||||
// 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,
|
||||
|
@ -43,6 +43,7 @@ impl PerformCrud for GetSite {
|
||||
|
||||
let create_site = CreateSite {
|
||||
name: setup.site_name.to_owned(),
|
||||
sidebar: None,
|
||||
description: None,
|
||||
icon: None,
|
||||
banner: None,
|
||||
|
@ -5,8 +5,14 @@ use lemmy_api_common::{
|
||||
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},
|
||||
@ -39,12 +45,19 @@ impl PerformCrud for EditSite {
|
||||
|
||||
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,
|
||||
|
@ -49,6 +49,7 @@ mod tests {
|
||||
|
||||
let site_form = SiteForm {
|
||||
name: "test_site".into(),
|
||||
sidebar: None,
|
||||
description: None,
|
||||
icon: None,
|
||||
banner: None,
|
||||
|
@ -422,7 +422,7 @@ table! {
|
||||
site (id) {
|
||||
id -> Int4,
|
||||
name -> Varchar,
|
||||
description -> Nullable<Text>,
|
||||
sidebar -> Nullable<Text>,
|
||||
creator_id -> Int4,
|
||||
published -> Timestamp,
|
||||
updated -> Nullable<Timestamp>,
|
||||
@ -431,6 +431,7 @@ table! {
|
||||
enable_nsfw -> Bool,
|
||||
icon -> Nullable<Varchar>,
|
||||
banner -> Nullable<Varchar>,
|
||||
description -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use serde::Serialize;
|
||||
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>,
|
||||
@ -15,13 +15,14 @@ pub struct Site {
|
||||
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,
|
||||
@ -30,4 +31,5 @@ pub struct SiteForm {
|
||||
// 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>>,
|
||||
}
|
||||
|
@ -0,0 +1,2 @@
|
||||
alter table site drop column description;
|
||||
alter table site rename column sidebar to description;
|
@ -0,0 +1,5 @@
|
||||
-- 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);
|
Loading…
Reference in New Issue
Block a user