Don't allow community name editing. Fixes #964

This commit is contained in:
Dessalines 2020-07-14 14:56:53 -04:00
parent 2c0928efe0
commit cd6f1c56e3
3 changed files with 21 additions and 30 deletions

View file

@ -979,7 +979,6 @@ Mods and admins can remove and lock a community, creators can delete it.
op: "EditCommunity", op: "EditCommunity",
data: { data: {
edit_id: i32, edit_id: i32,
name: String,
title: String, title: String,
description: Option<String>, description: Option<String>,
category_id: i32, category_id: i32,

View file

@ -98,7 +98,6 @@ pub struct AddModToCommunityResponse {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct EditCommunity { pub struct EditCommunity {
pub edit_id: i32, pub edit_id: i32,
name: String,
title: String, title: String,
description: Option<String>, description: Option<String>,
category_id: i32, category_id: i32,
@ -333,10 +332,6 @@ impl Perform for Oper<EditCommunity> {
) -> Result<CommunityResponse, LemmyError> { ) -> Result<CommunityResponse, LemmyError> {
let data: &EditCommunity = &self.data; let data: &EditCommunity = &self.data;
if let Err(slurs) = slur_check(&data.name) {
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
}
if let Err(slurs) = slur_check(&data.title) { if let Err(slurs) = slur_check(&data.title) {
return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
} }
@ -352,10 +347,6 @@ impl Perform for Oper<EditCommunity> {
Err(_e) => return Err(APIError::err("not_logged_in").into()), Err(_e) => return Err(APIError::err("not_logged_in").into()),
}; };
if !is_valid_community_name(&data.name) {
return Err(APIError::err("invalid_community_name").into());
}
let user_id = claims.id; let user_id = claims.id;
// Check for a site ban // Check for a site ban
@ -388,7 +379,7 @@ impl Perform for Oper<EditCommunity> {
let read_community = blocking(pool, move |conn| Community::read(conn, edit_id)).await??; let read_community = blocking(pool, move |conn| Community::read(conn, edit_id)).await??;
let community_form = CommunityForm { let community_form = CommunityForm {
name: data.name.to_owned(), name: read_community.name,
title: data.title.to_owned(), title: data.title.to_owned(),
description: data.description.to_owned(), description: data.description.to_owned(),
category_id: data.category_id.to_owned(), category_id: data.category_id.to_owned(),

View file

@ -128,26 +128,27 @@ export class CommunityForm extends Component<
message={i18n.t('block_leaving')} message={i18n.t('block_leaving')}
/> />
<form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}> <form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}>
<div class="form-group row"> {!this.props.community && (
<label class="col-12 col-form-label" htmlFor="community-name"> <div class="form-group row">
{i18n.t('name')} <label class="col-12 col-form-label" htmlFor="community-name">
</label> {i18n.t('name')}
<div class="col-12"> </label>
<input <div class="col-12">
type="text" <input
id="community-name" type="text"
class="form-control" id="community-name"
value={this.state.communityForm.name} class="form-control"
onInput={linkEvent(this, this.handleCommunityNameChange)} value={this.state.communityForm.name}
required onInput={linkEvent(this, this.handleCommunityNameChange)}
minLength={3} required
maxLength={20} minLength={3}
pattern="[a-z0-9_]+" maxLength={20}
title={i18n.t('community_reqs')} pattern="[a-z0-9_]+"
/> title={i18n.t('community_reqs')}
/>
</div>
</div> </div>
</div> )}
<div class="form-group row"> <div class="form-group row">
<label class="col-12 col-form-label" htmlFor="community-title"> <label class="col-12 col-form-label" htmlFor="community-title">
{i18n.t('title')} {i18n.t('title')}