mirror of https://github.com/LemmyNet/lemmy
Remove enable nsfw (#5017)
* Remove `local_site.enable_nsfw` in favor of `site.content_warning` (fixes #4627) * cleanup usage of SiteView::read_local * test * uppercasepull/4987/head^2
parent
5febf2b8fb
commit
6454a4d43d
@ -1,28 +1,32 @@
|
||||
use crate::structs::SiteView;
|
||||
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, OptionalExtension, QueryDsl};
|
||||
use diesel::{ExpressionMethods, JoinOnDsl, OptionalExtension, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_db_schema::{
|
||||
schema::{local_site, local_site_rate_limit, site, site_aggregates},
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
||||
|
||||
impl SiteView {
|
||||
pub async fn read_local(pool: &mut DbPool<'_>) -> Result<Option<Self>, Error> {
|
||||
pub async fn read_local(pool: &mut DbPool<'_>) -> LemmyResult<Self> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
site::table
|
||||
.inner_join(local_site::table)
|
||||
.inner_join(
|
||||
local_site_rate_limit::table.on(local_site::id.eq(local_site_rate_limit::local_site_id)),
|
||||
)
|
||||
.inner_join(site_aggregates::table)
|
||||
.select((
|
||||
site::all_columns,
|
||||
local_site::all_columns,
|
||||
local_site_rate_limit::all_columns,
|
||||
site_aggregates::all_columns,
|
||||
))
|
||||
.first(conn)
|
||||
.await
|
||||
.optional()
|
||||
Ok(
|
||||
site::table
|
||||
.inner_join(local_site::table)
|
||||
.inner_join(
|
||||
local_site_rate_limit::table.on(local_site::id.eq(local_site_rate_limit::local_site_id)),
|
||||
)
|
||||
.inner_join(site_aggregates::table)
|
||||
.select((
|
||||
site::all_columns,
|
||||
local_site::all_columns,
|
||||
local_site_rate_limit::all_columns,
|
||||
site_aggregates::all_columns,
|
||||
))
|
||||
.first(conn)
|
||||
.await
|
||||
.optional()?
|
||||
.ok_or(LemmyErrorType::LocalSiteNotSetup)?,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
ALTER TABLE local_site
|
||||
ADD COLUMN enable_nsfw boolean NOT NULL DEFAULT FALSE;
|
||||
|
||||
UPDATE
|
||||
local_site
|
||||
SET
|
||||
enable_nsfw = CASE WHEN site.content_warning IS NULL THEN
|
||||
FALSE
|
||||
ELSE
|
||||
TRUE
|
||||
END
|
||||
FROM
|
||||
site
|
||||
WHERE
|
||||
-- only local site has private key
|
||||
site.private_key IS NOT NULL;
|
||||
|
@ -0,0 +1,20 @@
|
||||
-- if site has enable_nsfw, set a default content warning
|
||||
UPDATE
|
||||
site
|
||||
SET
|
||||
content_warning = CASE WHEN local_site.enable_nsfw THEN
|
||||
'NSFW'
|
||||
ELSE
|
||||
NULL
|
||||
END
|
||||
FROM
|
||||
local_site
|
||||
-- only local site has private key
|
||||
WHERE
|
||||
private_key IS NOT NULL
|
||||
-- dont overwrite existing content warning
|
||||
AND content_warning IS NOT NULL;
|
||||
|
||||
ALTER TABLE local_site
|
||||
DROP enable_nsfw;
|
||||
|
Loading…
Reference in New Issue