Skip to content

Commit

Permalink
Merge pull request #3286 from nextcloud/fix/settings/config-handling-…
Browse files Browse the repository at this point in the history
…stable30
  • Loading branch information
provokateurin authored Sep 30, 2024
2 parents 0c063d8 + 4aa9b0b commit de31f94
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 120 deletions.
11 changes: 11 additions & 0 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\GroupFolders\Service\DelegationService;
use OCA\GroupFolders\Service\FoldersFilter;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -148,6 +149,7 @@ private function getRootFolderStorageId(): ?int {
* @NoAdminRequired
* @throws OCSNotFoundException
*/
#[PasswordConfirmationRequired]
public function addFolder(string $mountpoint): DataResponse {
$id = $this->manager->createFolder(trim($mountpoint));
$folder = $this->manager->getFolder($id, $this->rootFolder->getMountPoint()->getNumericStorageId());
Expand All @@ -161,6 +163,7 @@ public function addFolder(string $mountpoint): DataResponse {
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[PasswordConfirmationRequired]
public function removeFolder(int $id): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -176,6 +179,7 @@ public function removeFolder(int $id): DataResponse {
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[PasswordConfirmationRequired]
public function setMountPoint(int $id, string $mountPoint): DataResponse {
$this->manager->renameFolder($id, trim($mountPoint));
return new DataResponse(['success' => true]);
Expand All @@ -185,6 +189,7 @@ public function setMountPoint(int $id, string $mountPoint): DataResponse {
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[PasswordConfirmationRequired]
public function addGroup(int $id, string $group): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -198,6 +203,7 @@ public function addGroup(int $id, string $group): DataResponse {
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[PasswordConfirmationRequired]
public function removeGroup(int $id, string $group): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -211,6 +217,7 @@ public function removeGroup(int $id, string $group): DataResponse {
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[PasswordConfirmationRequired]
public function setPermissions(int $id, string $group, int $permissions): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -225,6 +232,7 @@ public function setPermissions(int $id, string $group, int $permissions): DataRe
* @RequireGroupFolderAdmin
* @throws \OCP\DB\Exception
*/
#[PasswordConfirmationRequired]
public function setManageACL(int $id, string $mappingType, string $mappingId, bool $manageAcl): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -238,6 +246,7 @@ public function setManageACL(int $id, string $mappingType, string $mappingId, bo
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[PasswordConfirmationRequired]
public function setQuota(int $id, int $quota): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -251,6 +260,7 @@ public function setQuota(int $id, int $quota): DataResponse {
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[PasswordConfirmationRequired]
public function setACL(int $id, bool $acl): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand All @@ -264,6 +274,7 @@ public function setACL(int $id, bool $acl): DataResponse {
* @NoAdminRequired
* @RequireGroupFolderAdmin
*/
#[PasswordConfirmationRequired]
public function renameFolder(int $id, string $mountpoint): DataResponse {
$response = $this->checkFolderExists($id);
if ($response) {
Expand Down
30 changes: 20 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@nextcloud/webpack-vue-config": "^5.5.1",
"@types/bootstrap": "^5.2.10",
"@types/jest": "^29.5.12",
"@types/jquery": "^3.5.29",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.0",
"@types/webpack": "^5.28.5",
Expand Down Expand Up @@ -60,6 +59,7 @@
"@nextcloud/initial-state": "^2.2.0",
"@nextcloud/l10n": "^3.1.0",
"@nextcloud/logger": "^3.0.2",
"@nextcloud/password-confirmation": "^5.1.1",
"@nextcloud/router": "^3.0.1",
"@nextcloud/vue": "^8.17.0",
"nextcloud-server": "^0.15.10",
Expand Down
155 changes: 78 additions & 77 deletions src/settings/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { generateUrl } from '@nextcloud/router'
import { OCSResult, AxiosOCSResult } from 'NC'
import axios from '@nextcloud/axios'
import Thenable = JQuery.Thenable;
import { confirmPassword } from '@nextcloud/password-confirmation'
// eslint-disable-next-line n/no-unpublished-import
import type { OCSResponse } from '@nextcloud/typings/lib/ocs'

export interface Group {
gid: string;
Expand Down Expand Up @@ -33,7 +34,6 @@ export interface ManageRuleProps {
displayname: string;
}


export interface Folder {
id: number;
mount_point: string;
Expand All @@ -50,118 +50,119 @@ export class Api {
return OC.generateUrl(`apps/groupfolders/${endpoint}`)
}

listFolders(): Thenable<Folder[]> {
return $.getJSON(this.getUrl('folders'))
.then((data: OCSResult<Folder[]>) => Object.keys(data.ocs.data).map(id => data.ocs.data[id]))
async listFolders(): Promise<Folder[]> {
const response = await axios.get<OCSResponse<Folder[]>>(this.getUrl('folders'))
return Object.keys(response.data.ocs.data).map(id => response.data.ocs.data[id])
}

// Returns all NC groups
listGroups(): Thenable<Group[]> {
return $.getJSON(this.getUrl('delegation/groups'))
.then((data: OCSResult<Group[]>) => data.ocs.data)
async listGroups(): Promise<Group[]> {
const response = await axios.get<OCSResponse<Group[]>>(this.getUrl('delegation/groups'))
return response.data.ocs.data
}

// Returns all visible NC circles
listCircles(): Thenable<Circle[]> {
return $.getJSON(this.getUrl('delegation/circles'))
.then((data: OCSResult<Circle[]>) => data.ocs.data)
async listCircles(): Promise<Circle[]> {
const response = await axios.get<OCSResponse<Circle[]>>(this.getUrl('delegation/circles'))
return response.data.ocs.data
}

// Returns all groups that have been granted delegated admin or subadmin rights on groupfolders
listDelegatedGroups(classname: string): Thenable<Group[]> {
return axios.get(this.getUrl('/delegation/authorized-groups'), { params: { classname } })
.then((data: AxiosOCSResult<Group[]>) => {
// The admin group is always there. We don't want the user to remove it
const groups = data.data.ocs.data.filter(g => g.gid !== 'admin')
return groups
})
async listDelegatedGroups(classname: string): Promise<Group[]> {
const response = await axios.get<OCSResponse<Group[]>>(this.getUrl('/delegation/authorized-groups'), { params: { classname } })
return response.data.ocs.data.filter(g => g.gid !== 'admin')
}

// Updates the list of groups that have been granted delegated admin or subadmin rights on groupfolders
updateDelegatedGroups(newGroups: Group[], classname: string): Thenable<void> {
return axios.post(generateUrl('/apps/settings/') + '/settings/authorizedgroups/saveSettings', {
async updateDelegatedGroups(newGroups: Group[], classname: string): Promise<void> {
await confirmPassword()

await axios.post(generateUrl('/apps/settings/') + '/settings/authorizedgroups/saveSettings', {
newGroups,
class: classname,
}).then((data) => data.data)
})
}

createFolder(mountPoint: string): Thenable<Folder> {
return $.post(this.getUrl('folders'), {
mountpoint: mountPoint
}, null, 'json').then((data: OCSResult<Folder>) => data.ocs.data)
async createFolder(mountPoint: string): Promise<Folder> {
await confirmPassword()

const response = await axios.post<OCSResponse<Folder>>(this.getUrl('folders'), { mountpoint: mountPoint })
return response.data.ocs.data
}

deleteFolder(id: number): Thenable<void> {
return $.ajax({
url: this.getUrl(`folders/${id}`),
type: 'DELETE'
})
async deleteFolder(id: number): Promise<void> {
await confirmPassword()

await axios.delete(this.getUrl(`folders/${id}`))
}

addGroup(folderId: number, group: string): Thenable<void> {
return $.post(this.getUrl(`folders/${folderId}/groups`), {
group
})
async addGroup(folderId: number, group: string): Promise<void> {
await confirmPassword()

await axios.post(this.getUrl(`folders/${folderId}/groups`), { group })
}

removeGroup(folderId: number, group: string): Thenable<void> {
return $.ajax({
url: this.getUrl(`folders/${folderId}/groups/${group}`),
type: 'DELETE'
})
async removeGroup(folderId: number, group: string): Promise<void> {
await confirmPassword()

await axios.delete(this.getUrl(`folders/${folderId}/groups/${group}`))
}

setPermissions(folderId: number, group: string, permissions: number): Thenable<void> {
return $.post(this.getUrl(`folders/${folderId}/groups/${group}`), {
permissions
})
async setPermissions(folderId: number, group: string, permissions: number): Promise<void> {
await confirmPassword()

await axios.post(this.getUrl(`folders/${folderId}/groups/${group}`), { permissions })
}

setManageACL(folderId: number, type: string, id: string, manageACL: boolean): Thenable<void> {
return $.post(this.getUrl(`folders/${folderId}/manageACL`), {
async setManageACL(folderId: number, type: string, id: string, manageACL: boolean): Promise<void> {
await confirmPassword()

await axios.post(this.getUrl(`folders/${folderId}/manageACL`), {
mappingType: type,
mappingId: id,
manageAcl: manageACL ? 1 : 0
manageAcl: manageACL ? 1 : 0,
})
}

setQuota(folderId: number, quota: number): Thenable<void> {
return $.post(this.getUrl(`folders/${folderId}/quota`), {
quota
})
async setQuota(folderId: number, quota: number): Promise<void> {
await confirmPassword()

await axios.post(this.getUrl(`folders/${folderId}/quota`), { quota })
}

setACL(folderId: number, acl: boolean): Thenable<void> {
return $.post(this.getUrl(`folders/${folderId}/acl`), {
acl: acl ? 1 : 0
})
async setACL(folderId: number, acl: boolean): Promise<void> {
await confirmPassword()

await axios.post(this.getUrl(`folders/${folderId}/acl`), { acl: acl ? 1 : 0 })
}

renameFolder(folderId: number, mountpoint: string): Thenable<void> {
return $.post(this.getUrl(`folders/${folderId}/mountpoint`), {
mountpoint
})
async renameFolder(folderId: number, mountpoint: string): Promise<void> {
await confirmPassword()

await axios.post(this.getUrl(`folders/${folderId}/mountpoint`), { mountpoint })
}

aclMappingSearch(folderId: number, search: string): Thenable<{groups: OCSGroup[], users: OCSUser[]}> {
return $.getJSON(this.getUrl(`folders/${folderId}/search?format=json&search=${search}`))
.then((data: OCSResult<{ groups: OCSGroup[]; users: OCSUser[]; }>) => {
async aclMappingSearch(folderId: number, search: string): Promise<{
groups: ManageRuleProps[],
users: ManageRuleProps[]
}> {
const response = await axios.get<OCSResponse<{groups: OCSGroup[], users: OCSUser[]}>>(this.getUrl(`folders/${folderId}/search`), { params: { search } })
return {
groups: Object.values(response.data.ocs.data.groups).map((item) => {
return {
groups: Object.values(data.ocs.data.groups).map((item) => {
return {
type: 'group',
id: item.gid,
displayname: item.displayname
}
}),
users: Object.values(data.ocs.data.users).map((item) => {
return {
type: 'user',
id: item.uid,
displayname: item.displayname
}
})
type: 'group',
id: item.gid,
displayname: item.displayname,
}
})
}),
users: Object.values(response.data.ocs.data.users).map((item) => {
return {
type: 'user',
id: item.uid,
displayname: item.displayname,
}
}),
}
}

}
Loading

0 comments on commit de31f94

Please sign in to comment.