]> Untitled Git - lemmy.git/commitdiff
Don't allow community name editing. Fixes #964 (#973)
authorDessalines <dessalines@users.noreply.github.com>
Wed, 15 Jul 2020 13:53:52 +0000 (09:53 -0400)
committerGitHub <noreply@github.com>
Wed, 15 Jul 2020 13:53:52 +0000 (09:53 -0400)
docs/src/contributing_websocket_http_api.md
server/src/api/community.rs
ui/src/components/community-form.tsx

index 6ed25b98ebe09290185a3d5d8cb48e287ac70a93..5af89431a5a5a260c1fa9547ebc08d224167cca1 100644 (file)
@@ -979,7 +979,6 @@ Mods and admins can remove and lock a community, creators can delete it.
   op: "EditCommunity",
   data: {
     edit_id: i32,
-    name: String,
     title: String,
     description: Option<String>,
     category_id: i32,
index e5063e0ff0af6093704387674a6d36f235ee6891..80d2d12532f701540be2bba609b55e9f4c8f5df0 100644 (file)
@@ -98,7 +98,6 @@ pub struct AddModToCommunityResponse {
 #[derive(Serialize, Deserialize)]
 pub struct EditCommunity {
   pub edit_id: i32,
-  name: String,
   title: String,
   description: Option<String>,
   category_id: i32,
@@ -333,10 +332,6 @@ impl Perform for Oper<EditCommunity> {
   ) -> Result<CommunityResponse, LemmyError> {
     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) {
       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()),
     };
 
-    if !is_valid_community_name(&data.name) {
-      return Err(APIError::err("invalid_community_name").into());
-    }
-
     let user_id = claims.id;
 
     // 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 community_form = CommunityForm {
-      name: data.name.to_owned(),
+      name: read_community.name,
       title: data.title.to_owned(),
       description: data.description.to_owned(),
       category_id: data.category_id.to_owned(),
index 95d9c1f745958e9ddac65572681eac63568a4a55..1a8ac65a9c82539ddc4f050a2dde5c4539510252 100644 (file)
@@ -128,26 +128,27 @@ export class CommunityForm extends Component<
           message={i18n.t('block_leaving')}
         />
         <form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}>
-          <div class="form-group row">
-            <label class="col-12 col-form-label" htmlFor="community-name">
-              {i18n.t('name')}
-            </label>
-            <div class="col-12">
-              <input
-                type="text"
-                id="community-name"
-                class="form-control"
-                value={this.state.communityForm.name}
-                onInput={linkEvent(this, this.handleCommunityNameChange)}
-                required
-                minLength={3}
-                maxLength={20}
-                pattern="[a-z0-9_]+"
-                title={i18n.t('community_reqs')}
-              />
+          {!this.props.community && (
+            <div class="form-group row">
+              <label class="col-12 col-form-label" htmlFor="community-name">
+                {i18n.t('name')}
+              </label>
+              <div class="col-12">
+                <input
+                  type="text"
+                  id="community-name"
+                  class="form-control"
+                  value={this.state.communityForm.name}
+                  onInput={linkEvent(this, this.handleCommunityNameChange)}
+                  required
+                  minLength={3}
+                  maxLength={20}
+                  pattern="[a-z0-9_]+"
+                  title={i18n.t('community_reqs')}
+                />
+              </div>
             </div>
-          </div>
-
+          )}
           <div class="form-group row">
             <label class="col-12 col-form-label" htmlFor="community-title">
               {i18n.t('title')}