aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/js/wizard/wizardTabExpert.js
blob: 4848ced40fe9174d0475da582bd2db02761fb2ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
 * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

OCA = OCA || {};

(function() {

	/**
	 * @classdesc This class represents the view belonging to the expert tab
	 * in the LDAP wizard.
	 */
	var WizardTabExpert = OCA.LDAP.Wizard.WizardTabGeneric.subClass({
		/**
		 * initializes the instance. Always call it after initialization.
		 *
		 * @param {any} tabIndex -
		 * @param {any} tabID -
		 */
		init: function (tabIndex, tabID) {
			this._super(tabIndex, tabID);

			var items = {
				ldap_expert_username_attr: {
					$element: $('#ldap_expert_username_attr'),
					setMethod: 'setUsernameAttribute'
				},
				ldap_expert_uuid_user_attr: {
					$element: $('#ldap_expert_uuid_user_attr'),
					setMethod: 'setUserUUIDAttribute'
				},
				ldap_expert_uuid_group_attr: {
					$element: $('#ldap_expert_uuid_group_attr'),
					setMethod: 'setGroupUUIDAttribute'
				},

				//Buttons
				ldap_action_clear_user_mappings: {
					$element: $('#ldap_action_clear_user_mappings')
				},
				ldap_action_clear_group_mappings: {
					$element: $('#ldap_action_clear_group_mappings')
				}

			};
			this.setManagedItems(items);
			_.bindAll(this, 'onClearUserMappingsClick', 'onClearGroupMappingsClick');
			this.managedItems.ldap_action_clear_user_mappings.$element.click(this.onClearUserMappingsClick);
			this.managedItems.ldap_action_clear_group_mappings.$element.click(this.onClearGroupMappingsClick);
		},

		/**
		 * Sets the config model for this view and subscribes to some events.
		 * Also binds the config chooser to the model
		 *
		 * @param {OCA.LDAP.Wizard.ConfigModel} configModel
		 */
		setModel: function(configModel) {
			this._super(configModel);
			this.configModel.on('configLoaded', this.onConfigLoaded, this);
			this.configModel.on('receivedLdapFeature', this.onResultReceived, this);
		},

		/**
		 * sets the attribute to be used to create an Nextcloud ID (username)
		 *
		 * @param {string} attribute
		 */
		setUsernameAttribute: function(attribute) {
			this.setElementValue(this.managedItems.ldap_expert_username_attr.$element, attribute);
		},

		/**
		 * sets the attribute that provides an unique identifier per LDAP user
		 * entry
		 *
		 * @param {string} attribute
		 */
		setUserUUIDAttribute: function(attribute) {
			this.setElementValue(this.managedItems.ldap_expert_uuid_user_attr.$element, attribute);
		},

		/**
		 * sets the attribute that provides an unique identifier per LDAP group
		 * entry
		 *
		 * @param {string} attribute
		 */
		setGroupUUIDAttribute: function(attribute) {
			this.setElementValue(this.managedItems.ldap_expert_uuid_group_attr.$element, attribute);
		},

		/**
		 * requests clearing of all user mappings
		 */
		onClearUserMappingsClick: function() {
			this.configModel.requestWizard('ldap_action_clear_user_mappings', {ldap_clear_mapping: 'user'});
		},

		/**
		 * requests clearing of all group mappings
		 */
		onClearGroupMappingsClick: function() {
			this.configModel.requestWizard('ldap_action_clear_group_mappings', {ldap_clear_mapping: 'group'});
		},

		/**
		 * deals with the result of the Test Connection test
		 *
		 * @param {WizardTabAdvanced} view
		 * @param {FeaturePayload} payload
		 */
		onResultReceived: function(view, payload) {
			if(payload.feature === 'ClearMappings') {
				var message;
				if(payload.data.status === 'success') {
					message = t('user_ldap', 'Mappings cleared successfully!');
				} else {
					message = t('user_ldap', 'Error while clearing the mappings.');
				}
				OC.Notification.showTemporary(message);
			}
		}
	});

	OCA.LDAP.Wizard.WizardTabExpert = WizardTabExpert;
})();
n>$offset): void { unset($this->data[$offset]); } public function offsetGet(mixed $offset): mixed { return match ($offset) { 'type' => $this->getType(), 'etag' => $this->getEtag(), 'size' => $this->getSize(), 'mtime' => $this->getMTime(), 'permissions' => $this->getPermissions(), default => $this->data[$offset] ?? null, }; } /** * @return string */ public function getPath() { return $this->path; } public function getStorage() { return $this->storage; } /** * @return string */ public function getInternalPath() { return $this->internalPath; } /** * Get FileInfo ID or null in case of part file * * @return int|null */ public function getId() { return isset($this->data['fileid']) ? (int)$this->data['fileid'] : null; } /** * @return string */ public function getMimetype() { return $this->data['mimetype']; } /** * @return string */ public function getMimePart() { return $this->data['mimepart']; } /** * @return string */ public function getName() { return empty($this->data['name']) ? basename($this->getPath()) : $this->data['name']; } /** * @return string */ public function getEtag() { $this->updateEntryFromSubMounts(); if (count($this->childEtags) > 0) { $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); return md5($combinedEtag); } else { return $this->data['etag']; } } /** * @param bool $includeMounts * @return int|float */ public function getSize($includeMounts = true) { if ($includeMounts) { $this->updateEntryFromSubMounts(); if ($this->isEncrypted() && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) { return $this->data['unencrypted_size']; } else { return isset($this->data['size']) ? 0 + $this->data['size'] : 0; } } else { return $this->rawSize; } } /** * @return int */ public function getMTime() { $this->updateEntryFromSubMounts(); return (int)$this->data['mtime']; } /** * @return bool */ public function isEncrypted() { return $this->data['encrypted'] ?? false; } /** * Return the current version used for the HMAC in the encryption app */ public function getEncryptedVersion(): int { return isset($this->data['encryptedVersion']) ? (int)$this->data['encryptedVersion'] : 1; } /** * @return int */ public function getPermissions() { return (int)$this->data['permissions']; } /** * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER */ public function getType() { if (!isset($this->data['type'])) { $this->data['type'] = ($this->getMimetype() === self::MIMETYPE_FOLDER) ? self::TYPE_FOLDER : self::TYPE_FILE; } return $this->data['type']; } public function getData() { return $this->data; } /** * @param int $permissions * @return bool */ protected function checkPermissions($permissions) { return ($this->getPermissions() & $permissions) === $permissions; } /** * @return bool */ public function isReadable() { return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); } /** * @return bool */ public function isUpdateable() { return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); } /** * Check whether new files or folders can be created inside this folder * * @return bool */ public function isCreatable() { return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); } /** * @return bool */ public function isDeletable() { return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); } /** * @return bool */ public function isShareable() { return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); } /** * Check if a file or folder is shared * * @return bool */ public function isShared() { return $this->mount instanceof ISharedMountPoint; } public function isMounted() { $isHome = $this->mount instanceof HomeMountPoint; return !$isHome && !$this->isShared(); } /** * Get the mountpoint the file belongs to * * @return \OCP\Files\Mount\IMountPoint */ public function getMountPoint() { return $this->mount; } /** * Get the owner of the file * * @return ?IUser */ public function getOwner() { return $this->owner; } /** * @param IMountPoint[] $mounts */ public function setSubMounts(array $mounts) { $this->subMounts = $mounts; } private function updateEntryFromSubMounts(): void { if ($this->subMountsUsed) { return; } $this->subMountsUsed = true; foreach ($this->subMounts as $mount) { $subStorage = $mount->getStorage(); if ($subStorage) { $subCache = $subStorage->getCache(''); $rootEntry = $subCache->get(''); $this->addSubEntry($rootEntry, $mount->getMountPoint()); } } } /** * Add a cache entry which is the child of this folder * * Sets the size, etag and size to for cross-storage childs * * @param array|ICacheEntry $data cache entry for the child * @param string $entryPath full path of the child entry */ public function addSubEntry($data, $entryPath) { if (!$data) { return; } $hasUnencryptedSize = isset($data['unencrypted_size']) && $data['unencrypted_size'] > 0; if ($hasUnencryptedSize) { $subSize = $data['unencrypted_size']; } else { $subSize = $data['size'] ?: 0; } $this->data['size'] += $subSize; if ($hasUnencryptedSize) { $this->data['unencrypted_size'] += $subSize; } if (isset($data['mtime'])) { $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); } if (isset($data['etag'])) { // prefix the etag with the relative path of the subentry to propagate etag on mount moves $relativeEntryPath = substr($entryPath, strlen($this->getPath())); // attach the permissions to propagate etag on permission changes of submounts $permissions = isset($data['permissions']) ? $data['permissions'] : 0; $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; } } /** * @inheritdoc */ public function getChecksum() { return $this->data['checksum']; } public function getExtension(): string { return pathinfo($this->getName(), PATHINFO_EXTENSION); } public function getCreationTime(): int { return (int)$this->data['creation_time']; } public function getUploadTime(): int { return (int)$this->data['upload_time']; } public function getParentId(): int { return $this->data['parent'] ?? -1; } /** * @inheritDoc * @return array<string, int|string|bool|float|string[]|int[]> */ public function getMetadata(): array { return $this->data['metadata'] ?? []; } }