Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
94 changes: 75 additions & 19 deletions app/assets/javascripts/file_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function rename(path) {
$.ajax({
url: "/file_manager/" + rel_path,
type: "PUT",
data: { new_name: new_name, relative_path: rel_path},
data: { new_name: new_name, relative_path: rel_path },
success: function(data) {
console.log(`Renamed: ${rel_path}`)
location.reload();
Expand All @@ -19,11 +19,11 @@ function deleteSelected(path) {
$.ajax({
url: path,
type: "DELETE",
success: function () {
success: function() {
console.log(`Deleted: ${path}`);
resolve();
},
error: function (xhr, status, error) {
error: function(xhr, status, error) {
reject(error);
}
});
Expand All @@ -38,7 +38,7 @@ function downloadSelected(path) {
data: {
path: path
},
success: function (data) {
success: function(data) {
let blob = new Blob([data], { type: 'application/x-tar' });
let url = URL.createObjectURL(blob);
let a = document.createElement('a');
Expand All @@ -53,7 +53,7 @@ function downloadSelected(path) {
console.log(`Downloaded: ${data.filename}`);
resolve();
},
error: function (xhr, status, error) {
error: function(xhr, status, error) {
console.error(`Failed to download ${path}: ${error}`);
reject(error);
}
Expand All @@ -76,11 +76,11 @@ function uploadFile(file, path, name) {
data: formData,
contentType: false,
processData: false,
success: function () {
success: function() {
console.log("Uploaded file successfully");
resolve();
},
error: function (xhr, status, error) {
error: function(xhr, status, error) {
console.error(`Failed to upload file: ${error}`);
reject(error);
}
Expand All @@ -98,14 +98,14 @@ function uploadAllFiles(path) {
}
if (files.length > 0) {
Promise.all(uploadPromises)
.then(() => {
alert("All files uploaded successfully.");
location.reload();
})
.catch((error) => {
alert("Some files failed to upload successfully. Ensure that you are not in the root directory, the file is smaller than 1 GB, and does not already exist.");
location.reload();
});
.then(() => {
alert("All files uploaded successfully.");
location.reload();
})
.catch((error) => {
alert("Some files failed to upload successfully. Ensure that you are not in the root directory, the file is smaller than 1 GB, and does not already exist.");
location.reload();
});
} else {
console.log('No files selected.');
}
Expand All @@ -130,8 +130,7 @@ function createFolder(path) {
})
.catch((error) => {
alert("Failed to create folder. Check that you are not in the root directory and that the tile/folder does not already exist.");
})
;
});
}
}

Expand Down Expand Up @@ -204,6 +203,60 @@ function handleSelectionChange() {
updateButtonStatesAndStyle(deleteBtn, deleteParent);
}

function changePermissions(path, permissions) {
// Validate permissions format
if (!/^[0-7]{3,4}$/.test(permissions)) {
alert("Invalid permission format. Please use 3-4 digit octal format (e.g., 755, 644)");
return;
}

let rel_path = decodeURIComponent(path.split("/file_manager/")[1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Path manipulation could fail on edge cases.

Line 213 splits the path by "/file_manager/" and assumes the relevant path is after the first occurrence. This could break if the path itself contains the string "/file_manager/".

Use a more robust approach. If path is already the relative path as used elsewhere in the file, you might not need this splitting at all:

-let rel_path = decodeURIComponent(path.split("/file_manager/")[1]);
+// Assuming path is already the relative path from entry[:relative]
+let rel_path = decodeURIComponent(path);

Alternatively, if you must extract from a full URL:

// Remove the /file_manager/ prefix if present
let rel_path = path.replace(/^\/file_manager\//, '');
rel_path = decodeURIComponent(rel_path);
🤖 Prompt for AI Agents
In app/assets/javascripts/file_manager.js around line 213, the current code
splits the path on "/file_manager/" and takes the second segment which fails if
the path contains that string multiple times; instead remove only a leading
"/file_manager/" prefix if present (or skip any splitting entirely if path is
already relative), then decodeURIComponent the resulting string; implement this
by checking and stripping the prefix at the start of the string and then calling
decodeURIComponent on the result.

$.ajax({
url: "/file_manager/" + rel_path + "/chmod",
type: "PATCH",
data: {
path: rel_path,
permissions: permissions
},
success: function(data) {
console.log(`Changed permissions for: ${rel_path} to ${permissions}`);
location.reload();
},
error: function(xhr, status, error) {
console.error("Error changing permissions:", error);
alert("Error changing permissions: " + (xhr.responseJSON ? xhr.responseJSON.error : error));
}
});
}

// Add keyboard support for permissions input
function setupPermissionsKeyboardSupport() {
document.querySelectorAll('.permissions-input').forEach(function(input) {
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
const filePath = this.getAttribute('data-file-path');
changePermissions(filePath, this.value);
}
});

// Real-time validation feedback
input.addEventListener('input', function(e) {
const value = this.value;
if (value && !/^[0-7]{0,4}$/.test(value)) {
this.style.borderColor = '#dc3545';
this.style.backgroundColor = '#ffe6e6';
} else if (value && /^[0-7]{3,4}$/.test(value)) {
this.style.borderColor = '#28a745';
this.style.backgroundColor = '#e6ffe6';
} else {
this.style.borderColor = '#ddd';
this.style.backgroundColor = '#f9f9f9';
}
});
});
}

document.addEventListener('DOMContentLoaded', function() {
const otherCheckboxes = document.querySelectorAll('.check');
handleSelectionChange();
Expand All @@ -218,5 +271,8 @@ document.addEventListener('DOMContentLoaded', function() {

$(".check").click(function() {
handleSelectionChange();
})
});
});

// Setup permissions input keyboard support
setupPermissionsKeyboardSupport();
});
161 changes: 106 additions & 55 deletions app/assets/stylesheets/file_manager.scss
Original file line number Diff line number Diff line change
@@ -1,91 +1,142 @@
.div-row {
display: flex;
flex-direction: row;
gap: 5rem;
display: flex;
flex-direction: row;
gap: 5rem;
}

[type="checkbox"]:not(:checked) {
opacity: 100;
position: relative;
display: flex;
justify-content: center;
align-items: center;
pointer-events: auto;
opacity: 100;
position: relative;
display: flex;
justify-content: center;
align-items: center;
pointer-events: auto;
}

[type="checkbox"]:checked {
position: relative;
opacity: 1;
pointer-events: unset;
position: relative;
opacity: 1;
pointer-events: unset;
}

.table-col-center {
display: flex;
justify-content: center;
align-items: center;
padding-top: 35%;
display: flex;
justify-content: center;
align-items: center;
padding-top: 35%;
}

.table-scroll {
height: 40rem;
overflow-y: auto;
height: 40rem;
overflow-y: auto;
}

.div-row-cols {
display: flex;
align-items: center;
display: flex;
align-items: center;
}

.button-file {
position: relative;
overflow: hidden;
position: relative;
overflow: hidden;
}

.button-file input[type=submit] {
left: -10px;
right: 0;
padding: 0;
left: -10px;
right: 0;
padding: 0;
}

.button-file input {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: green;
display: block;
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: green;
display: block;
}

.button-file a {
color: white;
color: white;
}

@media screen and (max-width: 1164px) {
.div-row {
display: grid;
grid-template-columns: auto auto;
gap: 1rem;
}
.button-file {
width: 200px;
}
.div-row-cols {
margin: 0;
padding: 0;
}
.div-row {
display: grid;
grid-template-columns: auto auto;
gap: 1rem;
}
.button-file {
width: 200px;
}
.div-row-cols {
margin: 0;
padding: 0;
}
}

@media screen and (max-width: 478px) {
.div-row {
display: grid;
grid-template-columns: auto;
gap: 1rem;
}
.div-row {
display: grid;
grid-template-columns: auto;
gap: 1rem;
}
}

// Permissions input styling
input[type=text].permissions-input {
width: 40px;
text-align: center;
font-family: monospace;
font-size: 12px;
padding: 2px 4px;
border: 1px solid #ddd;
border-radius: 3px;
background-color: #f9f9f9;
&:focus {
outline: none;
border-color: #007bff;
background-color: white;
}
&:invalid {
border-color: #dc3545;
background-color: #ffe6e6;
}
}

.permissions-button {
padding: 2px 4px;
font-size: 12px;
border: none;
background-color: #28a745;
color: white;
border-radius: 3px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
min-width: 10px;
height: 24px;
&:hover {
background-color: #218838;
}
&:active {
background-color: #1e7e34;
}
.material-icons {
font-size: 14px;
}
}

.permissions-container {
display: flex;
align-items: center;
gap: 8px;
// justify-content: center;
}
Loading
Loading