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

[5.2] Error handling while create folder in media manager new pr #3371

Closed
jgerman-bot opened this issue Jan 19, 2025 · 0 comments · Fixed by #3375
Closed

[5.2] Error handling while create folder in media manager new pr #3371

jgerman-bot opened this issue Jan 19, 2025 · 0 comments · Fixed by #3375

Comments

@jgerman-bot
Copy link

New language relevant PR in upstream repo: joomla/joomla-cms#39878 Here are the upstream changes:

Click to expand the diff!
diff --git a/administrator/components/com_media/resources/scripts/components/modals/create-folder-modal.vue b/administrator/components/com_media/resources/scripts/components/modals/create-folder-modal.vue
index 99269aa27d795..50e5186565ea9 100644
--- a/administrator/components/com_media/resources/scripts/components/modals/create-folder-modal.vue
+++ b/administrator/components/com_media/resources/scripts/components/modals/create-folder-modal.vue
@@ -30,8 +30,31 @@
               type="text"
               required
               autocomplete="off"
+              v-bind:class="(isValidName()!==0 && isValid())?'is-invalid':''"
+              aria-describedby="folderFeedback"
               @input="folder = $event.target.value"
             >
+            <div
+              v-if="isValidName()===1"
+              id="folderFeedback"
+              class="invalid-feedback"
+            >
+              {{ translate('COM_MEDIA_CREATE_NEW_FOLDER_RELATIVE_PATH_ERROR') }}
+            </div>
+            <div
+              v-if="isValidName()===2"
+              id="folderFeedback"
+              class="invalid-feedback"
+            >
+              {{ translate('COM_MEDIA_CREATE_NEW_FOLDER_EXISTING_FOLDER_ERROR') }}
+            </div>
+            <div
+              v-if="isValidName()===3 && isValid()"
+              id="folderFeedback"
+              class="invalid-feedback"
+            >
+              {{ translate('COM_MEDIA_CREATE_NEW_FOLDER_UNEXPECTED_CHARACTER') }}
+            </div>
           </div>
         </form>
       </div>
@@ -46,7 +69,7 @@
         </button>
         <button
           class="btn btn-success"
-          :disabled="!isValid()"
+          :disabled="!isValid() || isValidName()!==0"
           @click="save()"
         >
           {{ translate('JACTION_CREATE') }}
@@ -70,6 +93,15 @@ export default {
       folder: '',
     };
   },
+  computed: {
+    /* Get the contents of the currently selected directory */
+    items() {
+      const directories = this.$store.getters.getSelectedDirectoryDirectories;
+      const files = this.$store.getters.getSelectedDirectoryFiles;
+
+      return [...directories, ...files];
+    },
+  },
   watch: {
     '$store.state.showCreateFolderModal': function (show) {
       this.$nextTick(() => {
@@ -79,11 +111,25 @@ export default {
       });
     },
   },
+
   methods: {
     /* Check if the form is valid */
     isValid() {
       return (this.folder);
     },
+    /* Check folder name is valid or not */
+    isValidName() {
+      if (this.folder.includes('..')) {
+        return 1;
+      }
+      if ((this.items.filter((file) => file.name.toLowerCase() === (this.folder.toLowerCase())).length !== 0)) {
+        return 2;
+      }
+      if ((!/^[\p{L}\p{N}\-_. ]+$/u.test(this.folder))) {
+        return 3;
+      }
+      return 0;
+    },
     /* Close the modal instance */
     close() {
       this.reset();
diff --git a/administrator/components/com_media/tmpl/media/default_texts.php b/administrator/components/com_media/tmpl/media/default_texts.php
index f112607d93b09..575c8511b774e 100644
--- a/administrator/components/com_media/tmpl/media/default_texts.php
+++ b/administrator/components/com_media/tmpl/media/default_texts.php
@@ -28,6 +28,9 @@
     'COM_MEDIA_CREATE_NEW_FOLDER',
     'COM_MEDIA_CREATE_NEW_FOLDER_ERROR',
     'COM_MEDIA_CREATE_NEW_FOLDER_SUCCESS',
+    'COM_MEDIA_CREATE_NEW_FOLDER_EXISTING_FOLDER_ERROR',
+    'COM_MEDIA_CREATE_NEW_FOLDER_RELATIVE_PATH_ERROR',
+    'COM_MEDIA_CREATE_NEW_FOLDER_UNEXPECTED_CHARACTER',
     'COM_MEDIA_DECREASE_GRID',
     'COM_MEDIA_DELETE_ERROR',
     'COM_MEDIA_DELETE_SUCCESS',
diff --git a/administrator/language/en-GB/com_media.ini b/administrator/language/en-GB/com_media.ini
index 26ae6e64dc30a..f8e617dc457a9 100644
--- a/administrator/language/en-GB/com_media.ini
+++ b/administrator/language/en-GB/com_media.ini
@@ -25,6 +25,9 @@ COM_MEDIA_COPY_FOLDER_NOT_POSSIBLE="Copy folder is not possible"
 COM_MEDIA_CREATE_NEW_FOLDER="Create New Folder"
 COM_MEDIA_CREATE_NEW_FOLDER_ERROR="Error creating folder."
 COM_MEDIA_CREATE_NEW_FOLDER_SUCCESS="Folder created."
+COM_MEDIA_CREATE_NEW_FOLDER_EXISTING_FOLDER_ERROR="Folder or file name already exists "
+COM_MEDIA_CREATE_NEW_FOLDER_RELATIVE_PATH_ERROR="Use of relative paths not permitted"
+COM_MEDIA_CREATE_NEW_FOLDER_UNEXPECTED_CHARACTER="Only Alphanumeric ,underscore(_),hyphen(-) and  peroid(.) are allowed"
 COM_MEDIA_DECREASE_GRID="Decrease grid size"
 COM_MEDIA_DELETE_ERROR="Error deleting the item."
 COM_MEDIA_DELETE_NOT_POSSIBLE="Delete not possible!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants