Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom emoji and tagline views #4580

Merged
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fd27523
Add custom_emoji list route
Mar 31, 2024
b4a8615
Add tagline list route
Mar 31, 2024
10a8f01
Apply linting
Mar 31, 2024
17e2834
Remove unecessary TaglineView
Apr 2, 2024
486c746
Add category filter for custom emoji
Apr 2, 2024
a1a7e2c
Add create tagline endpoint
Apr 3, 2024
ab93806
Add update tagline endpoint
Apr 3, 2024
e536d39
Add delete tagline endpoint
Apr 3, 2024
5358908
Format through lint.sh
Apr 3, 2024
2b1fdf1
Remove custom_emojis and taglines from site resource
Apr 4, 2024
f1b993f
Get random tagline on site requets
Apr 4, 2024
144c112
Impl Crud for Tagline
Apr 5, 2024
5342a22
Move tagline endpoints under /admin
Apr 5, 2024
bab417a
Impl Crud for CustomEmoji
Apr 5, 2024
ead5151
Remove delete from tagline and custom emoji impls
Apr 5, 2024
abdfc90
Check markdown for tagline
Apr 5, 2024
b2b8c43
Validate markdown on tagline
Apr 5, 2024
55be9a1
Merge branch 'main' into feature/custom-emoji-and-tagline-views
SleeplessOne1917 Apr 6, 2024
7759602
Make content fields non optional
Apr 6, 2024
6ffcc1f
Use process_markdown instead of process_markdown_opt
Apr 6, 2024
5cf15a4
Merge branch 'main' into feature/custom-emoji-and-tagline-views
SleeplessOne1917 Apr 8, 2024
7ce89fb
Consolidate Tagline error types
fvanzee Apr 8, 2024
8c7b300
Remove unecessary clone
fvanzee Apr 8, 2024
562c909
Updat misleading comments
fvanzee Apr 8, 2024
6935acb
Remove local_site_id from tagline and custom_emoji
fvanzee Apr 8, 2024
999e984
Update TaglineInserForm and TaglineUpdateForm
fvanzee Apr 11, 2024
1f629cc
Add ignore_page_limits for custom emojis
fvanzee Apr 14, 2024
4771085
Update custom_emoji_view
fvanzee Apr 16, 2024
920adcc
Merge branch 'main' into feature/custom-emoji-and-tagline-views
fvanzee Apr 16, 2024
e96d0be
Merge remote-tracking branch 'origin/main' into custom_emoji_dess
dessalines Sep 16, 2024
004b1b2
Removing pointless get_all fn.
dessalines Sep 16, 2024
e09e54e
remove tagline length checks
Nutomic Sep 18, 2024
215ebf7
make fields of TaglineInsertForm and TaglineUpdateForm mandatory
Nutomic Sep 18, 2024
2de4503
move emoji order statement
Nutomic Sep 18, 2024
18a4cf9
add comment for GetSiteResponse.tagline
Nutomic Sep 18, 2024
e4e18fe
Merge remote-tracking branch 'origin/main' into custom_emoji_dess
dessalines Sep 18, 2024
8076dd8
Adding a default_comment_sort_type column for local_site and local_us…
dessalines Sep 19, 2024
afe5ff6
Simplify tests using default (#5026)
Nutomic Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions crates/api/src/site/leave_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use lemmy_db_schema::{
},
traits::Crud,
};
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView};
use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::{
error::{LemmyErrorType, LemmyResult},
Expand Down Expand Up @@ -60,10 +60,8 @@ pub async fn leave_admin(

let all_languages = Language::read_all(&mut context.pool()).await?;
let discussion_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
let taglines = Tagline::get_all(&mut context.pool(), site_view.local_site.id).await?;
let custom_emojis =
CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
let blocked_urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
let tagline = Tagline::get_random(&mut context.pool()).await?;

Ok(Json(GetSiteResponse {
site_view,
Expand All @@ -72,8 +70,7 @@ pub async fn leave_admin(
my_user: None,
all_languages,
discussion_languages,
taglines,
custom_emojis,
blocked_urls,
tagline,
}))
}
21 changes: 21 additions & 0 deletions crates/api_common/src/custom_emoji.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use lemmy_db_schema::newtypes::CustomEmojiId;
use lemmy_db_views::structs::CustomEmojiView;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
use url::Url;
Expand Down Expand Up @@ -46,3 +47,23 @@ pub struct DeleteCustomEmoji {
pub struct CustomEmojiResponse {
pub custom_emoji: CustomEmojiView,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A response for custom emojis.
pub struct ListCustomEmojisResponse {
pub custom_emojis: Vec<CustomEmojiView>,
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Fetches a list of custom emojis.
pub struct ListCustomEmojis {
pub page: Option<i64>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makotech222 look into your emoji library, because these may need a search term, optional category, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a category search parameter. This column is also already indexed

pub limit: Option<i64>,
pub category: Option<String>,
pub ignore_page_limits: Option<bool>,
}
1 change: 1 addition & 0 deletions crates/api_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod request;
#[cfg(feature = "full")]
pub mod send_activity;
pub mod site;
pub mod tagline;
#[cfg(feature = "full")]
pub mod utils;

Expand Down
10 changes: 1 addition & 9 deletions crates/api_common/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use lemmy_db_schema::{
};
use lemmy_db_views::structs::{
CommentView,
CustomEmojiView,
LocalUserView,
PostView,
RegistrationApplicationView,
Expand Down Expand Up @@ -198,7 +197,6 @@ pub struct CreateSite {
pub captcha_difficulty: Option<String>,
pub allowed_instances: Option<Vec<String>>,
pub blocked_instances: Option<Vec<String>>,
pub taglines: Option<Vec<String>>,
pub registration_mode: Option<RegistrationMode>,
pub content_warning: Option<String>,
pub default_post_listing_mode: Option<PostListingMode>,
Expand Down Expand Up @@ -279,8 +277,6 @@ pub struct EditSite {
pub blocked_instances: Option<Vec<String>>,
/// A list of blocked URLs
pub blocked_urls: Option<Vec<String>>,
/// A list of taglines shown at the top of the front page.
pub taglines: Option<Vec<String>>,
pub registration_mode: Option<RegistrationMode>,
/// Whether to email admins for new reports.
pub reports_email_admins: Option<bool>,
Expand All @@ -297,7 +293,6 @@ pub struct EditSite {
/// The response for a site.
pub struct SiteResponse {
pub site_view: SiteView,
pub taglines: Vec<Tagline>,
}

#[skip_serializing_none]
Expand All @@ -312,10 +307,7 @@ pub struct GetSiteResponse {
pub my_user: Option<MyUserInfo>,
pub all_languages: Vec<Language>,
pub discussion_languages: Vec<LanguageId>,
/// A list of taglines shown at the top of the front page.
pub taglines: Vec<Tagline>,
/// A list of custom emojis your site supports.
pub custom_emojis: Vec<CustomEmojiView>,
pub tagline: Option<Tagline>,
pub blocked_urls: Vec<LocalSiteUrlBlocklist>,
}

Expand Down
55 changes: 55 additions & 0 deletions crates/api_common/src/tagline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use lemmy_db_schema::{newtypes::TaglineId, source::tagline::Tagline};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Create a tagline
pub struct CreateTagline {
pub content: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Update a tagline
pub struct UpdateTagline {
pub id: TaglineId,
pub content: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Delete a tagline
pub struct DeleteTagline {
pub id: TaglineId,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
pub struct TaglineResponse {
pub tagline: Tagline,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A response for taglines.
pub struct ListTaglinesResponse {
pub taglines: Vec<Tagline>,
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Fetches a list of taglines.
pub struct ListTaglines {
pub page: Option<i64>,
pub limit: Option<i64>,
}
12 changes: 6 additions & 6 deletions crates/api_crud/src/custom_emoji/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use lemmy_api_common::{
custom_emoji::{CreateCustomEmoji, CustomEmojiResponse},
utils::is_admin,
};
use lemmy_db_schema::source::{
custom_emoji::{CustomEmoji, CustomEmojiInsertForm},
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
local_site::LocalSite,
use lemmy_db_schema::{
source::{
custom_emoji::{CustomEmoji, CustomEmojiInsertForm},
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
},
traits::Crud,
};
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView};
use lemmy_utils::error::LemmyResult;
Expand All @@ -19,12 +21,10 @@ pub async fn create_custom_emoji(
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<CustomEmojiResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;

let emoji_form = CustomEmojiInsertForm::builder()
.local_site_id(local_site.id)
.shortcode(data.shortcode.to_lowercase().trim().to_string())
.alt_text(data.alt_text.to_string())
.category(data.category.to_string())
Expand Down
2 changes: 1 addition & 1 deletion crates/api_crud/src/custom_emoji/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use lemmy_api_common::{
utils::is_admin,
SuccessResponse,
};
use lemmy_db_schema::source::custom_emoji::CustomEmoji;
use lemmy_db_schema::{source::custom_emoji::CustomEmoji, traits::Crud};
use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyResult;

Expand Down
25 changes: 25 additions & 0 deletions crates/api_crud/src/custom_emoji/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use actix_web::web::{Data, Json, Query};
use lemmy_api_common::{
context::LemmyContext,
custom_emoji::{ListCustomEmojis, ListCustomEmojisResponse},
};
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView};
use lemmy_utils::error::LemmyError;

#[tracing::instrument(skip(context))]
pub async fn list_custom_emojis(
data: Query<ListCustomEmojis>,
local_user_view: Option<LocalUserView>,
context: Data<LemmyContext>,
) -> Result<Json<ListCustomEmojisResponse>, LemmyError> {
let custom_emojis = CustomEmojiView::list(
&mut context.pool(),
&data.category,
data.page,
data.limit,
data.ignore_page_limits.unwrap_or(false),
)
.await?;

Ok(Json(ListCustomEmojisResponse { custom_emojis }))
}
1 change: 1 addition & 0 deletions crates/api_crud/src/custom_emoji/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod create;
pub mod delete;
pub mod list;
pub mod update;
12 changes: 6 additions & 6 deletions crates/api_crud/src/custom_emoji/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use lemmy_api_common::{
custom_emoji::{CustomEmojiResponse, EditCustomEmoji},
utils::is_admin,
};
use lemmy_db_schema::source::{
custom_emoji::{CustomEmoji, CustomEmojiUpdateForm},
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
local_site::LocalSite,
use lemmy_db_schema::{
source::{
custom_emoji::{CustomEmoji, CustomEmojiUpdateForm},
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
},
traits::Crud,
};
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView};
use lemmy_utils::error::LemmyResult;
Expand All @@ -19,12 +21,10 @@ pub async fn update_custom_emoji(
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<CustomEmojiResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;

let emoji_form = CustomEmojiUpdateForm::builder()
.local_site_id(local_site.id)
.alt_text(data.alt_text.to_string())
.category(data.category.to_string())
.image_url(data.clone().image_url.into())
Expand Down
1 change: 1 addition & 0 deletions crates/api_crud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub mod custom_emoji;
pub mod post;
pub mod private_message;
pub mod site;
pub mod tagline;
pub mod user;
10 changes: 1 addition & 9 deletions crates/api_crud/src/site/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use lemmy_db_schema::{
local_site::{LocalSite, LocalSiteUpdateForm},
local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm},
site::{Site, SiteUpdateForm},
tagline::Tagline,
},
traits::Crud,
utils::{diesel_string_update, diesel_url_create, naive_now},
Expand Down Expand Up @@ -134,17 +133,11 @@ pub async fn create_site(

let site_view = SiteView::read_local(&mut context.pool()).await?;

let new_taglines = data.taglines.clone();
let taglines = Tagline::replace(&mut context.pool(), local_site.id, new_taglines).await?;

let rate_limit_config =
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
context.rate_limit_cell().set_config(rate_limit_config);

Ok(Json(SiteResponse {
site_view,
taglines,
}))
Ok(Json(SiteResponse { site_view }))
}

fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) -> LemmyResult<()> {
Expand Down Expand Up @@ -589,7 +582,6 @@ mod tests {
captcha_difficulty: None,
allowed_instances: None,
blocked_instances: None,
taglines: None,
registration_mode: site_registration_mode,
content_warning: None,
default_post_listing_mode: None,
Expand Down
9 changes: 3 additions & 6 deletions crates/api_crud/src/site/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use lemmy_db_schema::source::{
person_block::PersonBlock,
tagline::Tagline,
};
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView};
use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_db_views_actor::structs::{CommunityFollowerView, CommunityModeratorView, PersonView};
use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
Expand Down Expand Up @@ -41,20 +41,17 @@ pub async fn get_site(
let admins = PersonView::admins(&mut context.pool()).await?;
let all_languages = Language::read_all(&mut context.pool()).await?;
let discussion_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
let taglines = Tagline::get_all(&mut context.pool(), site_view.local_site.id).await?;
let custom_emojis =
CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
let blocked_urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
let tagline = Tagline::get_random(&mut context.pool()).await?;
Ok(GetSiteResponse {
site_view,
admins,
version: VERSION.to_string(),
my_user: None,
all_languages,
discussion_languages,
taglines,
custom_emojis,
blocked_urls,
tagline,
})
})
.await
Expand Down
10 changes: 1 addition & 9 deletions crates/api_crud/src/site/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use lemmy_db_schema::{
local_site_url_blocklist::LocalSiteUrlBlocklist,
local_user::LocalUser,
site::{Site, SiteUpdateForm},
tagline::Tagline,
},
traits::Crud,
utils::{diesel_string_update, diesel_url_update, naive_now},
Expand Down Expand Up @@ -185,19 +184,13 @@ pub async fn update_site(
.with_lemmy_type(LemmyErrorType::CouldntSetAllEmailVerified)?;
}

let new_taglines = data.taglines.clone();
let taglines = Tagline::replace(&mut context.pool(), local_site.id, new_taglines).await?;

let site_view = SiteView::read_local(&mut context.pool()).await?;

let rate_limit_config =
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
context.rate_limit_cell().set_config(rate_limit_config);

Ok(Json(SiteResponse {
site_view,
taglines,
}))
Ok(Json(SiteResponse { site_view }))
}

fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> LemmyResult<()> {
Expand Down Expand Up @@ -602,7 +595,6 @@ mod tests {
allowed_instances: None,
blocked_instances: None,
blocked_urls: None,
taglines: None,
registration_mode: site_registration_mode,
reports_email_admins: None,
content_warning: None,
Expand Down
Loading