feat: permission recursion types (#6)
parent
8fbda126e4
commit
9369e8ae31
|
@ -186,8 +186,11 @@ export async function unarchive(path, name, override) {
|
|||
return resourceAction(url, "PATCH");
|
||||
}
|
||||
|
||||
export async function chmod(path, perms, recursive = false) {
|
||||
export async function chmod(path, perms, recursive, recursionType) {
|
||||
const action = `chmod`;
|
||||
const url = `${path}?action=${action}&permissions=${perms}&recursive=${recursive}`;
|
||||
let url = `${path}?action=${action}&permissions=${perms}&recursive=${recursive}`;
|
||||
if (recursive) {
|
||||
url += `&type=${recursionType}`;
|
||||
}
|
||||
return resourceAction(url, "PATCH");
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<h2>{{ $t("prompts.permissions") }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<table class="permissions">
|
||||
<div class="card-content" id="permissions">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td></td>
|
||||
|
@ -15,7 +15,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="permission-row">
|
||||
<tr>
|
||||
<td>{{ $t("prompts.owner") }}</td>
|
||||
<td>
|
||||
<input type="checkbox" v-model="permissions.owner.read" />
|
||||
|
@ -27,7 +27,7 @@
|
|||
<input type="checkbox" v-model="permissions.owner.execute" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="permission-row">
|
||||
<tr>
|
||||
<td>{{ $t("prompts.group") }}</td>
|
||||
<td>
|
||||
<input type="checkbox" v-model="permissions.group.read" />
|
||||
|
@ -39,7 +39,7 @@
|
|||
<input type="checkbox" v-model="permissions.group.execute" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="permission-row">
|
||||
<tr>
|
||||
<td>{{ $t("prompts.others") }}</td>
|
||||
<td>
|
||||
<input type="checkbox" v-model="permissions.others.read" />
|
||||
|
@ -56,10 +56,50 @@
|
|||
<p>
|
||||
<code>{{ permModeString }} ({{ permMode.toString(8) }})</code>
|
||||
</p>
|
||||
<p v-if="dirSelected">
|
||||
<input type="checkbox" v-model="recursive" />
|
||||
{{ $t("prompts.recursive") }}
|
||||
</p>
|
||||
<template v-if="dirSelected">
|
||||
<p>
|
||||
<input type="checkbox" v-model="recursive" />
|
||||
{{ $t("prompts.recursive") }}:
|
||||
</p>
|
||||
<div class="recursion-types">
|
||||
<p>
|
||||
<input
|
||||
type="radio"
|
||||
id="recursive-all"
|
||||
value="all"
|
||||
:disabled="!recursive"
|
||||
v-model="recursionType"
|
||||
/>
|
||||
<label for="recursive-all">
|
||||
{{ $t("prompts.directoriesAndFiles") }}
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<input
|
||||
type="radio"
|
||||
id="recursive-directories"
|
||||
value="directories"
|
||||
:disabled="!recursive"
|
||||
v-model="recursionType"
|
||||
/>
|
||||
<label for="recursive-directories">
|
||||
{{ $t("prompts.directories") }}
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<input
|
||||
type="radio"
|
||||
id="recursive-files"
|
||||
value="files"
|
||||
:disabled="!recursive"
|
||||
v-model="recursionType"
|
||||
/>
|
||||
<label for="recursive-files">
|
||||
{{ $t("prompts.files") }}
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="card-action">
|
||||
|
@ -93,6 +133,7 @@ export default {
|
|||
data: function () {
|
||||
return {
|
||||
recursive: false,
|
||||
recursionType: "all",
|
||||
permissions: {
|
||||
owner: {
|
||||
read: false,
|
||||
|
@ -191,7 +232,12 @@ export default {
|
|||
|
||||
try {
|
||||
this.loading = true;
|
||||
await api.chmod(item.url, this.permMode, this.recursive);
|
||||
await api.chmod(
|
||||
item.url,
|
||||
this.permMode,
|
||||
this.recursive,
|
||||
this.recursionType
|
||||
);
|
||||
|
||||
this.$store.commit("setReload", true);
|
||||
} catch (e) {
|
||||
|
|
|
@ -461,4 +461,12 @@ table tr>*:last-child {
|
|||
.card .card-action.full .action .title {
|
||||
font-size: 1.5em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* * * * * * * * * * * * * * * *
|
||||
* PROMPT - PERMISSIONS *
|
||||
* * * * * * * * * * * * * * * */
|
||||
|
||||
#permissions .recursion-types {
|
||||
padding-left: 1em;
|
||||
}
|
|
@ -125,6 +125,9 @@
|
|||
"group": "Group",
|
||||
"others": "Others",
|
||||
"recursive": "Recursive",
|
||||
"directoriesAndFiles": "Directories and files",
|
||||
"directories": "Directories",
|
||||
"files": "Files",
|
||||
"archive": "Archive",
|
||||
"archiveMessage": "Choose archive name and format:",
|
||||
"unarchive": "Unarchive",
|
||||
|
|
|
@ -478,8 +478,9 @@ func parseArchiver(algo string) (string, archiver.Archiver, error) {
|
|||
|
||||
func chmodActionHandler(r *http.Request, d *data) error {
|
||||
target := r.URL.Path
|
||||
recursive := r.URL.Query().Get("recursive") == "true"
|
||||
perms := r.URL.Query().Get("permissions")
|
||||
recursive := r.URL.Query().Get("recursive") == "true"
|
||||
recursionType := r.URL.Query().Get("type")
|
||||
|
||||
if !d.user.Perm.Modify {
|
||||
return errors.ErrPermissionDenied
|
||||
|
@ -500,13 +501,32 @@ func chmodActionHandler(r *http.Request, d *data) error {
|
|||
}
|
||||
|
||||
if recursive && info.IsDir() {
|
||||
var recFilter func(i os.FileInfo) bool
|
||||
|
||||
switch recursionType {
|
||||
case "directories":
|
||||
recFilter = func(i os.FileInfo) bool {
|
||||
return i.IsDir()
|
||||
}
|
||||
case "files":
|
||||
recFilter = func(i os.FileInfo) bool {
|
||||
return !i.IsDir()
|
||||
}
|
||||
default:
|
||||
recFilter = func(i os.FileInfo) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return afero.Walk(d.user.Fs, target, func(name string, info os.FileInfo, err error) error {
|
||||
if err == nil {
|
||||
err = d.user.Fs.Chmod(name, os.FileMode(mode))
|
||||
if recFilter(info) {
|
||||
err = d.user.Fs.Chmod(name, os.FileMode(mode))
|
||||
}
|
||||
}
|
||||
return err
|
||||
})
|
||||
} else {
|
||||
return d.user.Fs.Chmod(target, os.FileMode(mode))
|
||||
}
|
||||
|
||||
return d.user.Fs.Chmod(target, os.FileMode(mode))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue