@@ -40,244 +40,244 @@ |
||
| 40 | 40 | |
| 41 | 41 | class JSConfigHelper { |
| 42 | 42 | |
| 43 | - /** @var IL10N */ |
|
| 44 | - private $l; |
|
| 43 | + /** @var IL10N */ |
|
| 44 | + private $l; |
|
| 45 | 45 | |
| 46 | - /** @var Defaults */ |
|
| 47 | - private $defaults; |
|
| 46 | + /** @var Defaults */ |
|
| 47 | + private $defaults; |
|
| 48 | 48 | |
| 49 | - /** @var IAppManager */ |
|
| 50 | - private $appManager; |
|
| 49 | + /** @var IAppManager */ |
|
| 50 | + private $appManager; |
|
| 51 | 51 | |
| 52 | - /** @var ISession */ |
|
| 53 | - private $session; |
|
| 52 | + /** @var ISession */ |
|
| 53 | + private $session; |
|
| 54 | 54 | |
| 55 | - /** @var IUser|null */ |
|
| 56 | - private $currentUser; |
|
| 55 | + /** @var IUser|null */ |
|
| 56 | + private $currentUser; |
|
| 57 | 57 | |
| 58 | - /** @var IConfig */ |
|
| 59 | - private $config; |
|
| 58 | + /** @var IConfig */ |
|
| 59 | + private $config; |
|
| 60 | 60 | |
| 61 | - /** @var IGroupManager */ |
|
| 62 | - private $groupManager; |
|
| 61 | + /** @var IGroupManager */ |
|
| 62 | + private $groupManager; |
|
| 63 | 63 | |
| 64 | - /** @var IniGetWrapper */ |
|
| 65 | - private $iniWrapper; |
|
| 64 | + /** @var IniGetWrapper */ |
|
| 65 | + private $iniWrapper; |
|
| 66 | 66 | |
| 67 | - /** @var IURLGenerator */ |
|
| 68 | - private $urlGenerator; |
|
| 67 | + /** @var IURLGenerator */ |
|
| 68 | + private $urlGenerator; |
|
| 69 | 69 | |
| 70 | - /** @var CapabilitiesManager */ |
|
| 71 | - private $capabilitiesManager; |
|
| 70 | + /** @var CapabilitiesManager */ |
|
| 71 | + private $capabilitiesManager; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param IL10N $l |
|
| 75 | - * @param Defaults $defaults |
|
| 76 | - * @param IAppManager $appManager |
|
| 77 | - * @param ISession $session |
|
| 78 | - * @param IUser|null $currentUser |
|
| 79 | - * @param IConfig $config |
|
| 80 | - * @param IGroupManager $groupManager |
|
| 81 | - * @param IniGetWrapper $iniWrapper |
|
| 82 | - * @param IURLGenerator $urlGenerator |
|
| 83 | - * @param CapabilitiesManager $capabilitiesManager |
|
| 84 | - */ |
|
| 85 | - public function __construct(IL10N $l, |
|
| 86 | - Defaults $defaults, |
|
| 87 | - IAppManager $appManager, |
|
| 88 | - ISession $session, |
|
| 89 | - $currentUser, |
|
| 90 | - IConfig $config, |
|
| 91 | - IGroupManager $groupManager, |
|
| 92 | - IniGetWrapper $iniWrapper, |
|
| 93 | - IURLGenerator $urlGenerator, |
|
| 94 | - CapabilitiesManager $capabilitiesManager) { |
|
| 95 | - $this->l = $l; |
|
| 96 | - $this->defaults = $defaults; |
|
| 97 | - $this->appManager = $appManager; |
|
| 98 | - $this->session = $session; |
|
| 99 | - $this->currentUser = $currentUser; |
|
| 100 | - $this->config = $config; |
|
| 101 | - $this->groupManager = $groupManager; |
|
| 102 | - $this->iniWrapper = $iniWrapper; |
|
| 103 | - $this->urlGenerator = $urlGenerator; |
|
| 104 | - $this->capabilitiesManager = $capabilitiesManager; |
|
| 105 | - } |
|
| 73 | + /** |
|
| 74 | + * @param IL10N $l |
|
| 75 | + * @param Defaults $defaults |
|
| 76 | + * @param IAppManager $appManager |
|
| 77 | + * @param ISession $session |
|
| 78 | + * @param IUser|null $currentUser |
|
| 79 | + * @param IConfig $config |
|
| 80 | + * @param IGroupManager $groupManager |
|
| 81 | + * @param IniGetWrapper $iniWrapper |
|
| 82 | + * @param IURLGenerator $urlGenerator |
|
| 83 | + * @param CapabilitiesManager $capabilitiesManager |
|
| 84 | + */ |
|
| 85 | + public function __construct(IL10N $l, |
|
| 86 | + Defaults $defaults, |
|
| 87 | + IAppManager $appManager, |
|
| 88 | + ISession $session, |
|
| 89 | + $currentUser, |
|
| 90 | + IConfig $config, |
|
| 91 | + IGroupManager $groupManager, |
|
| 92 | + IniGetWrapper $iniWrapper, |
|
| 93 | + IURLGenerator $urlGenerator, |
|
| 94 | + CapabilitiesManager $capabilitiesManager) { |
|
| 95 | + $this->l = $l; |
|
| 96 | + $this->defaults = $defaults; |
|
| 97 | + $this->appManager = $appManager; |
|
| 98 | + $this->session = $session; |
|
| 99 | + $this->currentUser = $currentUser; |
|
| 100 | + $this->config = $config; |
|
| 101 | + $this->groupManager = $groupManager; |
|
| 102 | + $this->iniWrapper = $iniWrapper; |
|
| 103 | + $this->urlGenerator = $urlGenerator; |
|
| 104 | + $this->capabilitiesManager = $capabilitiesManager; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function getConfig() { |
|
| 107 | + public function getConfig() { |
|
| 108 | 108 | |
| 109 | - if ($this->currentUser !== null) { |
|
| 110 | - $uid = $this->currentUser->getUID(); |
|
| 111 | - } else { |
|
| 112 | - $uid = null; |
|
| 113 | - } |
|
| 109 | + if ($this->currentUser !== null) { |
|
| 110 | + $uid = $this->currentUser->getUID(); |
|
| 111 | + } else { |
|
| 112 | + $uid = null; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - // Get the config |
|
| 116 | - $apps_paths = []; |
|
| 115 | + // Get the config |
|
| 116 | + $apps_paths = []; |
|
| 117 | 117 | |
| 118 | - if ($this->currentUser === null) { |
|
| 119 | - $apps = $this->appManager->getInstalledApps(); |
|
| 120 | - } else { |
|
| 121 | - $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
| 122 | - } |
|
| 118 | + if ($this->currentUser === null) { |
|
| 119 | + $apps = $this->appManager->getInstalledApps(); |
|
| 120 | + } else { |
|
| 121 | + $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - foreach($apps as $app) { |
|
| 125 | - $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
| 126 | - } |
|
| 124 | + foreach($apps as $app) { |
|
| 125 | + $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | |
| 129 | - $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
| 130 | - $enableLinkPasswordByDefault = ($enableLinkPasswordByDefault === 'yes') ? true : false; |
|
| 131 | - $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 132 | - $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
| 133 | - if ($defaultExpireDateEnabled) { |
|
| 134 | - $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 135 | - $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 136 | - } |
|
| 137 | - $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 129 | + $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
| 130 | + $enableLinkPasswordByDefault = ($enableLinkPasswordByDefault === 'yes') ? true : false; |
|
| 131 | + $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 132 | + $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
| 133 | + if ($defaultExpireDateEnabled) { |
|
| 134 | + $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 135 | + $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 136 | + } |
|
| 137 | + $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 138 | 138 | |
| 139 | - $countOfDataLocation = 0; |
|
| 140 | - $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
| 141 | - if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
| 142 | - $dataLocation = false; |
|
| 143 | - } |
|
| 139 | + $countOfDataLocation = 0; |
|
| 140 | + $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
| 141 | + if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
| 142 | + $dataLocation = false; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if ($this->currentUser instanceof IUser) { |
|
| 146 | - $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
| 147 | - if (!is_int($lastConfirmTimestamp)) { |
|
| 148 | - $lastConfirmTimestamp = 0; |
|
| 149 | - } |
|
| 150 | - } else { |
|
| 151 | - $lastConfirmTimestamp = 0; |
|
| 152 | - } |
|
| 145 | + if ($this->currentUser instanceof IUser) { |
|
| 146 | + $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
| 147 | + if (!is_int($lastConfirmTimestamp)) { |
|
| 148 | + $lastConfirmTimestamp = 0; |
|
| 149 | + } |
|
| 150 | + } else { |
|
| 151 | + $lastConfirmTimestamp = 0; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
| 154 | + $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
| 155 | 155 | |
| 156 | - $array = [ |
|
| 157 | - "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
| 158 | - "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
| 159 | - "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
| 160 | - "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
| 161 | - "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
| 162 | - "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
| 163 | - 'nc_lastLogin' => $lastConfirmTimestamp, |
|
| 164 | - "dayNames" => json_encode([ |
|
| 165 | - (string)$this->l->t('Sunday'), |
|
| 166 | - (string)$this->l->t('Monday'), |
|
| 167 | - (string)$this->l->t('Tuesday'), |
|
| 168 | - (string)$this->l->t('Wednesday'), |
|
| 169 | - (string)$this->l->t('Thursday'), |
|
| 170 | - (string)$this->l->t('Friday'), |
|
| 171 | - (string)$this->l->t('Saturday') |
|
| 172 | - ]), |
|
| 173 | - "dayNamesShort" => json_encode([ |
|
| 174 | - (string)$this->l->t('Sun.'), |
|
| 175 | - (string)$this->l->t('Mon.'), |
|
| 176 | - (string)$this->l->t('Tue.'), |
|
| 177 | - (string)$this->l->t('Wed.'), |
|
| 178 | - (string)$this->l->t('Thu.'), |
|
| 179 | - (string)$this->l->t('Fri.'), |
|
| 180 | - (string)$this->l->t('Sat.') |
|
| 181 | - ]), |
|
| 182 | - "dayNamesMin" => json_encode([ |
|
| 183 | - (string)$this->l->t('Su'), |
|
| 184 | - (string)$this->l->t('Mo'), |
|
| 185 | - (string)$this->l->t('Tu'), |
|
| 186 | - (string)$this->l->t('We'), |
|
| 187 | - (string)$this->l->t('Th'), |
|
| 188 | - (string)$this->l->t('Fr'), |
|
| 189 | - (string)$this->l->t('Sa') |
|
| 190 | - ]), |
|
| 191 | - "monthNames" => json_encode([ |
|
| 192 | - (string)$this->l->t('January'), |
|
| 193 | - (string)$this->l->t('February'), |
|
| 194 | - (string)$this->l->t('March'), |
|
| 195 | - (string)$this->l->t('April'), |
|
| 196 | - (string)$this->l->t('May'), |
|
| 197 | - (string)$this->l->t('June'), |
|
| 198 | - (string)$this->l->t('July'), |
|
| 199 | - (string)$this->l->t('August'), |
|
| 200 | - (string)$this->l->t('September'), |
|
| 201 | - (string)$this->l->t('October'), |
|
| 202 | - (string)$this->l->t('November'), |
|
| 203 | - (string)$this->l->t('December') |
|
| 204 | - ]), |
|
| 205 | - "monthNamesShort" => json_encode([ |
|
| 206 | - (string)$this->l->t('Jan.'), |
|
| 207 | - (string)$this->l->t('Feb.'), |
|
| 208 | - (string)$this->l->t('Mar.'), |
|
| 209 | - (string)$this->l->t('Apr.'), |
|
| 210 | - (string)$this->l->t('May.'), |
|
| 211 | - (string)$this->l->t('Jun.'), |
|
| 212 | - (string)$this->l->t('Jul.'), |
|
| 213 | - (string)$this->l->t('Aug.'), |
|
| 214 | - (string)$this->l->t('Sep.'), |
|
| 215 | - (string)$this->l->t('Oct.'), |
|
| 216 | - (string)$this->l->t('Nov.'), |
|
| 217 | - (string)$this->l->t('Dec.') |
|
| 218 | - ]), |
|
| 219 | - "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
| 220 | - "oc_config" => json_encode([ |
|
| 221 | - 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
| 222 | - 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
| 223 | - 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 224 | - 'versionstring' => \OC_Util::getVersionString(), |
|
| 225 | - 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
| 226 | - 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), |
|
| 227 | - 'modRewriteWorking' => ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'), |
|
| 228 | - 'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)), |
|
| 229 | - 'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)), |
|
| 230 | - 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
| 231 | - ]), |
|
| 232 | - "oc_appconfig" => json_encode([ |
|
| 233 | - 'core' => [ |
|
| 234 | - 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
| 235 | - 'defaultExpireDate' => $defaultExpireDate, |
|
| 236 | - 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
| 237 | - 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
| 238 | - 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
| 239 | - 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
| 240 | - 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
| 241 | - 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
| 242 | - 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
| 243 | - 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() |
|
| 244 | - ] |
|
| 245 | - ]), |
|
| 246 | - "oc_defaults" => json_encode([ |
|
| 247 | - 'entity' => $this->defaults->getEntity(), |
|
| 248 | - 'name' => $this->defaults->getName(), |
|
| 249 | - 'title' => $this->defaults->getTitle(), |
|
| 250 | - 'baseUrl' => $this->defaults->getBaseUrl(), |
|
| 251 | - 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
| 252 | - 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
| 253 | - 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
| 254 | - 'slogan' => $this->defaults->getSlogan(), |
|
| 255 | - 'logoClaim' => '', |
|
| 256 | - 'shortFooter' => $this->defaults->getShortFooter(), |
|
| 257 | - 'longFooter' => $this->defaults->getLongFooter(), |
|
| 258 | - 'folder' => \OC_Util::getTheme(), |
|
| 259 | - ]), |
|
| 260 | - "oc_capabilities" => json_encode($capabilities), |
|
| 261 | - ]; |
|
| 156 | + $array = [ |
|
| 157 | + "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
| 158 | + "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
| 159 | + "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
| 160 | + "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
| 161 | + "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
| 162 | + "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
| 163 | + 'nc_lastLogin' => $lastConfirmTimestamp, |
|
| 164 | + "dayNames" => json_encode([ |
|
| 165 | + (string)$this->l->t('Sunday'), |
|
| 166 | + (string)$this->l->t('Monday'), |
|
| 167 | + (string)$this->l->t('Tuesday'), |
|
| 168 | + (string)$this->l->t('Wednesday'), |
|
| 169 | + (string)$this->l->t('Thursday'), |
|
| 170 | + (string)$this->l->t('Friday'), |
|
| 171 | + (string)$this->l->t('Saturday') |
|
| 172 | + ]), |
|
| 173 | + "dayNamesShort" => json_encode([ |
|
| 174 | + (string)$this->l->t('Sun.'), |
|
| 175 | + (string)$this->l->t('Mon.'), |
|
| 176 | + (string)$this->l->t('Tue.'), |
|
| 177 | + (string)$this->l->t('Wed.'), |
|
| 178 | + (string)$this->l->t('Thu.'), |
|
| 179 | + (string)$this->l->t('Fri.'), |
|
| 180 | + (string)$this->l->t('Sat.') |
|
| 181 | + ]), |
|
| 182 | + "dayNamesMin" => json_encode([ |
|
| 183 | + (string)$this->l->t('Su'), |
|
| 184 | + (string)$this->l->t('Mo'), |
|
| 185 | + (string)$this->l->t('Tu'), |
|
| 186 | + (string)$this->l->t('We'), |
|
| 187 | + (string)$this->l->t('Th'), |
|
| 188 | + (string)$this->l->t('Fr'), |
|
| 189 | + (string)$this->l->t('Sa') |
|
| 190 | + ]), |
|
| 191 | + "monthNames" => json_encode([ |
|
| 192 | + (string)$this->l->t('January'), |
|
| 193 | + (string)$this->l->t('February'), |
|
| 194 | + (string)$this->l->t('March'), |
|
| 195 | + (string)$this->l->t('April'), |
|
| 196 | + (string)$this->l->t('May'), |
|
| 197 | + (string)$this->l->t('June'), |
|
| 198 | + (string)$this->l->t('July'), |
|
| 199 | + (string)$this->l->t('August'), |
|
| 200 | + (string)$this->l->t('September'), |
|
| 201 | + (string)$this->l->t('October'), |
|
| 202 | + (string)$this->l->t('November'), |
|
| 203 | + (string)$this->l->t('December') |
|
| 204 | + ]), |
|
| 205 | + "monthNamesShort" => json_encode([ |
|
| 206 | + (string)$this->l->t('Jan.'), |
|
| 207 | + (string)$this->l->t('Feb.'), |
|
| 208 | + (string)$this->l->t('Mar.'), |
|
| 209 | + (string)$this->l->t('Apr.'), |
|
| 210 | + (string)$this->l->t('May.'), |
|
| 211 | + (string)$this->l->t('Jun.'), |
|
| 212 | + (string)$this->l->t('Jul.'), |
|
| 213 | + (string)$this->l->t('Aug.'), |
|
| 214 | + (string)$this->l->t('Sep.'), |
|
| 215 | + (string)$this->l->t('Oct.'), |
|
| 216 | + (string)$this->l->t('Nov.'), |
|
| 217 | + (string)$this->l->t('Dec.') |
|
| 218 | + ]), |
|
| 219 | + "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
| 220 | + "oc_config" => json_encode([ |
|
| 221 | + 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
| 222 | + 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
| 223 | + 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 224 | + 'versionstring' => \OC_Util::getVersionString(), |
|
| 225 | + 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
| 226 | + 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), |
|
| 227 | + 'modRewriteWorking' => ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'), |
|
| 228 | + 'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)), |
|
| 229 | + 'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)), |
|
| 230 | + 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
| 231 | + ]), |
|
| 232 | + "oc_appconfig" => json_encode([ |
|
| 233 | + 'core' => [ |
|
| 234 | + 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
| 235 | + 'defaultExpireDate' => $defaultExpireDate, |
|
| 236 | + 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
| 237 | + 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
| 238 | + 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
| 239 | + 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
| 240 | + 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
| 241 | + 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
| 242 | + 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
| 243 | + 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() |
|
| 244 | + ] |
|
| 245 | + ]), |
|
| 246 | + "oc_defaults" => json_encode([ |
|
| 247 | + 'entity' => $this->defaults->getEntity(), |
|
| 248 | + 'name' => $this->defaults->getName(), |
|
| 249 | + 'title' => $this->defaults->getTitle(), |
|
| 250 | + 'baseUrl' => $this->defaults->getBaseUrl(), |
|
| 251 | + 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
| 252 | + 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
| 253 | + 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
| 254 | + 'slogan' => $this->defaults->getSlogan(), |
|
| 255 | + 'logoClaim' => '', |
|
| 256 | + 'shortFooter' => $this->defaults->getShortFooter(), |
|
| 257 | + 'longFooter' => $this->defaults->getLongFooter(), |
|
| 258 | + 'folder' => \OC_Util::getTheme(), |
|
| 259 | + ]), |
|
| 260 | + "oc_capabilities" => json_encode($capabilities), |
|
| 261 | + ]; |
|
| 262 | 262 | |
| 263 | - if ($this->currentUser !== null) { |
|
| 264 | - $array['oc_userconfig'] = json_encode([ |
|
| 265 | - 'avatar' => [ |
|
| 266 | - 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
| 267 | - ] |
|
| 268 | - ]); |
|
| 269 | - } |
|
| 263 | + if ($this->currentUser !== null) { |
|
| 264 | + $array['oc_userconfig'] = json_encode([ |
|
| 265 | + 'avatar' => [ |
|
| 266 | + 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
| 267 | + ] |
|
| 268 | + ]); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - // Allow hooks to modify the output values |
|
| 272 | - \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); |
|
| 271 | + // Allow hooks to modify the output values |
|
| 272 | + \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); |
|
| 273 | 273 | |
| 274 | - $result = ''; |
|
| 274 | + $result = ''; |
|
| 275 | 275 | |
| 276 | - // Echo it |
|
| 277 | - foreach ($array as $setting => $value) { |
|
| 278 | - $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
| 279 | - } |
|
| 276 | + // Echo it |
|
| 277 | + foreach ($array as $setting => $value) { |
|
| 278 | + $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - return $result; |
|
| 282 | - } |
|
| 281 | + return $result; |
|
| 282 | + } |
|
| 283 | 283 | } |
@@ -45,228 +45,228 @@ |
||
| 45 | 45 | |
| 46 | 46 | class TemplateLayout extends \OC_Template { |
| 47 | 47 | |
| 48 | - private static $versionHash = ''; |
|
| 48 | + private static $versionHash = ''; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var \OCP\IConfig |
|
| 52 | - */ |
|
| 53 | - private $config; |
|
| 50 | + /** |
|
| 51 | + * @var \OCP\IConfig |
|
| 52 | + */ |
|
| 53 | + private $config; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param string $renderAs |
|
| 57 | - * @param string $appId application id |
|
| 58 | - */ |
|
| 59 | - public function __construct( $renderAs, $appId = '' ) { |
|
| 55 | + /** |
|
| 56 | + * @param string $renderAs |
|
| 57 | + * @param string $appId application id |
|
| 58 | + */ |
|
| 59 | + public function __construct( $renderAs, $appId = '' ) { |
|
| 60 | 60 | |
| 61 | - // yes - should be injected .... |
|
| 62 | - $this->config = \OC::$server->getConfig(); |
|
| 61 | + // yes - should be injected .... |
|
| 62 | + $this->config = \OC::$server->getConfig(); |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | - // Decide which page we show |
|
| 66 | - if($renderAs == 'user') { |
|
| 67 | - parent::__construct( 'core', 'layout.user' ); |
|
| 68 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 69 | - $this->assign('bodyid', 'body-settings'); |
|
| 70 | - }else{ |
|
| 71 | - $this->assign('bodyid', 'body-user'); |
|
| 72 | - } |
|
| 65 | + // Decide which page we show |
|
| 66 | + if($renderAs == 'user') { |
|
| 67 | + parent::__construct( 'core', 'layout.user' ); |
|
| 68 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 69 | + $this->assign('bodyid', 'body-settings'); |
|
| 70 | + }else{ |
|
| 71 | + $this->assign('bodyid', 'body-user'); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - // Code integrity notification |
|
| 75 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
| 76 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 77 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
| 78 | - } |
|
| 74 | + // Code integrity notification |
|
| 75 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
| 76 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
| 77 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // Add navigation entry |
|
| 81 | - $this->assign( 'application', ''); |
|
| 82 | - $this->assign( 'appid', $appId ); |
|
| 83 | - $navigation = \OC_App::getNavigation(); |
|
| 84 | - $this->assign( 'navigation', $navigation); |
|
| 85 | - $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
| 86 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 87 | - foreach($navigation as $entry) { |
|
| 88 | - if ($entry['active']) { |
|
| 89 | - $this->assign( 'application', $entry['name'] ); |
|
| 90 | - break; |
|
| 91 | - } |
|
| 92 | - } |
|
| 80 | + // Add navigation entry |
|
| 81 | + $this->assign( 'application', ''); |
|
| 82 | + $this->assign( 'appid', $appId ); |
|
| 83 | + $navigation = \OC_App::getNavigation(); |
|
| 84 | + $this->assign( 'navigation', $navigation); |
|
| 85 | + $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
| 86 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 87 | + foreach($navigation as $entry) { |
|
| 88 | + if ($entry['active']) { |
|
| 89 | + $this->assign( 'application', $entry['name'] ); |
|
| 90 | + break; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - foreach($settingsNavigation as $entry) { |
|
| 95 | - if ($entry['active']) { |
|
| 96 | - $this->assign( 'application', $entry['name'] ); |
|
| 97 | - break; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - $userDisplayName = \OC_User::getDisplayName(); |
|
| 101 | - $this->assign('user_displayname', $userDisplayName); |
|
| 102 | - $this->assign('user_uid', \OC_User::getUser()); |
|
| 94 | + foreach($settingsNavigation as $entry) { |
|
| 95 | + if ($entry['active']) { |
|
| 96 | + $this->assign( 'application', $entry['name'] ); |
|
| 97 | + break; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + $userDisplayName = \OC_User::getDisplayName(); |
|
| 101 | + $this->assign('user_displayname', $userDisplayName); |
|
| 102 | + $this->assign('user_uid', \OC_User::getUser()); |
|
| 103 | 103 | |
| 104 | - if (\OC_User::getUser() === false) { |
|
| 105 | - $this->assign('userAvatarSet', false); |
|
| 106 | - } else { |
|
| 107 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
| 108 | - $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
| 109 | - } |
|
| 104 | + if (\OC_User::getUser() === false) { |
|
| 105 | + $this->assign('userAvatarSet', false); |
|
| 106 | + } else { |
|
| 107 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
| 108 | + $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - } else if ($renderAs == 'error') { |
|
| 112 | - parent::__construct('core', 'layout.guest', '', false); |
|
| 113 | - $this->assign('bodyid', 'body-login'); |
|
| 114 | - } else if ($renderAs == 'guest') { |
|
| 115 | - parent::__construct('core', 'layout.guest'); |
|
| 116 | - $this->assign('bodyid', 'body-login'); |
|
| 117 | - } else { |
|
| 118 | - parent::__construct('core', 'layout.base'); |
|
| 111 | + } else if ($renderAs == 'error') { |
|
| 112 | + parent::__construct('core', 'layout.guest', '', false); |
|
| 113 | + $this->assign('bodyid', 'body-login'); |
|
| 114 | + } else if ($renderAs == 'guest') { |
|
| 115 | + parent::__construct('core', 'layout.guest'); |
|
| 116 | + $this->assign('bodyid', 'body-login'); |
|
| 117 | + } else { |
|
| 118 | + parent::__construct('core', 'layout.base'); |
|
| 119 | 119 | |
| 120 | - } |
|
| 121 | - // Send the language to our layouts |
|
| 122 | - $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
| 120 | + } |
|
| 121 | + // Send the language to our layouts |
|
| 122 | + $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
| 123 | 123 | |
| 124 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 125 | - if (empty(self::$versionHash)) { |
|
| 126 | - $v = \OC_App::getAppVersions(); |
|
| 127 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
| 128 | - self::$versionHash = md5(implode(',', $v)); |
|
| 129 | - } |
|
| 130 | - } else { |
|
| 131 | - self::$versionHash = md5('not installed'); |
|
| 132 | - } |
|
| 124 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 125 | + if (empty(self::$versionHash)) { |
|
| 126 | + $v = \OC_App::getAppVersions(); |
|
| 127 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
| 128 | + self::$versionHash = md5(implode(',', $v)); |
|
| 129 | + } |
|
| 130 | + } else { |
|
| 131 | + self::$versionHash = md5('not installed'); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - // Add the js files |
|
| 135 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
| 136 | - $this->assign('jsfiles', array()); |
|
| 137 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
| 138 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
| 139 | - $jsConfigHelper = new JSConfigHelper( |
|
| 140 | - \OC::$server->getL10N('core'), |
|
| 141 | - \OC::$server->query(Defaults::class), |
|
| 142 | - \OC::$server->getAppManager(), |
|
| 143 | - \OC::$server->getSession(), |
|
| 144 | - \OC::$server->getUserSession()->getUser(), |
|
| 145 | - \OC::$server->getConfig(), |
|
| 146 | - \OC::$server->getGroupManager(), |
|
| 147 | - \OC::$server->getIniWrapper(), |
|
| 148 | - \OC::$server->getURLGenerator(), |
|
| 149 | - \OC::$server->getCapabilitiesManager() |
|
| 150 | - ); |
|
| 151 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
| 152 | - } else { |
|
| 153 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - foreach($jsFiles as $info) { |
|
| 157 | - $web = $info[1]; |
|
| 158 | - $file = $info[2]; |
|
| 159 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 160 | - } |
|
| 134 | + // Add the js files |
|
| 135 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
| 136 | + $this->assign('jsfiles', array()); |
|
| 137 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
| 138 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
| 139 | + $jsConfigHelper = new JSConfigHelper( |
|
| 140 | + \OC::$server->getL10N('core'), |
|
| 141 | + \OC::$server->query(Defaults::class), |
|
| 142 | + \OC::$server->getAppManager(), |
|
| 143 | + \OC::$server->getSession(), |
|
| 144 | + \OC::$server->getUserSession()->getUser(), |
|
| 145 | + \OC::$server->getConfig(), |
|
| 146 | + \OC::$server->getGroupManager(), |
|
| 147 | + \OC::$server->getIniWrapper(), |
|
| 148 | + \OC::$server->getURLGenerator(), |
|
| 149 | + \OC::$server->getCapabilitiesManager() |
|
| 150 | + ); |
|
| 151 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
| 152 | + } else { |
|
| 153 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + foreach($jsFiles as $info) { |
|
| 157 | + $web = $info[1]; |
|
| 158 | + $file = $info[2]; |
|
| 159 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - try { |
|
| 163 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
| 164 | - } catch (\Exception $e) { |
|
| 165 | - $pathInfo = ''; |
|
| 166 | - } |
|
| 162 | + try { |
|
| 163 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
| 164 | + } catch (\Exception $e) { |
|
| 165 | + $pathInfo = ''; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - // Do not initialise scss appdata until we have a fully installed instance |
|
| 169 | - // Do not load scss for update, errors, installation or login page |
|
| 170 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 171 | - && !\OCP\Util::needUpgrade() |
|
| 172 | - && $pathInfo !== '' |
|
| 173 | - && !preg_match('/^\/login/', $pathInfo)) { |
|
| 174 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
| 175 | - } else { |
|
| 176 | - // If we ignore the scss compiler, |
|
| 177 | - // we need to load the guest css fallback |
|
| 178 | - \OC_Util::addStyle('guest'); |
|
| 179 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
| 180 | - } |
|
| 168 | + // Do not initialise scss appdata until we have a fully installed instance |
|
| 169 | + // Do not load scss for update, errors, installation or login page |
|
| 170 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 171 | + && !\OCP\Util::needUpgrade() |
|
| 172 | + && $pathInfo !== '' |
|
| 173 | + && !preg_match('/^\/login/', $pathInfo)) { |
|
| 174 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
| 175 | + } else { |
|
| 176 | + // If we ignore the scss compiler, |
|
| 177 | + // we need to load the guest css fallback |
|
| 178 | + \OC_Util::addStyle('guest'); |
|
| 179 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $this->assign('cssfiles', array()); |
|
| 183 | - $this->assign('printcssfiles', []); |
|
| 184 | - $this->assign('versionHash', self::$versionHash); |
|
| 185 | - foreach($cssFiles as $info) { |
|
| 186 | - $web = $info[1]; |
|
| 187 | - $file = $info[2]; |
|
| 182 | + $this->assign('cssfiles', array()); |
|
| 183 | + $this->assign('printcssfiles', []); |
|
| 184 | + $this->assign('versionHash', self::$versionHash); |
|
| 185 | + foreach($cssFiles as $info) { |
|
| 186 | + $web = $info[1]; |
|
| 187 | + $file = $info[2]; |
|
| 188 | 188 | |
| 189 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
| 190 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 191 | - } else { |
|
| 192 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - } |
|
| 189 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
| 190 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 191 | + } else { |
|
| 192 | + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - protected function getVersionHashSuffix() { |
|
| 198 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 199 | - // allows chrome workspace mapping in debug mode |
|
| 200 | - return ""; |
|
| 201 | - } |
|
| 202 | - if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
|
| 203 | - return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 204 | - } |
|
| 205 | - return '?v=' . self::$versionHash; |
|
| 206 | - } |
|
| 197 | + protected function getVersionHashSuffix() { |
|
| 198 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 199 | + // allows chrome workspace mapping in debug mode |
|
| 200 | + return ""; |
|
| 201 | + } |
|
| 202 | + if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
|
| 203 | + return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 204 | + } |
|
| 205 | + return '?v=' . self::$versionHash; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * @param array $styles |
|
| 210 | - * @return array |
|
| 211 | - */ |
|
| 212 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
| 213 | - // Read the selected theme from the config file |
|
| 214 | - $theme = \OC_Util::getTheme(); |
|
| 208 | + /** |
|
| 209 | + * @param array $styles |
|
| 210 | + * @return array |
|
| 211 | + */ |
|
| 212 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
| 213 | + // Read the selected theme from the config file |
|
| 214 | + $theme = \OC_Util::getTheme(); |
|
| 215 | 215 | |
| 216 | - if($compileScss) { |
|
| 217 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
| 218 | - } else { |
|
| 219 | - $SCSSCacher = null; |
|
| 220 | - } |
|
| 216 | + if($compileScss) { |
|
| 217 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
| 218 | + } else { |
|
| 219 | + $SCSSCacher = null; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - $locator = new \OC\Template\CSSResourceLocator( |
|
| 223 | - \OC::$server->getLogger(), |
|
| 224 | - $theme, |
|
| 225 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 226 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 227 | - $SCSSCacher |
|
| 228 | - ); |
|
| 229 | - $locator->find($styles); |
|
| 230 | - return $locator->getResources(); |
|
| 231 | - } |
|
| 222 | + $locator = new \OC\Template\CSSResourceLocator( |
|
| 223 | + \OC::$server->getLogger(), |
|
| 224 | + $theme, |
|
| 225 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 226 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 227 | + $SCSSCacher |
|
| 228 | + ); |
|
| 229 | + $locator->find($styles); |
|
| 230 | + return $locator->getResources(); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * @param array $scripts |
|
| 235 | - * @return array |
|
| 236 | - */ |
|
| 237 | - static public function findJavascriptFiles($scripts) { |
|
| 238 | - // Read the selected theme from the config file |
|
| 239 | - $theme = \OC_Util::getTheme(); |
|
| 233 | + /** |
|
| 234 | + * @param array $scripts |
|
| 235 | + * @return array |
|
| 236 | + */ |
|
| 237 | + static public function findJavascriptFiles($scripts) { |
|
| 238 | + // Read the selected theme from the config file |
|
| 239 | + $theme = \OC_Util::getTheme(); |
|
| 240 | 240 | |
| 241 | - $locator = new \OC\Template\JSResourceLocator( |
|
| 242 | - \OC::$server->getLogger(), |
|
| 243 | - $theme, |
|
| 244 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 245 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 246 | - new JSCombiner( |
|
| 247 | - \OC::$server->getAppDataDir('js'), |
|
| 248 | - \OC::$server->getURLGenerator(), |
|
| 249 | - \OC::$server->getMemCacheFactory()->create('JS'), |
|
| 250 | - \OC::$server->getSystemConfig(), |
|
| 251 | - \OC::$server->getLogger() |
|
| 252 | - ) |
|
| 253 | - ); |
|
| 254 | - $locator->find($scripts); |
|
| 255 | - return $locator->getResources(); |
|
| 256 | - } |
|
| 241 | + $locator = new \OC\Template\JSResourceLocator( |
|
| 242 | + \OC::$server->getLogger(), |
|
| 243 | + $theme, |
|
| 244 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 245 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 246 | + new JSCombiner( |
|
| 247 | + \OC::$server->getAppDataDir('js'), |
|
| 248 | + \OC::$server->getURLGenerator(), |
|
| 249 | + \OC::$server->getMemCacheFactory()->create('JS'), |
|
| 250 | + \OC::$server->getSystemConfig(), |
|
| 251 | + \OC::$server->getLogger() |
|
| 252 | + ) |
|
| 253 | + ); |
|
| 254 | + $locator->find($scripts); |
|
| 255 | + return $locator->getResources(); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
| 260 | - * @param string $filePath Absolute path |
|
| 261 | - * @return string Relative path |
|
| 262 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
| 263 | - */ |
|
| 264 | - public static function convertToRelativePath($filePath) { |
|
| 265 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
| 266 | - if(count($relativePath) !== 2) { |
|
| 267 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
| 268 | - } |
|
| 258 | + /** |
|
| 259 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
| 260 | + * @param string $filePath Absolute path |
|
| 261 | + * @return string Relative path |
|
| 262 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
| 263 | + */ |
|
| 264 | + public static function convertToRelativePath($filePath) { |
|
| 265 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
| 266 | + if(count($relativePath) !== 2) { |
|
| 267 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - return $relativePath[1]; |
|
| 271 | - } |
|
| 270 | + return $relativePath[1]; |
|
| 271 | + } |
|
| 272 | 272 | } |
@@ -49,505 +49,505 @@ |
||
| 49 | 49 | use OCP\Settings\ISection; |
| 50 | 50 | |
| 51 | 51 | class Manager implements IManager { |
| 52 | - /** @var ILogger */ |
|
| 53 | - private $log; |
|
| 54 | - /** @var IDBConnection */ |
|
| 55 | - private $dbc; |
|
| 56 | - /** @var Mapper */ |
|
| 57 | - private $mapper; |
|
| 58 | - /** @var IL10N */ |
|
| 59 | - private $l; |
|
| 60 | - /** @var IConfig */ |
|
| 61 | - private $config; |
|
| 62 | - /** @var EncryptionManager */ |
|
| 63 | - private $encryptionManager; |
|
| 64 | - /** @var IUserManager */ |
|
| 65 | - private $userManager; |
|
| 66 | - /** @var ILockingProvider */ |
|
| 67 | - private $lockingProvider; |
|
| 68 | - /** @var IRequest */ |
|
| 69 | - private $request; |
|
| 70 | - /** @var IURLGenerator */ |
|
| 71 | - private $url; |
|
| 72 | - /** @var AccountManager */ |
|
| 73 | - private $accountManager; |
|
| 74 | - /** @var IGroupManager */ |
|
| 75 | - private $groupManager; |
|
| 76 | - /** @var IFactory */ |
|
| 77 | - private $l10nFactory; |
|
| 78 | - /** @var \OC_Defaults */ |
|
| 79 | - private $defaults; |
|
| 80 | - /** @var IAppManager */ |
|
| 81 | - private $appManager; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param ILogger $log |
|
| 85 | - * @param IDBConnection $dbc |
|
| 86 | - * @param IL10N $l |
|
| 87 | - * @param IConfig $config |
|
| 88 | - * @param EncryptionManager $encryptionManager |
|
| 89 | - * @param IUserManager $userManager |
|
| 90 | - * @param ILockingProvider $lockingProvider |
|
| 91 | - * @param IRequest $request |
|
| 92 | - * @param Mapper $mapper |
|
| 93 | - * @param IURLGenerator $url |
|
| 94 | - * @param AccountManager $accountManager |
|
| 95 | - * @param IGroupManager $groupManager |
|
| 96 | - * @param IFactory $l10nFactory |
|
| 97 | - * @param \OC_Defaults $defaults |
|
| 98 | - */ |
|
| 99 | - public function __construct( |
|
| 100 | - ILogger $log, |
|
| 101 | - IDBConnection $dbc, |
|
| 102 | - IL10N $l, |
|
| 103 | - IConfig $config, |
|
| 104 | - EncryptionManager $encryptionManager, |
|
| 105 | - IUserManager $userManager, |
|
| 106 | - ILockingProvider $lockingProvider, |
|
| 107 | - IRequest $request, |
|
| 108 | - Mapper $mapper, |
|
| 109 | - IURLGenerator $url, |
|
| 110 | - AccountManager $accountManager, |
|
| 111 | - IGroupManager $groupManager, |
|
| 112 | - IFactory $l10nFactory, |
|
| 113 | - \OC_Defaults $defaults, |
|
| 114 | - IAppManager $appManager |
|
| 115 | - ) { |
|
| 116 | - $this->log = $log; |
|
| 117 | - $this->dbc = $dbc; |
|
| 118 | - $this->mapper = $mapper; |
|
| 119 | - $this->l = $l; |
|
| 120 | - $this->config = $config; |
|
| 121 | - $this->encryptionManager = $encryptionManager; |
|
| 122 | - $this->userManager = $userManager; |
|
| 123 | - $this->lockingProvider = $lockingProvider; |
|
| 124 | - $this->request = $request; |
|
| 125 | - $this->url = $url; |
|
| 126 | - $this->accountManager = $accountManager; |
|
| 127 | - $this->groupManager = $groupManager; |
|
| 128 | - $this->l10nFactory = $l10nFactory; |
|
| 129 | - $this->defaults = $defaults; |
|
| 130 | - $this->appManager = $appManager; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @inheritdoc |
|
| 135 | - */ |
|
| 136 | - public function setupSettings(array $settings) { |
|
| 137 | - if (!empty($settings[IManager::KEY_ADMIN_SECTION])) { |
|
| 138 | - foreach ($settings[IManager::KEY_ADMIN_SECTION] as $className) { |
|
| 139 | - $this->setupSectionEntry($className, 'admin'); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - if (!empty($settings[IManager::KEY_ADMIN_SETTINGS])) { |
|
| 143 | - foreach ($settings[IManager::KEY_ADMIN_SETTINGS] as $className) { |
|
| 144 | - $this->setupSettingsEntry($className, 'admin'); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - if (!empty($settings[IManager::KEY_PERSONAL_SECTION])) { |
|
| 149 | - foreach ($settings[IManager::KEY_PERSONAL_SECTION] as $className) { |
|
| 150 | - $this->setupSectionEntry($className, 'personal'); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - if (!empty($settings[IManager::KEY_PERSONAL_SETTINGS])) { |
|
| 154 | - foreach ($settings[IManager::KEY_PERSONAL_SETTINGS] as $className) { |
|
| 155 | - $this->setupSettingsEntry($className, 'personal'); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * attempts to remove an apps section and/or settings entry. A listener is |
|
| 162 | - * added centrally making sure that this method is called ones an app was |
|
| 163 | - * disabled. |
|
| 164 | - * |
|
| 165 | - * @param string $appId |
|
| 166 | - * @since 9.1.0 |
|
| 167 | - */ |
|
| 168 | - public function onAppDisabled($appId) { |
|
| 169 | - $appInfo = \OC_App::getAppInfo($appId); // hello static legacy |
|
| 170 | - |
|
| 171 | - if (!empty($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { |
|
| 172 | - foreach ($appInfo['settings'][IManager::KEY_ADMIN_SECTION] as $className) { |
|
| 173 | - $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($className, '\\')); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - if (!empty($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { |
|
| 177 | - foreach ($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS] as $className) { |
|
| 178 | - $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($className, '\\')); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (!empty($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) { |
|
| 183 | - foreach ($appInfo['settings'][IManager::KEY_PERSONAL_SECTION] as $className) { |
|
| 184 | - $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($className, '\\')); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - if (!empty($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) { |
|
| 188 | - foreach ($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS] as $className) { |
|
| 189 | - $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($className, '\\')); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - public function checkForOrphanedClassNames() { |
|
| 195 | - $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS]; |
|
| 196 | - foreach ($tables as $table) { |
|
| 197 | - $classes = $this->mapper->getClasses($table); |
|
| 198 | - foreach ($classes as $className) { |
|
| 199 | - try { |
|
| 200 | - \OC::$server->query($className); |
|
| 201 | - } catch (QueryException $e) { |
|
| 202 | - $this->mapper->remove($table, $className); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param string $sectionClassName |
|
| 210 | - * @param string $type either 'admin' or 'personal' |
|
| 211 | - */ |
|
| 212 | - private function setupSectionEntry($sectionClassName, $type) { |
|
| 213 | - if (!class_exists($sectionClassName)) { |
|
| 214 | - $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName); |
|
| 215 | - return; |
|
| 216 | - } |
|
| 217 | - try { |
|
| 218 | - $section = $this->query($sectionClassName); |
|
| 219 | - } catch (QueryException $e) { |
|
| 220 | - // cancel |
|
| 221 | - return; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - if (!$section instanceof ISection) { |
|
| 225 | - $this->log->error( |
|
| 226 | - ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
| 227 | - ['class' => $sectionClassName] |
|
| 228 | - ); |
|
| 229 | - return; |
|
| 230 | - } |
|
| 231 | - $table = $this->getSectionTableForType($type); |
|
| 232 | - if(!$this->hasSection(get_class($section), $table)) { |
|
| 233 | - $this->addSection($section, $table); |
|
| 234 | - } else { |
|
| 235 | - $this->updateSection($section, $table); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - private function addSection(ISection $section, $table) { |
|
| 240 | - $this->mapper->add($table, [ |
|
| 241 | - 'id' => $section->getID(), |
|
| 242 | - 'class' => get_class($section), |
|
| 243 | - 'priority' => $section->getPriority(), |
|
| 244 | - ]); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - private function addSettings(ISettings $settings, $table) { |
|
| 248 | - $this->mapper->add($table, [ |
|
| 249 | - 'class' => get_class($settings), |
|
| 250 | - 'section' => $settings->getSection(), |
|
| 251 | - 'priority' => $settings->getPriority(), |
|
| 252 | - ]); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - private function updateSettings(ISettings $settings, $table) { |
|
| 256 | - $this->mapper->update( |
|
| 257 | - $table, |
|
| 258 | - 'class', |
|
| 259 | - get_class($settings), |
|
| 260 | - [ |
|
| 261 | - 'section' => $settings->getSection(), |
|
| 262 | - 'priority' => $settings->getPriority(), |
|
| 263 | - ] |
|
| 264 | - ); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - private function updateSection(ISection $section, $table) { |
|
| 268 | - $this->mapper->update( |
|
| 269 | - $table, |
|
| 270 | - 'class', |
|
| 271 | - get_class($section), |
|
| 272 | - [ |
|
| 273 | - 'id' => $section->getID(), |
|
| 274 | - 'priority' => $section->getPriority(), |
|
| 275 | - ] |
|
| 276 | - ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @param string $className |
|
| 281 | - * @param string $table |
|
| 282 | - * @return bool |
|
| 283 | - */ |
|
| 284 | - private function hasSection($className, $table) { |
|
| 285 | - return $this->mapper->has($table, $className); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @param string $className |
|
| 290 | - * @return bool |
|
| 291 | - */ |
|
| 292 | - private function hasSettings($className, $table) { |
|
| 293 | - return $this->mapper->has($table, $className); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - private function setupSettingsEntry($settingsClassName, $type) { |
|
| 297 | - if (!class_exists($settingsClassName)) { |
|
| 298 | - $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
|
| 299 | - return; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - try { |
|
| 303 | - /** @var ISettings $settings */ |
|
| 304 | - $settings = $this->query($settingsClassName); |
|
| 305 | - } catch (QueryException $e) { |
|
| 306 | - // cancel |
|
| 307 | - return; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - if (!$settings instanceof ISettings) { |
|
| 311 | - $this->log->error( |
|
| 312 | - ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
| 313 | - ['class' => $settingsClassName] |
|
| 314 | - ); |
|
| 315 | - return; |
|
| 316 | - } |
|
| 317 | - $table = $this->getSettingsTableForType($type); |
|
| 318 | - if (!$this->hasSettings(get_class($settings), $table)) { |
|
| 319 | - $this->addSettings($settings, $table); |
|
| 320 | - } else { |
|
| 321 | - $this->updateSettings($settings, $table); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - private function getSectionTableForType($type) { |
|
| 326 | - if($type === 'admin') { |
|
| 327 | - return Mapper::TABLE_ADMIN_SECTIONS; |
|
| 328 | - } else if($type === 'personal') { |
|
| 329 | - return Mapper::TABLE_PERSONAL_SECTIONS; |
|
| 330 | - } |
|
| 331 | - throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - private function getSettingsTableForType($type) { |
|
| 335 | - if($type === 'admin') { |
|
| 336 | - return Mapper::TABLE_ADMIN_SETTINGS; |
|
| 337 | - } else if($type === 'personal') { |
|
| 338 | - return Mapper::TABLE_PERSONAL_SETTINGS; |
|
| 339 | - } |
|
| 340 | - throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - private function query($className) { |
|
| 344 | - try { |
|
| 345 | - return \OC::$server->query($className); |
|
| 346 | - } catch (QueryException $e) { |
|
| 347 | - $this->log->logException($e); |
|
| 348 | - throw $e; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @inheritdoc |
|
| 354 | - */ |
|
| 355 | - public function getAdminSections() { |
|
| 356 | - // built-in sections |
|
| 357 | - $sections = [ |
|
| 358 | - 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
| 359 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
| 360 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 361 | - 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 362 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 363 | - 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
| 364 | - ]; |
|
| 365 | - |
|
| 366 | - $rows = $this->mapper->getAdminSectionsFromDB(); |
|
| 367 | - |
|
| 368 | - foreach ($rows as $row) { |
|
| 369 | - if (!isset($sections[$row['priority']])) { |
|
| 370 | - $sections[$row['priority']] = []; |
|
| 371 | - } |
|
| 372 | - try { |
|
| 373 | - $sections[$row['priority']][] = $this->query($row['class']); |
|
| 374 | - } catch (QueryException $e) { |
|
| 375 | - // skip |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - ksort($sections); |
|
| 380 | - |
|
| 381 | - return $sections; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * @param string $section |
|
| 386 | - * @return ISection[] |
|
| 387 | - */ |
|
| 388 | - private function getBuiltInAdminSettings($section) { |
|
| 389 | - $forms = []; |
|
| 390 | - try { |
|
| 391 | - if ($section === 'server') { |
|
| 392 | - /** @var ISettings $form */ |
|
| 393 | - $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
| 394 | - $forms[$form->getPriority()] = [$form]; |
|
| 395 | - $form = new Admin\ServerDevNotice(); |
|
| 396 | - $forms[$form->getPriority()] = [$form]; |
|
| 397 | - } |
|
| 398 | - if ($section === 'encryption') { |
|
| 399 | - /** @var ISettings $form */ |
|
| 400 | - $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
| 401 | - $forms[$form->getPriority()] = [$form]; |
|
| 402 | - } |
|
| 403 | - if ($section === 'sharing') { |
|
| 404 | - /** @var ISettings $form */ |
|
| 405 | - $form = new Admin\Sharing($this->config, $this->l); |
|
| 406 | - $forms[$form->getPriority()] = [$form]; |
|
| 407 | - } |
|
| 408 | - if ($section === 'additional') { |
|
| 409 | - /** @var ISettings $form */ |
|
| 410 | - $form = new Admin\Additional($this->config); |
|
| 411 | - $forms[$form->getPriority()] = [$form]; |
|
| 412 | - } |
|
| 413 | - if ($section === 'tips-tricks') { |
|
| 414 | - /** @var ISettings $form */ |
|
| 415 | - $form = new Admin\TipsTricks($this->config); |
|
| 416 | - $forms[$form->getPriority()] = [$form]; |
|
| 417 | - } |
|
| 418 | - } catch (QueryException $e) { |
|
| 419 | - // skip |
|
| 420 | - } |
|
| 421 | - return $forms; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * @param string $section |
|
| 426 | - * @return ISection[] |
|
| 427 | - */ |
|
| 428 | - private function getBuiltInPersonalSettings($section) { |
|
| 429 | - $forms = []; |
|
| 430 | - try { |
|
| 431 | - if ($section === 'personal-info') { |
|
| 432 | - /** @var ISettings $form */ |
|
| 433 | - $form = new Personal\PersonalInfo( |
|
| 434 | - $this->config, |
|
| 435 | - $this->userManager, |
|
| 436 | - $this->groupManager, |
|
| 437 | - $this->accountManager, |
|
| 438 | - $this->appManager, |
|
| 439 | - $this->l10nFactory, |
|
| 440 | - $this->l |
|
| 441 | - ); |
|
| 442 | - $forms[$form->getPriority()] = [$form]; |
|
| 443 | - } |
|
| 444 | - if($section === 'security') { |
|
| 445 | - /** @var ISettings $form */ |
|
| 446 | - $form = new Personal\Security(); |
|
| 447 | - $forms[$form->getPriority()] = [$form]; |
|
| 448 | - } |
|
| 449 | - if ($section === 'additional') { |
|
| 450 | - /** @var ISettings $form */ |
|
| 451 | - $form = new Personal\Additional($this->config); |
|
| 452 | - $forms[$form->getPriority()] = [$form]; |
|
| 453 | - } |
|
| 454 | - } catch (QueryException $e) { |
|
| 455 | - // skip |
|
| 456 | - } |
|
| 457 | - return $forms; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @inheritdoc |
|
| 462 | - */ |
|
| 463 | - public function getAdminSettings($section) { |
|
| 464 | - $settings = $this->getBuiltInAdminSettings($section); |
|
| 465 | - $dbRows = $this->mapper->getAdminSettingsFromDB($section); |
|
| 466 | - |
|
| 467 | - foreach ($dbRows as $row) { |
|
| 468 | - if (!isset($settings[$row['priority']])) { |
|
| 469 | - $settings[$row['priority']] = []; |
|
| 470 | - } |
|
| 471 | - try { |
|
| 472 | - $settings[$row['priority']][] = $this->query($row['class']); |
|
| 473 | - } catch (QueryException $e) { |
|
| 474 | - // skip |
|
| 475 | - } catch (AutoloadNotAllowedException $e) { |
|
| 476 | - // skip error and remove remnant of disabled app |
|
| 477 | - $this->log->warning('Orphan setting entry will be removed from admin_settings: ' . json_encode($row)); |
|
| 478 | - $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, $row['class']); |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - ksort($settings); |
|
| 483 | - return $settings; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @inheritdoc |
|
| 488 | - */ |
|
| 489 | - public function getPersonalSections() { |
|
| 490 | - $sections = [ |
|
| 491 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
| 492 | - 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
| 493 | - 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
| 494 | - ]; |
|
| 495 | - |
|
| 496 | - $legacyForms = \OC_App::getForms('personal'); |
|
| 497 | - if(count($legacyForms) > 0 && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
| 498 | - $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - $rows = $this->mapper->getPersonalSectionsFromDB(); |
|
| 502 | - |
|
| 503 | - foreach ($rows as $row) { |
|
| 504 | - if (!isset($sections[$row['priority']])) { |
|
| 505 | - $sections[$row['priority']] = []; |
|
| 506 | - } |
|
| 507 | - try { |
|
| 508 | - $sections[$row['priority']][] = $this->query($row['class']); |
|
| 509 | - } catch (QueryException $e) { |
|
| 510 | - // skip |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - ksort($sections); |
|
| 515 | - |
|
| 516 | - return $sections; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * @param $forms |
|
| 521 | - * @return bool |
|
| 522 | - */ |
|
| 523 | - private function hasLegacyPersonalSettingsToRender($forms) { |
|
| 524 | - foreach ($forms as $form) { |
|
| 525 | - if(trim($form) !== '') { |
|
| 526 | - return true; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - return false; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * @inheritdoc |
|
| 534 | - */ |
|
| 535 | - public function getPersonalSettings($section) { |
|
| 536 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
| 537 | - $dbRows = $this->mapper->getPersonalSettingsFromDB($section); |
|
| 538 | - |
|
| 539 | - foreach ($dbRows as $row) { |
|
| 540 | - if (!isset($settings[$row['priority']])) { |
|
| 541 | - $settings[$row['priority']] = []; |
|
| 542 | - } |
|
| 543 | - try { |
|
| 544 | - $settings[$row['priority']][] = $this->query($row['class']); |
|
| 545 | - } catch (QueryException $e) { |
|
| 546 | - // skip |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - ksort($settings); |
|
| 551 | - return $settings; |
|
| 552 | - } |
|
| 52 | + /** @var ILogger */ |
|
| 53 | + private $log; |
|
| 54 | + /** @var IDBConnection */ |
|
| 55 | + private $dbc; |
|
| 56 | + /** @var Mapper */ |
|
| 57 | + private $mapper; |
|
| 58 | + /** @var IL10N */ |
|
| 59 | + private $l; |
|
| 60 | + /** @var IConfig */ |
|
| 61 | + private $config; |
|
| 62 | + /** @var EncryptionManager */ |
|
| 63 | + private $encryptionManager; |
|
| 64 | + /** @var IUserManager */ |
|
| 65 | + private $userManager; |
|
| 66 | + /** @var ILockingProvider */ |
|
| 67 | + private $lockingProvider; |
|
| 68 | + /** @var IRequest */ |
|
| 69 | + private $request; |
|
| 70 | + /** @var IURLGenerator */ |
|
| 71 | + private $url; |
|
| 72 | + /** @var AccountManager */ |
|
| 73 | + private $accountManager; |
|
| 74 | + /** @var IGroupManager */ |
|
| 75 | + private $groupManager; |
|
| 76 | + /** @var IFactory */ |
|
| 77 | + private $l10nFactory; |
|
| 78 | + /** @var \OC_Defaults */ |
|
| 79 | + private $defaults; |
|
| 80 | + /** @var IAppManager */ |
|
| 81 | + private $appManager; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param ILogger $log |
|
| 85 | + * @param IDBConnection $dbc |
|
| 86 | + * @param IL10N $l |
|
| 87 | + * @param IConfig $config |
|
| 88 | + * @param EncryptionManager $encryptionManager |
|
| 89 | + * @param IUserManager $userManager |
|
| 90 | + * @param ILockingProvider $lockingProvider |
|
| 91 | + * @param IRequest $request |
|
| 92 | + * @param Mapper $mapper |
|
| 93 | + * @param IURLGenerator $url |
|
| 94 | + * @param AccountManager $accountManager |
|
| 95 | + * @param IGroupManager $groupManager |
|
| 96 | + * @param IFactory $l10nFactory |
|
| 97 | + * @param \OC_Defaults $defaults |
|
| 98 | + */ |
|
| 99 | + public function __construct( |
|
| 100 | + ILogger $log, |
|
| 101 | + IDBConnection $dbc, |
|
| 102 | + IL10N $l, |
|
| 103 | + IConfig $config, |
|
| 104 | + EncryptionManager $encryptionManager, |
|
| 105 | + IUserManager $userManager, |
|
| 106 | + ILockingProvider $lockingProvider, |
|
| 107 | + IRequest $request, |
|
| 108 | + Mapper $mapper, |
|
| 109 | + IURLGenerator $url, |
|
| 110 | + AccountManager $accountManager, |
|
| 111 | + IGroupManager $groupManager, |
|
| 112 | + IFactory $l10nFactory, |
|
| 113 | + \OC_Defaults $defaults, |
|
| 114 | + IAppManager $appManager |
|
| 115 | + ) { |
|
| 116 | + $this->log = $log; |
|
| 117 | + $this->dbc = $dbc; |
|
| 118 | + $this->mapper = $mapper; |
|
| 119 | + $this->l = $l; |
|
| 120 | + $this->config = $config; |
|
| 121 | + $this->encryptionManager = $encryptionManager; |
|
| 122 | + $this->userManager = $userManager; |
|
| 123 | + $this->lockingProvider = $lockingProvider; |
|
| 124 | + $this->request = $request; |
|
| 125 | + $this->url = $url; |
|
| 126 | + $this->accountManager = $accountManager; |
|
| 127 | + $this->groupManager = $groupManager; |
|
| 128 | + $this->l10nFactory = $l10nFactory; |
|
| 129 | + $this->defaults = $defaults; |
|
| 130 | + $this->appManager = $appManager; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @inheritdoc |
|
| 135 | + */ |
|
| 136 | + public function setupSettings(array $settings) { |
|
| 137 | + if (!empty($settings[IManager::KEY_ADMIN_SECTION])) { |
|
| 138 | + foreach ($settings[IManager::KEY_ADMIN_SECTION] as $className) { |
|
| 139 | + $this->setupSectionEntry($className, 'admin'); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + if (!empty($settings[IManager::KEY_ADMIN_SETTINGS])) { |
|
| 143 | + foreach ($settings[IManager::KEY_ADMIN_SETTINGS] as $className) { |
|
| 144 | + $this->setupSettingsEntry($className, 'admin'); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + if (!empty($settings[IManager::KEY_PERSONAL_SECTION])) { |
|
| 149 | + foreach ($settings[IManager::KEY_PERSONAL_SECTION] as $className) { |
|
| 150 | + $this->setupSectionEntry($className, 'personal'); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + if (!empty($settings[IManager::KEY_PERSONAL_SETTINGS])) { |
|
| 154 | + foreach ($settings[IManager::KEY_PERSONAL_SETTINGS] as $className) { |
|
| 155 | + $this->setupSettingsEntry($className, 'personal'); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * attempts to remove an apps section and/or settings entry. A listener is |
|
| 162 | + * added centrally making sure that this method is called ones an app was |
|
| 163 | + * disabled. |
|
| 164 | + * |
|
| 165 | + * @param string $appId |
|
| 166 | + * @since 9.1.0 |
|
| 167 | + */ |
|
| 168 | + public function onAppDisabled($appId) { |
|
| 169 | + $appInfo = \OC_App::getAppInfo($appId); // hello static legacy |
|
| 170 | + |
|
| 171 | + if (!empty($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { |
|
| 172 | + foreach ($appInfo['settings'][IManager::KEY_ADMIN_SECTION] as $className) { |
|
| 173 | + $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($className, '\\')); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + if (!empty($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { |
|
| 177 | + foreach ($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS] as $className) { |
|
| 178 | + $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($className, '\\')); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (!empty($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) { |
|
| 183 | + foreach ($appInfo['settings'][IManager::KEY_PERSONAL_SECTION] as $className) { |
|
| 184 | + $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($className, '\\')); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + if (!empty($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) { |
|
| 188 | + foreach ($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS] as $className) { |
|
| 189 | + $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($className, '\\')); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + public function checkForOrphanedClassNames() { |
|
| 195 | + $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS]; |
|
| 196 | + foreach ($tables as $table) { |
|
| 197 | + $classes = $this->mapper->getClasses($table); |
|
| 198 | + foreach ($classes as $className) { |
|
| 199 | + try { |
|
| 200 | + \OC::$server->query($className); |
|
| 201 | + } catch (QueryException $e) { |
|
| 202 | + $this->mapper->remove($table, $className); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param string $sectionClassName |
|
| 210 | + * @param string $type either 'admin' or 'personal' |
|
| 211 | + */ |
|
| 212 | + private function setupSectionEntry($sectionClassName, $type) { |
|
| 213 | + if (!class_exists($sectionClassName)) { |
|
| 214 | + $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName); |
|
| 215 | + return; |
|
| 216 | + } |
|
| 217 | + try { |
|
| 218 | + $section = $this->query($sectionClassName); |
|
| 219 | + } catch (QueryException $e) { |
|
| 220 | + // cancel |
|
| 221 | + return; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + if (!$section instanceof ISection) { |
|
| 225 | + $this->log->error( |
|
| 226 | + ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
| 227 | + ['class' => $sectionClassName] |
|
| 228 | + ); |
|
| 229 | + return; |
|
| 230 | + } |
|
| 231 | + $table = $this->getSectionTableForType($type); |
|
| 232 | + if(!$this->hasSection(get_class($section), $table)) { |
|
| 233 | + $this->addSection($section, $table); |
|
| 234 | + } else { |
|
| 235 | + $this->updateSection($section, $table); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + private function addSection(ISection $section, $table) { |
|
| 240 | + $this->mapper->add($table, [ |
|
| 241 | + 'id' => $section->getID(), |
|
| 242 | + 'class' => get_class($section), |
|
| 243 | + 'priority' => $section->getPriority(), |
|
| 244 | + ]); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + private function addSettings(ISettings $settings, $table) { |
|
| 248 | + $this->mapper->add($table, [ |
|
| 249 | + 'class' => get_class($settings), |
|
| 250 | + 'section' => $settings->getSection(), |
|
| 251 | + 'priority' => $settings->getPriority(), |
|
| 252 | + ]); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + private function updateSettings(ISettings $settings, $table) { |
|
| 256 | + $this->mapper->update( |
|
| 257 | + $table, |
|
| 258 | + 'class', |
|
| 259 | + get_class($settings), |
|
| 260 | + [ |
|
| 261 | + 'section' => $settings->getSection(), |
|
| 262 | + 'priority' => $settings->getPriority(), |
|
| 263 | + ] |
|
| 264 | + ); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + private function updateSection(ISection $section, $table) { |
|
| 268 | + $this->mapper->update( |
|
| 269 | + $table, |
|
| 270 | + 'class', |
|
| 271 | + get_class($section), |
|
| 272 | + [ |
|
| 273 | + 'id' => $section->getID(), |
|
| 274 | + 'priority' => $section->getPriority(), |
|
| 275 | + ] |
|
| 276 | + ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @param string $className |
|
| 281 | + * @param string $table |
|
| 282 | + * @return bool |
|
| 283 | + */ |
|
| 284 | + private function hasSection($className, $table) { |
|
| 285 | + return $this->mapper->has($table, $className); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @param string $className |
|
| 290 | + * @return bool |
|
| 291 | + */ |
|
| 292 | + private function hasSettings($className, $table) { |
|
| 293 | + return $this->mapper->has($table, $className); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + private function setupSettingsEntry($settingsClassName, $type) { |
|
| 297 | + if (!class_exists($settingsClassName)) { |
|
| 298 | + $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
|
| 299 | + return; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + try { |
|
| 303 | + /** @var ISettings $settings */ |
|
| 304 | + $settings = $this->query($settingsClassName); |
|
| 305 | + } catch (QueryException $e) { |
|
| 306 | + // cancel |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + if (!$settings instanceof ISettings) { |
|
| 311 | + $this->log->error( |
|
| 312 | + ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
| 313 | + ['class' => $settingsClassName] |
|
| 314 | + ); |
|
| 315 | + return; |
|
| 316 | + } |
|
| 317 | + $table = $this->getSettingsTableForType($type); |
|
| 318 | + if (!$this->hasSettings(get_class($settings), $table)) { |
|
| 319 | + $this->addSettings($settings, $table); |
|
| 320 | + } else { |
|
| 321 | + $this->updateSettings($settings, $table); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + private function getSectionTableForType($type) { |
|
| 326 | + if($type === 'admin') { |
|
| 327 | + return Mapper::TABLE_ADMIN_SECTIONS; |
|
| 328 | + } else if($type === 'personal') { |
|
| 329 | + return Mapper::TABLE_PERSONAL_SECTIONS; |
|
| 330 | + } |
|
| 331 | + throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + private function getSettingsTableForType($type) { |
|
| 335 | + if($type === 'admin') { |
|
| 336 | + return Mapper::TABLE_ADMIN_SETTINGS; |
|
| 337 | + } else if($type === 'personal') { |
|
| 338 | + return Mapper::TABLE_PERSONAL_SETTINGS; |
|
| 339 | + } |
|
| 340 | + throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + private function query($className) { |
|
| 344 | + try { |
|
| 345 | + return \OC::$server->query($className); |
|
| 346 | + } catch (QueryException $e) { |
|
| 347 | + $this->log->logException($e); |
|
| 348 | + throw $e; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @inheritdoc |
|
| 354 | + */ |
|
| 355 | + public function getAdminSections() { |
|
| 356 | + // built-in sections |
|
| 357 | + $sections = [ |
|
| 358 | + 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
| 359 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
| 360 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 361 | + 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
| 362 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
| 363 | + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
| 364 | + ]; |
|
| 365 | + |
|
| 366 | + $rows = $this->mapper->getAdminSectionsFromDB(); |
|
| 367 | + |
|
| 368 | + foreach ($rows as $row) { |
|
| 369 | + if (!isset($sections[$row['priority']])) { |
|
| 370 | + $sections[$row['priority']] = []; |
|
| 371 | + } |
|
| 372 | + try { |
|
| 373 | + $sections[$row['priority']][] = $this->query($row['class']); |
|
| 374 | + } catch (QueryException $e) { |
|
| 375 | + // skip |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + ksort($sections); |
|
| 380 | + |
|
| 381 | + return $sections; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * @param string $section |
|
| 386 | + * @return ISection[] |
|
| 387 | + */ |
|
| 388 | + private function getBuiltInAdminSettings($section) { |
|
| 389 | + $forms = []; |
|
| 390 | + try { |
|
| 391 | + if ($section === 'server') { |
|
| 392 | + /** @var ISettings $form */ |
|
| 393 | + $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
| 394 | + $forms[$form->getPriority()] = [$form]; |
|
| 395 | + $form = new Admin\ServerDevNotice(); |
|
| 396 | + $forms[$form->getPriority()] = [$form]; |
|
| 397 | + } |
|
| 398 | + if ($section === 'encryption') { |
|
| 399 | + /** @var ISettings $form */ |
|
| 400 | + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
| 401 | + $forms[$form->getPriority()] = [$form]; |
|
| 402 | + } |
|
| 403 | + if ($section === 'sharing') { |
|
| 404 | + /** @var ISettings $form */ |
|
| 405 | + $form = new Admin\Sharing($this->config, $this->l); |
|
| 406 | + $forms[$form->getPriority()] = [$form]; |
|
| 407 | + } |
|
| 408 | + if ($section === 'additional') { |
|
| 409 | + /** @var ISettings $form */ |
|
| 410 | + $form = new Admin\Additional($this->config); |
|
| 411 | + $forms[$form->getPriority()] = [$form]; |
|
| 412 | + } |
|
| 413 | + if ($section === 'tips-tricks') { |
|
| 414 | + /** @var ISettings $form */ |
|
| 415 | + $form = new Admin\TipsTricks($this->config); |
|
| 416 | + $forms[$form->getPriority()] = [$form]; |
|
| 417 | + } |
|
| 418 | + } catch (QueryException $e) { |
|
| 419 | + // skip |
|
| 420 | + } |
|
| 421 | + return $forms; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * @param string $section |
|
| 426 | + * @return ISection[] |
|
| 427 | + */ |
|
| 428 | + private function getBuiltInPersonalSettings($section) { |
|
| 429 | + $forms = []; |
|
| 430 | + try { |
|
| 431 | + if ($section === 'personal-info') { |
|
| 432 | + /** @var ISettings $form */ |
|
| 433 | + $form = new Personal\PersonalInfo( |
|
| 434 | + $this->config, |
|
| 435 | + $this->userManager, |
|
| 436 | + $this->groupManager, |
|
| 437 | + $this->accountManager, |
|
| 438 | + $this->appManager, |
|
| 439 | + $this->l10nFactory, |
|
| 440 | + $this->l |
|
| 441 | + ); |
|
| 442 | + $forms[$form->getPriority()] = [$form]; |
|
| 443 | + } |
|
| 444 | + if($section === 'security') { |
|
| 445 | + /** @var ISettings $form */ |
|
| 446 | + $form = new Personal\Security(); |
|
| 447 | + $forms[$form->getPriority()] = [$form]; |
|
| 448 | + } |
|
| 449 | + if ($section === 'additional') { |
|
| 450 | + /** @var ISettings $form */ |
|
| 451 | + $form = new Personal\Additional($this->config); |
|
| 452 | + $forms[$form->getPriority()] = [$form]; |
|
| 453 | + } |
|
| 454 | + } catch (QueryException $e) { |
|
| 455 | + // skip |
|
| 456 | + } |
|
| 457 | + return $forms; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @inheritdoc |
|
| 462 | + */ |
|
| 463 | + public function getAdminSettings($section) { |
|
| 464 | + $settings = $this->getBuiltInAdminSettings($section); |
|
| 465 | + $dbRows = $this->mapper->getAdminSettingsFromDB($section); |
|
| 466 | + |
|
| 467 | + foreach ($dbRows as $row) { |
|
| 468 | + if (!isset($settings[$row['priority']])) { |
|
| 469 | + $settings[$row['priority']] = []; |
|
| 470 | + } |
|
| 471 | + try { |
|
| 472 | + $settings[$row['priority']][] = $this->query($row['class']); |
|
| 473 | + } catch (QueryException $e) { |
|
| 474 | + // skip |
|
| 475 | + } catch (AutoloadNotAllowedException $e) { |
|
| 476 | + // skip error and remove remnant of disabled app |
|
| 477 | + $this->log->warning('Orphan setting entry will be removed from admin_settings: ' . json_encode($row)); |
|
| 478 | + $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, $row['class']); |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + ksort($settings); |
|
| 483 | + return $settings; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @inheritdoc |
|
| 488 | + */ |
|
| 489 | + public function getPersonalSections() { |
|
| 490 | + $sections = [ |
|
| 491 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
| 492 | + 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
| 493 | + 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
| 494 | + ]; |
|
| 495 | + |
|
| 496 | + $legacyForms = \OC_App::getForms('personal'); |
|
| 497 | + if(count($legacyForms) > 0 && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
| 498 | + $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + $rows = $this->mapper->getPersonalSectionsFromDB(); |
|
| 502 | + |
|
| 503 | + foreach ($rows as $row) { |
|
| 504 | + if (!isset($sections[$row['priority']])) { |
|
| 505 | + $sections[$row['priority']] = []; |
|
| 506 | + } |
|
| 507 | + try { |
|
| 508 | + $sections[$row['priority']][] = $this->query($row['class']); |
|
| 509 | + } catch (QueryException $e) { |
|
| 510 | + // skip |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + ksort($sections); |
|
| 515 | + |
|
| 516 | + return $sections; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * @param $forms |
|
| 521 | + * @return bool |
|
| 522 | + */ |
|
| 523 | + private function hasLegacyPersonalSettingsToRender($forms) { |
|
| 524 | + foreach ($forms as $form) { |
|
| 525 | + if(trim($form) !== '') { |
|
| 526 | + return true; |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * @inheritdoc |
|
| 534 | + */ |
|
| 535 | + public function getPersonalSettings($section) { |
|
| 536 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
| 537 | + $dbRows = $this->mapper->getPersonalSettingsFromDB($section); |
|
| 538 | + |
|
| 539 | + foreach ($dbRows as $row) { |
|
| 540 | + if (!isset($settings[$row['priority']])) { |
|
| 541 | + $settings[$row['priority']] = []; |
|
| 542 | + } |
|
| 543 | + try { |
|
| 544 | + $settings[$row['priority']][] = $this->query($row['class']); |
|
| 545 | + } catch (QueryException $e) { |
|
| 546 | + // skip |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + ksort($settings); |
|
| 551 | + return $settings; |
|
| 552 | + } |
|
| 553 | 553 | } |
@@ -33,72 +33,72 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class Capabilities implements ICapability { |
| 35 | 35 | |
| 36 | - /** @var IConfig */ |
|
| 37 | - private $config; |
|
| 36 | + /** @var IConfig */ |
|
| 37 | + private $config; |
|
| 38 | 38 | |
| 39 | - public function __construct(IConfig $config) { |
|
| 40 | - $this->config = $config; |
|
| 41 | - } |
|
| 39 | + public function __construct(IConfig $config) { |
|
| 40 | + $this->config = $config; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Return this classes capabilities |
|
| 45 | - * |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function getCapabilities() { |
|
| 49 | - $res = []; |
|
| 43 | + /** |
|
| 44 | + * Return this classes capabilities |
|
| 45 | + * |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function getCapabilities() { |
|
| 49 | + $res = []; |
|
| 50 | 50 | |
| 51 | - if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
| 52 | - $res['api_enabled'] = false; |
|
| 53 | - $res['public'] = ['enabled' => false]; |
|
| 54 | - $res['user'] = ['send_mail' => false]; |
|
| 55 | - $res['resharing'] = false; |
|
| 56 | - } else { |
|
| 57 | - $res['api_enabled'] = true; |
|
| 51 | + if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
| 52 | + $res['api_enabled'] = false; |
|
| 53 | + $res['public'] = ['enabled' => false]; |
|
| 54 | + $res['user'] = ['send_mail' => false]; |
|
| 55 | + $res['resharing'] = false; |
|
| 56 | + } else { |
|
| 57 | + $res['api_enabled'] = true; |
|
| 58 | 58 | |
| 59 | - $public = []; |
|
| 60 | - $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
| 61 | - if ($public['enabled']) { |
|
| 62 | - $public['password'] = []; |
|
| 63 | - $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'); |
|
| 59 | + $public = []; |
|
| 60 | + $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
| 61 | + if ($public['enabled']) { |
|
| 62 | + $public['password'] = []; |
|
| 63 | + $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'); |
|
| 64 | 64 | |
| 65 | - $public['expire_date'] = []; |
|
| 66 | - $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 67 | - if ($public['expire_date']['enabled']) { |
|
| 68 | - $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 69 | - $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 70 | - } |
|
| 65 | + $public['expire_date'] = []; |
|
| 66 | + $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 67 | + if ($public['expire_date']['enabled']) { |
|
| 68 | + $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 69 | + $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes'; |
|
| 73 | - $public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 74 | - $public['upload_files_drop'] = $public['upload']; |
|
| 75 | - } |
|
| 76 | - $res['public'] = $public; |
|
| 72 | + $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes'; |
|
| 73 | + $public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 74 | + $public['upload_files_drop'] = $public['upload']; |
|
| 75 | + } |
|
| 76 | + $res['public'] = $public; |
|
| 77 | 77 | |
| 78 | - $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; |
|
| 78 | + $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; |
|
| 79 | 79 | |
| 80 | - $res['user']['send_mail'] = false; |
|
| 81 | - $res['user']['expire_date']['enabled'] = true; |
|
| 80 | + $res['user']['send_mail'] = false; |
|
| 81 | + $res['user']['expire_date']['enabled'] = true; |
|
| 82 | 82 | |
| 83 | - // deprecated in favour of 'group', but we need to keep it for now |
|
| 84 | - // in order to stay compatible with older clients |
|
| 85 | - $res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 83 | + // deprecated in favour of 'group', but we need to keep it for now |
|
| 84 | + // in order to stay compatible with older clients |
|
| 85 | + $res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 86 | 86 | |
| 87 | - $res['group'] = []; |
|
| 88 | - $res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 89 | - $res['group']['expire_date']['enabled'] = true; |
|
| 90 | - $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
| 91 | - } |
|
| 87 | + $res['group'] = []; |
|
| 88 | + $res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 89 | + $res['group']['expire_date']['enabled'] = true; |
|
| 90 | + $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - //Federated sharing |
|
| 94 | - $res['federation'] = [ |
|
| 95 | - 'outgoing' => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes', |
|
| 96 | - 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes', |
|
| 97 | - 'expire_date' => ['enabled' => true] |
|
| 98 | - ]; |
|
| 93 | + //Federated sharing |
|
| 94 | + $res['federation'] = [ |
|
| 95 | + 'outgoing' => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes', |
|
| 96 | + 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes', |
|
| 97 | + 'expire_date' => ['enabled' => true] |
|
| 98 | + ]; |
|
| 99 | 99 | |
| 100 | - return [ |
|
| 101 | - 'files_sharing' => $res, |
|
| 102 | - ]; |
|
| 103 | - } |
|
| 100 | + return [ |
|
| 101 | + 'files_sharing' => $res, |
|
| 102 | + ]; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -87,7 +87,7 @@ |
||
| 87 | 87 | $res['group'] = []; |
| 88 | 88 | $res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
| 89 | 89 | $res['group']['expire_date']['enabled'] = true; |
| 90 | - $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
| 90 | + $res['default_permissions'] = (int) $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | //Federated sharing |
@@ -43,62 +43,62 @@ |
||
| 43 | 43 | |
| 44 | 44 | class OCJSController extends Controller { |
| 45 | 45 | |
| 46 | - /** @var JSConfigHelper */ |
|
| 47 | - private $helper; |
|
| 46 | + /** @var JSConfigHelper */ |
|
| 47 | + private $helper; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * OCJSController constructor. |
|
| 51 | - * |
|
| 52 | - * @param string $appName |
|
| 53 | - * @param IRequest $request |
|
| 54 | - * @param IL10N $l |
|
| 55 | - * @param Defaults $defaults |
|
| 56 | - * @param IAppManager $appManager |
|
| 57 | - * @param ISession $session |
|
| 58 | - * @param IUserSession $userSession |
|
| 59 | - * @param IConfig $config |
|
| 60 | - * @param IGroupManager $groupManager |
|
| 61 | - * @param IniGetWrapper $iniWrapper |
|
| 62 | - * @param IURLGenerator $urlGenerator |
|
| 63 | - * @param CapabilitiesManager $capabilitiesManager |
|
| 64 | - */ |
|
| 65 | - public function __construct($appName, |
|
| 66 | - IRequest $request, |
|
| 67 | - IL10N $l, |
|
| 68 | - Defaults $defaults, |
|
| 69 | - IAppManager $appManager, |
|
| 70 | - ISession $session, |
|
| 71 | - IUserSession $userSession, |
|
| 72 | - IConfig $config, |
|
| 73 | - IGroupManager $groupManager, |
|
| 74 | - IniGetWrapper $iniWrapper, |
|
| 75 | - IURLGenerator $urlGenerator, |
|
| 76 | - CapabilitiesManager $capabilitiesManager) { |
|
| 77 | - parent::__construct($appName, $request); |
|
| 49 | + /** |
|
| 50 | + * OCJSController constructor. |
|
| 51 | + * |
|
| 52 | + * @param string $appName |
|
| 53 | + * @param IRequest $request |
|
| 54 | + * @param IL10N $l |
|
| 55 | + * @param Defaults $defaults |
|
| 56 | + * @param IAppManager $appManager |
|
| 57 | + * @param ISession $session |
|
| 58 | + * @param IUserSession $userSession |
|
| 59 | + * @param IConfig $config |
|
| 60 | + * @param IGroupManager $groupManager |
|
| 61 | + * @param IniGetWrapper $iniWrapper |
|
| 62 | + * @param IURLGenerator $urlGenerator |
|
| 63 | + * @param CapabilitiesManager $capabilitiesManager |
|
| 64 | + */ |
|
| 65 | + public function __construct($appName, |
|
| 66 | + IRequest $request, |
|
| 67 | + IL10N $l, |
|
| 68 | + Defaults $defaults, |
|
| 69 | + IAppManager $appManager, |
|
| 70 | + ISession $session, |
|
| 71 | + IUserSession $userSession, |
|
| 72 | + IConfig $config, |
|
| 73 | + IGroupManager $groupManager, |
|
| 74 | + IniGetWrapper $iniWrapper, |
|
| 75 | + IURLGenerator $urlGenerator, |
|
| 76 | + CapabilitiesManager $capabilitiesManager) { |
|
| 77 | + parent::__construct($appName, $request); |
|
| 78 | 78 | |
| 79 | - $this->helper = new JSConfigHelper( |
|
| 80 | - $l, |
|
| 81 | - $defaults, |
|
| 82 | - $appManager, |
|
| 83 | - $session, |
|
| 84 | - $userSession->getUser(), |
|
| 85 | - $config, |
|
| 86 | - $groupManager, |
|
| 87 | - $iniWrapper, |
|
| 88 | - $urlGenerator, |
|
| 89 | - $capabilitiesManager |
|
| 90 | - ); |
|
| 91 | - } |
|
| 79 | + $this->helper = new JSConfigHelper( |
|
| 80 | + $l, |
|
| 81 | + $defaults, |
|
| 82 | + $appManager, |
|
| 83 | + $session, |
|
| 84 | + $userSession->getUser(), |
|
| 85 | + $config, |
|
| 86 | + $groupManager, |
|
| 87 | + $iniWrapper, |
|
| 88 | + $urlGenerator, |
|
| 89 | + $capabilitiesManager |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @NoCSRFRequired |
|
| 95 | - * @PublicPage |
|
| 96 | - * |
|
| 97 | - * @return DataDisplayResponse |
|
| 98 | - */ |
|
| 99 | - public function getConfig() { |
|
| 100 | - $data = $this->helper->getConfig(); |
|
| 93 | + /** |
|
| 94 | + * @NoCSRFRequired |
|
| 95 | + * @PublicPage |
|
| 96 | + * |
|
| 97 | + * @return DataDisplayResponse |
|
| 98 | + */ |
|
| 99 | + public function getConfig() { |
|
| 100 | + $data = $this->helper->getConfig(); |
|
| 101 | 101 | |
| 102 | - return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']); |
|
| 103 | - } |
|
| 102 | + return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']); |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -59,897 +59,897 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | class ShareAPIController extends OCSController { |
| 61 | 61 | |
| 62 | - /** @var IManager */ |
|
| 63 | - private $shareManager; |
|
| 64 | - /** @var IGroupManager */ |
|
| 65 | - private $groupManager; |
|
| 66 | - /** @var IUserManager */ |
|
| 67 | - private $userManager; |
|
| 68 | - /** @var IRequest */ |
|
| 69 | - protected $request; |
|
| 70 | - /** @var IRootFolder */ |
|
| 71 | - private $rootFolder; |
|
| 72 | - /** @var IURLGenerator */ |
|
| 73 | - private $urlGenerator; |
|
| 74 | - /** @var string */ |
|
| 75 | - private $currentUser; |
|
| 76 | - /** @var IL10N */ |
|
| 77 | - private $l; |
|
| 78 | - /** @var \OCP\Files\Node */ |
|
| 79 | - private $lockedNode; |
|
| 80 | - /** @var IConfig */ |
|
| 81 | - private $config; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Share20OCS constructor. |
|
| 85 | - * |
|
| 86 | - * @param string $appName |
|
| 87 | - * @param IRequest $request |
|
| 88 | - * @param IManager $shareManager |
|
| 89 | - * @param IGroupManager $groupManager |
|
| 90 | - * @param IUserManager $userManager |
|
| 91 | - * @param IRootFolder $rootFolder |
|
| 92 | - * @param IURLGenerator $urlGenerator |
|
| 93 | - * @param string $userId |
|
| 94 | - * @param IL10N $l10n |
|
| 95 | - * @param IConfig $config |
|
| 96 | - */ |
|
| 97 | - public function __construct( |
|
| 98 | - $appName, |
|
| 99 | - IRequest $request, |
|
| 100 | - IManager $shareManager, |
|
| 101 | - IGroupManager $groupManager, |
|
| 102 | - IUserManager $userManager, |
|
| 103 | - IRootFolder $rootFolder, |
|
| 104 | - IURLGenerator $urlGenerator, |
|
| 105 | - $userId, |
|
| 106 | - IL10N $l10n, |
|
| 107 | - IConfig $config |
|
| 108 | - ) { |
|
| 109 | - parent::__construct($appName, $request); |
|
| 110 | - |
|
| 111 | - $this->shareManager = $shareManager; |
|
| 112 | - $this->userManager = $userManager; |
|
| 113 | - $this->groupManager = $groupManager; |
|
| 114 | - $this->request = $request; |
|
| 115 | - $this->rootFolder = $rootFolder; |
|
| 116 | - $this->urlGenerator = $urlGenerator; |
|
| 117 | - $this->currentUser = $userId; |
|
| 118 | - $this->l = $l10n; |
|
| 119 | - $this->config = $config; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Convert an IShare to an array for OCS output |
|
| 124 | - * |
|
| 125 | - * @param \OCP\Share\IShare $share |
|
| 126 | - * @param Node|null $recipientNode |
|
| 127 | - * @return array |
|
| 128 | - * @throws NotFoundException In case the node can't be resolved. |
|
| 129 | - */ |
|
| 130 | - protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
| 131 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 132 | - $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
| 133 | - |
|
| 134 | - $result = [ |
|
| 135 | - 'id' => $share->getId(), |
|
| 136 | - 'share_type' => $share->getShareType(), |
|
| 137 | - 'uid_owner' => $share->getSharedBy(), |
|
| 138 | - 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
| 139 | - 'permissions' => $share->getPermissions(), |
|
| 140 | - 'stime' => $share->getShareTime()->getTimestamp(), |
|
| 141 | - 'parent' => null, |
|
| 142 | - 'expiration' => null, |
|
| 143 | - 'token' => null, |
|
| 144 | - 'uid_file_owner' => $share->getShareOwner(), |
|
| 145 | - 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
| 146 | - ]; |
|
| 147 | - |
|
| 148 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 149 | - if ($recipientNode) { |
|
| 150 | - $node = $recipientNode; |
|
| 151 | - } else { |
|
| 152 | - $nodes = $userFolder->getById($share->getNodeId()); |
|
| 153 | - |
|
| 154 | - if (empty($nodes)) { |
|
| 155 | - // fallback to guessing the path |
|
| 156 | - $node = $userFolder->get($share->getTarget()); |
|
| 157 | - if ($node === null) { |
|
| 158 | - throw new NotFoundException(); |
|
| 159 | - } |
|
| 160 | - } else { |
|
| 161 | - $node = $nodes[0]; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
| 166 | - if ($node instanceOf \OCP\Files\Folder) { |
|
| 167 | - $result['item_type'] = 'folder'; |
|
| 168 | - } else { |
|
| 169 | - $result['item_type'] = 'file'; |
|
| 170 | - } |
|
| 171 | - $result['mimetype'] = $node->getMimetype(); |
|
| 172 | - $result['storage_id'] = $node->getStorage()->getId(); |
|
| 173 | - $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
| 174 | - $result['item_source'] = $node->getId(); |
|
| 175 | - $result['file_source'] = $node->getId(); |
|
| 176 | - $result['file_parent'] = $node->getParent()->getId(); |
|
| 177 | - $result['file_target'] = $share->getTarget(); |
|
| 178 | - |
|
| 179 | - $expiration = $share->getExpirationDate(); |
|
| 180 | - if ($expiration !== null) { |
|
| 181 | - $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 185 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 186 | - $result['share_with'] = $share->getSharedWith(); |
|
| 187 | - $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
| 188 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 189 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
| 190 | - $result['share_with'] = $share->getSharedWith(); |
|
| 191 | - $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
| 192 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 193 | - |
|
| 194 | - $result['share_with'] = $share->getPassword(); |
|
| 195 | - $result['share_with_displayname'] = $share->getPassword(); |
|
| 196 | - |
|
| 197 | - $result['token'] = $share->getToken(); |
|
| 198 | - $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
| 199 | - |
|
| 200 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 201 | - $result['share_with'] = $share->getSharedWith(); |
|
| 202 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
| 203 | - $result['token'] = $share->getToken(); |
|
| 204 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 205 | - $result['share_with'] = $share->getSharedWith(); |
|
| 206 | - $result['password'] = $share->getPassword(); |
|
| 207 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
| 208 | - $result['token'] = $share->getToken(); |
|
| 209 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 210 | - $result['share_with_displayname'] = $share->getSharedWith(); |
|
| 211 | - $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0]; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
| 216 | - |
|
| 217 | - return $result; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Check if one of the users address books knows the exact property, if |
|
| 222 | - * yes we return the full name. |
|
| 223 | - * |
|
| 224 | - * @param string $query |
|
| 225 | - * @param string $property |
|
| 226 | - * @return string |
|
| 227 | - */ |
|
| 228 | - private function getDisplayNameFromAddressBook($query, $property) { |
|
| 229 | - // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
| 230 | - $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
| 231 | - foreach ($result as $r) { |
|
| 232 | - foreach($r[$property] as $value) { |
|
| 233 | - if ($value === $query) { |
|
| 234 | - return $r['FN']; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $query; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Get a specific share by id |
|
| 244 | - * |
|
| 245 | - * @NoAdminRequired |
|
| 246 | - * |
|
| 247 | - * @param string $id |
|
| 248 | - * @return DataResponse |
|
| 249 | - * @throws OCSNotFoundException |
|
| 250 | - */ |
|
| 251 | - public function getShare($id) { |
|
| 252 | - try { |
|
| 253 | - $share = $this->getShareById($id); |
|
| 254 | - } catch (ShareNotFound $e) { |
|
| 255 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - if ($this->canAccessShare($share)) { |
|
| 259 | - try { |
|
| 260 | - $share = $this->formatShare($share); |
|
| 261 | - return new DataResponse([$share]); |
|
| 262 | - } catch (NotFoundException $e) { |
|
| 263 | - //Fall trough |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Delete a share |
|
| 272 | - * |
|
| 273 | - * @NoAdminRequired |
|
| 274 | - * |
|
| 275 | - * @param string $id |
|
| 276 | - * @return DataResponse |
|
| 277 | - * @throws OCSNotFoundException |
|
| 278 | - */ |
|
| 279 | - public function deleteShare($id) { |
|
| 280 | - try { |
|
| 281 | - $share = $this->getShareById($id); |
|
| 282 | - } catch (ShareNotFound $e) { |
|
| 283 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - try { |
|
| 287 | - $this->lock($share->getNode()); |
|
| 288 | - } catch (LockedException $e) { |
|
| 289 | - throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if (!$this->canAccessShare($share)) { |
|
| 293 | - throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
| 297 | - $share->getShareOwner() !== $this->currentUser && |
|
| 298 | - $share->getSharedBy() !== $this->currentUser) { |
|
| 299 | - $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
| 300 | - } else { |
|
| 301 | - $this->shareManager->deleteShare($share); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return new DataResponse(); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @NoAdminRequired |
|
| 309 | - * |
|
| 310 | - * @param string $path |
|
| 311 | - * @param int $permissions |
|
| 312 | - * @param int $shareType |
|
| 313 | - * @param string $shareWith |
|
| 314 | - * @param string $publicUpload |
|
| 315 | - * @param string $password |
|
| 316 | - * @param string $expireDate |
|
| 317 | - * |
|
| 318 | - * @return DataResponse |
|
| 319 | - * @throws OCSNotFoundException |
|
| 320 | - * @throws OCSForbiddenException |
|
| 321 | - * @throws OCSBadRequestException |
|
| 322 | - * @throws OCSException |
|
| 323 | - * |
|
| 324 | - * @suppress PhanUndeclaredClassMethod |
|
| 325 | - */ |
|
| 326 | - public function createShare( |
|
| 327 | - $path = null, |
|
| 328 | - $permissions = null, |
|
| 329 | - $shareType = -1, |
|
| 330 | - $shareWith = null, |
|
| 331 | - $publicUpload = 'false', |
|
| 332 | - $password = '', |
|
| 333 | - $expireDate = '' |
|
| 334 | - ) { |
|
| 335 | - $share = $this->shareManager->newShare(); |
|
| 336 | - |
|
| 337 | - if ($permissions === null) { |
|
| 338 | - $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // Verify path |
|
| 342 | - if ($path === null) { |
|
| 343 | - throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 347 | - try { |
|
| 348 | - $path = $userFolder->get($path); |
|
| 349 | - } catch (NotFoundException $e) { |
|
| 350 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $share->setNode($path); |
|
| 354 | - |
|
| 355 | - try { |
|
| 356 | - $this->lock($share->getNode()); |
|
| 357 | - } catch (LockedException $e) { |
|
| 358 | - throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) { |
|
| 362 | - throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - // Shares always require read permissions |
|
| 366 | - $permissions |= Constants::PERMISSION_READ; |
|
| 367 | - |
|
| 368 | - if ($path instanceof \OCP\Files\File) { |
|
| 369 | - // Single file shares should never have delete or create permissions |
|
| 370 | - $permissions &= ~Constants::PERMISSION_DELETE; |
|
| 371 | - $permissions &= ~Constants::PERMISSION_CREATE; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /* |
|
| 62 | + /** @var IManager */ |
|
| 63 | + private $shareManager; |
|
| 64 | + /** @var IGroupManager */ |
|
| 65 | + private $groupManager; |
|
| 66 | + /** @var IUserManager */ |
|
| 67 | + private $userManager; |
|
| 68 | + /** @var IRequest */ |
|
| 69 | + protected $request; |
|
| 70 | + /** @var IRootFolder */ |
|
| 71 | + private $rootFolder; |
|
| 72 | + /** @var IURLGenerator */ |
|
| 73 | + private $urlGenerator; |
|
| 74 | + /** @var string */ |
|
| 75 | + private $currentUser; |
|
| 76 | + /** @var IL10N */ |
|
| 77 | + private $l; |
|
| 78 | + /** @var \OCP\Files\Node */ |
|
| 79 | + private $lockedNode; |
|
| 80 | + /** @var IConfig */ |
|
| 81 | + private $config; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Share20OCS constructor. |
|
| 85 | + * |
|
| 86 | + * @param string $appName |
|
| 87 | + * @param IRequest $request |
|
| 88 | + * @param IManager $shareManager |
|
| 89 | + * @param IGroupManager $groupManager |
|
| 90 | + * @param IUserManager $userManager |
|
| 91 | + * @param IRootFolder $rootFolder |
|
| 92 | + * @param IURLGenerator $urlGenerator |
|
| 93 | + * @param string $userId |
|
| 94 | + * @param IL10N $l10n |
|
| 95 | + * @param IConfig $config |
|
| 96 | + */ |
|
| 97 | + public function __construct( |
|
| 98 | + $appName, |
|
| 99 | + IRequest $request, |
|
| 100 | + IManager $shareManager, |
|
| 101 | + IGroupManager $groupManager, |
|
| 102 | + IUserManager $userManager, |
|
| 103 | + IRootFolder $rootFolder, |
|
| 104 | + IURLGenerator $urlGenerator, |
|
| 105 | + $userId, |
|
| 106 | + IL10N $l10n, |
|
| 107 | + IConfig $config |
|
| 108 | + ) { |
|
| 109 | + parent::__construct($appName, $request); |
|
| 110 | + |
|
| 111 | + $this->shareManager = $shareManager; |
|
| 112 | + $this->userManager = $userManager; |
|
| 113 | + $this->groupManager = $groupManager; |
|
| 114 | + $this->request = $request; |
|
| 115 | + $this->rootFolder = $rootFolder; |
|
| 116 | + $this->urlGenerator = $urlGenerator; |
|
| 117 | + $this->currentUser = $userId; |
|
| 118 | + $this->l = $l10n; |
|
| 119 | + $this->config = $config; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Convert an IShare to an array for OCS output |
|
| 124 | + * |
|
| 125 | + * @param \OCP\Share\IShare $share |
|
| 126 | + * @param Node|null $recipientNode |
|
| 127 | + * @return array |
|
| 128 | + * @throws NotFoundException In case the node can't be resolved. |
|
| 129 | + */ |
|
| 130 | + protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
| 131 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 132 | + $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
| 133 | + |
|
| 134 | + $result = [ |
|
| 135 | + 'id' => $share->getId(), |
|
| 136 | + 'share_type' => $share->getShareType(), |
|
| 137 | + 'uid_owner' => $share->getSharedBy(), |
|
| 138 | + 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
| 139 | + 'permissions' => $share->getPermissions(), |
|
| 140 | + 'stime' => $share->getShareTime()->getTimestamp(), |
|
| 141 | + 'parent' => null, |
|
| 142 | + 'expiration' => null, |
|
| 143 | + 'token' => null, |
|
| 144 | + 'uid_file_owner' => $share->getShareOwner(), |
|
| 145 | + 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
| 146 | + ]; |
|
| 147 | + |
|
| 148 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 149 | + if ($recipientNode) { |
|
| 150 | + $node = $recipientNode; |
|
| 151 | + } else { |
|
| 152 | + $nodes = $userFolder->getById($share->getNodeId()); |
|
| 153 | + |
|
| 154 | + if (empty($nodes)) { |
|
| 155 | + // fallback to guessing the path |
|
| 156 | + $node = $userFolder->get($share->getTarget()); |
|
| 157 | + if ($node === null) { |
|
| 158 | + throw new NotFoundException(); |
|
| 159 | + } |
|
| 160 | + } else { |
|
| 161 | + $node = $nodes[0]; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
| 166 | + if ($node instanceOf \OCP\Files\Folder) { |
|
| 167 | + $result['item_type'] = 'folder'; |
|
| 168 | + } else { |
|
| 169 | + $result['item_type'] = 'file'; |
|
| 170 | + } |
|
| 171 | + $result['mimetype'] = $node->getMimetype(); |
|
| 172 | + $result['storage_id'] = $node->getStorage()->getId(); |
|
| 173 | + $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
| 174 | + $result['item_source'] = $node->getId(); |
|
| 175 | + $result['file_source'] = $node->getId(); |
|
| 176 | + $result['file_parent'] = $node->getParent()->getId(); |
|
| 177 | + $result['file_target'] = $share->getTarget(); |
|
| 178 | + |
|
| 179 | + $expiration = $share->getExpirationDate(); |
|
| 180 | + if ($expiration !== null) { |
|
| 181 | + $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 185 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 186 | + $result['share_with'] = $share->getSharedWith(); |
|
| 187 | + $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
| 188 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 189 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
| 190 | + $result['share_with'] = $share->getSharedWith(); |
|
| 191 | + $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
| 192 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 193 | + |
|
| 194 | + $result['share_with'] = $share->getPassword(); |
|
| 195 | + $result['share_with_displayname'] = $share->getPassword(); |
|
| 196 | + |
|
| 197 | + $result['token'] = $share->getToken(); |
|
| 198 | + $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
| 199 | + |
|
| 200 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 201 | + $result['share_with'] = $share->getSharedWith(); |
|
| 202 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
| 203 | + $result['token'] = $share->getToken(); |
|
| 204 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 205 | + $result['share_with'] = $share->getSharedWith(); |
|
| 206 | + $result['password'] = $share->getPassword(); |
|
| 207 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
| 208 | + $result['token'] = $share->getToken(); |
|
| 209 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 210 | + $result['share_with_displayname'] = $share->getSharedWith(); |
|
| 211 | + $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0]; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
| 216 | + |
|
| 217 | + return $result; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Check if one of the users address books knows the exact property, if |
|
| 222 | + * yes we return the full name. |
|
| 223 | + * |
|
| 224 | + * @param string $query |
|
| 225 | + * @param string $property |
|
| 226 | + * @return string |
|
| 227 | + */ |
|
| 228 | + private function getDisplayNameFromAddressBook($query, $property) { |
|
| 229 | + // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
| 230 | + $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
| 231 | + foreach ($result as $r) { |
|
| 232 | + foreach($r[$property] as $value) { |
|
| 233 | + if ($value === $query) { |
|
| 234 | + return $r['FN']; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $query; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Get a specific share by id |
|
| 244 | + * |
|
| 245 | + * @NoAdminRequired |
|
| 246 | + * |
|
| 247 | + * @param string $id |
|
| 248 | + * @return DataResponse |
|
| 249 | + * @throws OCSNotFoundException |
|
| 250 | + */ |
|
| 251 | + public function getShare($id) { |
|
| 252 | + try { |
|
| 253 | + $share = $this->getShareById($id); |
|
| 254 | + } catch (ShareNotFound $e) { |
|
| 255 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + if ($this->canAccessShare($share)) { |
|
| 259 | + try { |
|
| 260 | + $share = $this->formatShare($share); |
|
| 261 | + return new DataResponse([$share]); |
|
| 262 | + } catch (NotFoundException $e) { |
|
| 263 | + //Fall trough |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Delete a share |
|
| 272 | + * |
|
| 273 | + * @NoAdminRequired |
|
| 274 | + * |
|
| 275 | + * @param string $id |
|
| 276 | + * @return DataResponse |
|
| 277 | + * @throws OCSNotFoundException |
|
| 278 | + */ |
|
| 279 | + public function deleteShare($id) { |
|
| 280 | + try { |
|
| 281 | + $share = $this->getShareById($id); |
|
| 282 | + } catch (ShareNotFound $e) { |
|
| 283 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + try { |
|
| 287 | + $this->lock($share->getNode()); |
|
| 288 | + } catch (LockedException $e) { |
|
| 289 | + throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if (!$this->canAccessShare($share)) { |
|
| 293 | + throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
| 297 | + $share->getShareOwner() !== $this->currentUser && |
|
| 298 | + $share->getSharedBy() !== $this->currentUser) { |
|
| 299 | + $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
| 300 | + } else { |
|
| 301 | + $this->shareManager->deleteShare($share); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return new DataResponse(); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @NoAdminRequired |
|
| 309 | + * |
|
| 310 | + * @param string $path |
|
| 311 | + * @param int $permissions |
|
| 312 | + * @param int $shareType |
|
| 313 | + * @param string $shareWith |
|
| 314 | + * @param string $publicUpload |
|
| 315 | + * @param string $password |
|
| 316 | + * @param string $expireDate |
|
| 317 | + * |
|
| 318 | + * @return DataResponse |
|
| 319 | + * @throws OCSNotFoundException |
|
| 320 | + * @throws OCSForbiddenException |
|
| 321 | + * @throws OCSBadRequestException |
|
| 322 | + * @throws OCSException |
|
| 323 | + * |
|
| 324 | + * @suppress PhanUndeclaredClassMethod |
|
| 325 | + */ |
|
| 326 | + public function createShare( |
|
| 327 | + $path = null, |
|
| 328 | + $permissions = null, |
|
| 329 | + $shareType = -1, |
|
| 330 | + $shareWith = null, |
|
| 331 | + $publicUpload = 'false', |
|
| 332 | + $password = '', |
|
| 333 | + $expireDate = '' |
|
| 334 | + ) { |
|
| 335 | + $share = $this->shareManager->newShare(); |
|
| 336 | + |
|
| 337 | + if ($permissions === null) { |
|
| 338 | + $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // Verify path |
|
| 342 | + if ($path === null) { |
|
| 343 | + throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 347 | + try { |
|
| 348 | + $path = $userFolder->get($path); |
|
| 349 | + } catch (NotFoundException $e) { |
|
| 350 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $share->setNode($path); |
|
| 354 | + |
|
| 355 | + try { |
|
| 356 | + $this->lock($share->getNode()); |
|
| 357 | + } catch (LockedException $e) { |
|
| 358 | + throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) { |
|
| 362 | + throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + // Shares always require read permissions |
|
| 366 | + $permissions |= Constants::PERMISSION_READ; |
|
| 367 | + |
|
| 368 | + if ($path instanceof \OCP\Files\File) { |
|
| 369 | + // Single file shares should never have delete or create permissions |
|
| 370 | + $permissions &= ~Constants::PERMISSION_DELETE; |
|
| 371 | + $permissions &= ~Constants::PERMISSION_CREATE; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /* |
|
| 375 | 375 | * Hack for https://github.com/owncloud/core/issues/22587 |
| 376 | 376 | * We check the permissions via webdav. But the permissions of the mount point |
| 377 | 377 | * do not equal the share permissions. Here we fix that for federated mounts. |
| 378 | 378 | */ |
| 379 | - if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 380 | - $permissions &= ~($permissions & ~$path->getPermissions()); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 384 | - // Valid user is required to share |
|
| 385 | - if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
| 386 | - throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
| 387 | - } |
|
| 388 | - $share->setSharedWith($shareWith); |
|
| 389 | - $share->setPermissions($permissions); |
|
| 390 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 391 | - if (!$this->shareManager->allowGroupSharing()) { |
|
| 392 | - throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - // Valid group is required to share |
|
| 396 | - if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
| 397 | - throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
| 398 | - } |
|
| 399 | - $share->setSharedWith($shareWith); |
|
| 400 | - $share->setPermissions($permissions); |
|
| 401 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 402 | - //Can we even share links? |
|
| 403 | - if (!$this->shareManager->shareApiAllowLinks()) { |
|
| 404 | - throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /* |
|
| 379 | + if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 380 | + $permissions &= ~($permissions & ~$path->getPermissions()); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 384 | + // Valid user is required to share |
|
| 385 | + if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
| 386 | + throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
| 387 | + } |
|
| 388 | + $share->setSharedWith($shareWith); |
|
| 389 | + $share->setPermissions($permissions); |
|
| 390 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 391 | + if (!$this->shareManager->allowGroupSharing()) { |
|
| 392 | + throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + // Valid group is required to share |
|
| 396 | + if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
| 397 | + throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
| 398 | + } |
|
| 399 | + $share->setSharedWith($shareWith); |
|
| 400 | + $share->setPermissions($permissions); |
|
| 401 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 402 | + //Can we even share links? |
|
| 403 | + if (!$this->shareManager->shareApiAllowLinks()) { |
|
| 404 | + throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /* |
|
| 408 | 408 | * For now we only allow 1 link share. |
| 409 | 409 | * Return the existing link share if this is a duplicate |
| 410 | 410 | */ |
| 411 | - $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
| 412 | - if (!empty($existingShares)) { |
|
| 413 | - return new DataResponse($this->formatShare($existingShares[0])); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - if ($publicUpload === 'true') { |
|
| 417 | - // Check if public upload is allowed |
|
| 418 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 419 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - // Public upload can only be set for folders |
|
| 423 | - if ($path instanceof \OCP\Files\File) { |
|
| 424 | - throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - $share->setPermissions( |
|
| 428 | - Constants::PERMISSION_READ | |
|
| 429 | - Constants::PERMISSION_CREATE | |
|
| 430 | - Constants::PERMISSION_UPDATE | |
|
| 431 | - Constants::PERMISSION_DELETE |
|
| 432 | - ); |
|
| 433 | - } else { |
|
| 434 | - $share->setPermissions(Constants::PERMISSION_READ); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // Set password |
|
| 438 | - if ($password !== '') { |
|
| 439 | - $share->setPassword($password); |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - //Expire date |
|
| 443 | - if ($expireDate !== '') { |
|
| 444 | - try { |
|
| 445 | - $expireDate = $this->parseDate($expireDate); |
|
| 446 | - $share->setExpirationDate($expireDate); |
|
| 447 | - } catch (\Exception $e) { |
|
| 448 | - throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 453 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 454 | - throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $share->setSharedWith($shareWith); |
|
| 458 | - $share->setPermissions($permissions); |
|
| 459 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 460 | - if ($share->getNodeType() === 'file') { |
|
| 461 | - $share->setPermissions(Constants::PERMISSION_READ); |
|
| 462 | - } else { |
|
| 463 | - $share->setPermissions($permissions); |
|
| 464 | - } |
|
| 465 | - $share->setSharedWith($shareWith); |
|
| 466 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 467 | - if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
| 468 | - throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith); |
|
| 472 | - |
|
| 473 | - // Valid circle is required to share |
|
| 474 | - if ($circle === null) { |
|
| 475 | - throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
| 476 | - } |
|
| 477 | - $share->setSharedWith($shareWith); |
|
| 478 | - $share->setPermissions($permissions); |
|
| 479 | - } else { |
|
| 480 | - throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - $share->setShareType($shareType); |
|
| 484 | - $share->setSharedBy($this->currentUser); |
|
| 485 | - |
|
| 486 | - try { |
|
| 487 | - $share = $this->shareManager->createShare($share); |
|
| 488 | - } catch (GenericShareException $e) { |
|
| 489 | - $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
| 490 | - throw new OCSException($e->getHint(), $code); |
|
| 491 | - } catch (\Exception $e) { |
|
| 492 | - throw new OCSForbiddenException($e->getMessage()); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $output = $this->formatShare($share); |
|
| 496 | - |
|
| 497 | - return new DataResponse($output); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
| 502 | - * @param boolean $includeTags |
|
| 503 | - * @return DataResponse |
|
| 504 | - */ |
|
| 505 | - private function getSharedWithMe($node = null, $includeTags) { |
|
| 506 | - |
|
| 507 | - $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
| 508 | - $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
| 509 | - $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
| 510 | - |
|
| 511 | - $shares = array_merge($userShares, $groupShares, $circleShares); |
|
| 512 | - |
|
| 513 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 514 | - return $share->getShareOwner() !== $this->currentUser; |
|
| 515 | - }); |
|
| 516 | - |
|
| 517 | - $formatted = []; |
|
| 518 | - foreach ($shares as $share) { |
|
| 519 | - if ($this->canAccessShare($share)) { |
|
| 520 | - try { |
|
| 521 | - $formatted[] = $this->formatShare($share); |
|
| 522 | - } catch (NotFoundException $e) { |
|
| 523 | - // Ignore this share |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - if ($includeTags) { |
|
| 529 | - $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - return new DataResponse($formatted); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * @param \OCP\Files\Folder $folder |
|
| 537 | - * @return DataResponse |
|
| 538 | - * @throws OCSBadRequestException |
|
| 539 | - */ |
|
| 540 | - private function getSharesInDir($folder) { |
|
| 541 | - if (!($folder instanceof \OCP\Files\Folder)) { |
|
| 542 | - throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - $nodes = $folder->getDirectoryListing(); |
|
| 546 | - /** @var \OCP\Share\IShare[] $shares */ |
|
| 547 | - $shares = []; |
|
| 548 | - foreach ($nodes as $node) { |
|
| 549 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
| 550 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
| 551 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
| 552 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 553 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
| 554 | - } |
|
| 555 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 556 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - $formatted = []; |
|
| 561 | - foreach ($shares as $share) { |
|
| 562 | - try { |
|
| 563 | - $formatted[] = $this->formatShare($share); |
|
| 564 | - } catch (NotFoundException $e) { |
|
| 565 | - //Ignore this share |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - return new DataResponse($formatted); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * The getShares function. |
|
| 574 | - * |
|
| 575 | - * @NoAdminRequired |
|
| 576 | - * |
|
| 577 | - * @param string $shared_with_me |
|
| 578 | - * @param string $reshares |
|
| 579 | - * @param string $subfiles |
|
| 580 | - * @param string $path |
|
| 581 | - * |
|
| 582 | - * - Get shares by the current user |
|
| 583 | - * - Get shares by the current user and reshares (?reshares=true) |
|
| 584 | - * - Get shares with the current user (?shared_with_me=true) |
|
| 585 | - * - Get shares for a specific path (?path=...) |
|
| 586 | - * - Get all shares in a folder (?subfiles=true&path=..) |
|
| 587 | - * |
|
| 588 | - * @return DataResponse |
|
| 589 | - * @throws OCSNotFoundException |
|
| 590 | - */ |
|
| 591 | - public function getShares( |
|
| 592 | - $shared_with_me = 'false', |
|
| 593 | - $reshares = 'false', |
|
| 594 | - $subfiles = 'false', |
|
| 595 | - $path = null, |
|
| 596 | - $include_tags = 'false' |
|
| 597 | - ) { |
|
| 598 | - |
|
| 599 | - if ($path !== null) { |
|
| 600 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 601 | - try { |
|
| 602 | - $path = $userFolder->get($path); |
|
| 603 | - $this->lock($path); |
|
| 604 | - } catch (\OCP\Files\NotFoundException $e) { |
|
| 605 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 606 | - } catch (LockedException $e) { |
|
| 607 | - throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - if ($shared_with_me === 'true') { |
|
| 612 | - $result = $this->getSharedWithMe($path, $include_tags); |
|
| 613 | - return $result; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - if ($subfiles === 'true') { |
|
| 617 | - $result = $this->getSharesInDir($path); |
|
| 618 | - return $result; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - if ($reshares === 'true') { |
|
| 622 | - $reshares = true; |
|
| 623 | - } else { |
|
| 624 | - $reshares = false; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - // Get all shares |
|
| 628 | - $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
| 629 | - $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
| 630 | - $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
| 631 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 632 | - $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
| 633 | - } else { |
|
| 634 | - $mailShares = []; |
|
| 635 | - } |
|
| 636 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 637 | - $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
| 638 | - } else { |
|
| 639 | - $circleShares = []; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
| 643 | - |
|
| 644 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 645 | - $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
| 646 | - $shares = array_merge($shares, $federatedShares); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - $formatted = []; |
|
| 650 | - foreach ($shares as $share) { |
|
| 651 | - try { |
|
| 652 | - $formatted[] = $this->formatShare($share, $path); |
|
| 653 | - } catch (NotFoundException $e) { |
|
| 654 | - //Ignore share |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - if ($include_tags) { |
|
| 659 | - $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - return new DataResponse($formatted); |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * @NoAdminRequired |
|
| 667 | - * |
|
| 668 | - * @param int $id |
|
| 669 | - * @param int $permissions |
|
| 670 | - * @param string $password |
|
| 671 | - * @param string $publicUpload |
|
| 672 | - * @param string $expireDate |
|
| 673 | - * @return DataResponse |
|
| 674 | - * @throws OCSNotFoundException |
|
| 675 | - * @throws OCSBadRequestException |
|
| 676 | - * @throws OCSForbiddenException |
|
| 677 | - */ |
|
| 678 | - public function updateShare( |
|
| 679 | - $id, |
|
| 680 | - $permissions = null, |
|
| 681 | - $password = null, |
|
| 682 | - $publicUpload = null, |
|
| 683 | - $expireDate = null |
|
| 684 | - ) { |
|
| 685 | - try { |
|
| 686 | - $share = $this->getShareById($id); |
|
| 687 | - } catch (ShareNotFound $e) { |
|
| 688 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - $this->lock($share->getNode()); |
|
| 692 | - |
|
| 693 | - if (!$this->canAccessShare($share, false)) { |
|
| 694 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
| 698 | - throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - /* |
|
| 411 | + $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
| 412 | + if (!empty($existingShares)) { |
|
| 413 | + return new DataResponse($this->formatShare($existingShares[0])); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + if ($publicUpload === 'true') { |
|
| 417 | + // Check if public upload is allowed |
|
| 418 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 419 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + // Public upload can only be set for folders |
|
| 423 | + if ($path instanceof \OCP\Files\File) { |
|
| 424 | + throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + $share->setPermissions( |
|
| 428 | + Constants::PERMISSION_READ | |
|
| 429 | + Constants::PERMISSION_CREATE | |
|
| 430 | + Constants::PERMISSION_UPDATE | |
|
| 431 | + Constants::PERMISSION_DELETE |
|
| 432 | + ); |
|
| 433 | + } else { |
|
| 434 | + $share->setPermissions(Constants::PERMISSION_READ); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // Set password |
|
| 438 | + if ($password !== '') { |
|
| 439 | + $share->setPassword($password); |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + //Expire date |
|
| 443 | + if ($expireDate !== '') { |
|
| 444 | + try { |
|
| 445 | + $expireDate = $this->parseDate($expireDate); |
|
| 446 | + $share->setExpirationDate($expireDate); |
|
| 447 | + } catch (\Exception $e) { |
|
| 448 | + throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 453 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 454 | + throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $share->setSharedWith($shareWith); |
|
| 458 | + $share->setPermissions($permissions); |
|
| 459 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 460 | + if ($share->getNodeType() === 'file') { |
|
| 461 | + $share->setPermissions(Constants::PERMISSION_READ); |
|
| 462 | + } else { |
|
| 463 | + $share->setPermissions($permissions); |
|
| 464 | + } |
|
| 465 | + $share->setSharedWith($shareWith); |
|
| 466 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 467 | + if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
| 468 | + throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith); |
|
| 472 | + |
|
| 473 | + // Valid circle is required to share |
|
| 474 | + if ($circle === null) { |
|
| 475 | + throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
| 476 | + } |
|
| 477 | + $share->setSharedWith($shareWith); |
|
| 478 | + $share->setPermissions($permissions); |
|
| 479 | + } else { |
|
| 480 | + throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + $share->setShareType($shareType); |
|
| 484 | + $share->setSharedBy($this->currentUser); |
|
| 485 | + |
|
| 486 | + try { |
|
| 487 | + $share = $this->shareManager->createShare($share); |
|
| 488 | + } catch (GenericShareException $e) { |
|
| 489 | + $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
| 490 | + throw new OCSException($e->getHint(), $code); |
|
| 491 | + } catch (\Exception $e) { |
|
| 492 | + throw new OCSForbiddenException($e->getMessage()); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $output = $this->formatShare($share); |
|
| 496 | + |
|
| 497 | + return new DataResponse($output); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
| 502 | + * @param boolean $includeTags |
|
| 503 | + * @return DataResponse |
|
| 504 | + */ |
|
| 505 | + private function getSharedWithMe($node = null, $includeTags) { |
|
| 506 | + |
|
| 507 | + $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
| 508 | + $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
| 509 | + $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
| 510 | + |
|
| 511 | + $shares = array_merge($userShares, $groupShares, $circleShares); |
|
| 512 | + |
|
| 513 | + $shares = array_filter($shares, function (IShare $share) { |
|
| 514 | + return $share->getShareOwner() !== $this->currentUser; |
|
| 515 | + }); |
|
| 516 | + |
|
| 517 | + $formatted = []; |
|
| 518 | + foreach ($shares as $share) { |
|
| 519 | + if ($this->canAccessShare($share)) { |
|
| 520 | + try { |
|
| 521 | + $formatted[] = $this->formatShare($share); |
|
| 522 | + } catch (NotFoundException $e) { |
|
| 523 | + // Ignore this share |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + if ($includeTags) { |
|
| 529 | + $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + return new DataResponse($formatted); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * @param \OCP\Files\Folder $folder |
|
| 537 | + * @return DataResponse |
|
| 538 | + * @throws OCSBadRequestException |
|
| 539 | + */ |
|
| 540 | + private function getSharesInDir($folder) { |
|
| 541 | + if (!($folder instanceof \OCP\Files\Folder)) { |
|
| 542 | + throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + $nodes = $folder->getDirectoryListing(); |
|
| 546 | + /** @var \OCP\Share\IShare[] $shares */ |
|
| 547 | + $shares = []; |
|
| 548 | + foreach ($nodes as $node) { |
|
| 549 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
| 550 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
| 551 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
| 552 | + if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 553 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
| 554 | + } |
|
| 555 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 556 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + $formatted = []; |
|
| 561 | + foreach ($shares as $share) { |
|
| 562 | + try { |
|
| 563 | + $formatted[] = $this->formatShare($share); |
|
| 564 | + } catch (NotFoundException $e) { |
|
| 565 | + //Ignore this share |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + return new DataResponse($formatted); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * The getShares function. |
|
| 574 | + * |
|
| 575 | + * @NoAdminRequired |
|
| 576 | + * |
|
| 577 | + * @param string $shared_with_me |
|
| 578 | + * @param string $reshares |
|
| 579 | + * @param string $subfiles |
|
| 580 | + * @param string $path |
|
| 581 | + * |
|
| 582 | + * - Get shares by the current user |
|
| 583 | + * - Get shares by the current user and reshares (?reshares=true) |
|
| 584 | + * - Get shares with the current user (?shared_with_me=true) |
|
| 585 | + * - Get shares for a specific path (?path=...) |
|
| 586 | + * - Get all shares in a folder (?subfiles=true&path=..) |
|
| 587 | + * |
|
| 588 | + * @return DataResponse |
|
| 589 | + * @throws OCSNotFoundException |
|
| 590 | + */ |
|
| 591 | + public function getShares( |
|
| 592 | + $shared_with_me = 'false', |
|
| 593 | + $reshares = 'false', |
|
| 594 | + $subfiles = 'false', |
|
| 595 | + $path = null, |
|
| 596 | + $include_tags = 'false' |
|
| 597 | + ) { |
|
| 598 | + |
|
| 599 | + if ($path !== null) { |
|
| 600 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 601 | + try { |
|
| 602 | + $path = $userFolder->get($path); |
|
| 603 | + $this->lock($path); |
|
| 604 | + } catch (\OCP\Files\NotFoundException $e) { |
|
| 605 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 606 | + } catch (LockedException $e) { |
|
| 607 | + throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + if ($shared_with_me === 'true') { |
|
| 612 | + $result = $this->getSharedWithMe($path, $include_tags); |
|
| 613 | + return $result; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + if ($subfiles === 'true') { |
|
| 617 | + $result = $this->getSharesInDir($path); |
|
| 618 | + return $result; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + if ($reshares === 'true') { |
|
| 622 | + $reshares = true; |
|
| 623 | + } else { |
|
| 624 | + $reshares = false; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + // Get all shares |
|
| 628 | + $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
| 629 | + $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
| 630 | + $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
| 631 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 632 | + $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
| 633 | + } else { |
|
| 634 | + $mailShares = []; |
|
| 635 | + } |
|
| 636 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 637 | + $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
| 638 | + } else { |
|
| 639 | + $circleShares = []; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
| 643 | + |
|
| 644 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 645 | + $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
| 646 | + $shares = array_merge($shares, $federatedShares); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + $formatted = []; |
|
| 650 | + foreach ($shares as $share) { |
|
| 651 | + try { |
|
| 652 | + $formatted[] = $this->formatShare($share, $path); |
|
| 653 | + } catch (NotFoundException $e) { |
|
| 654 | + //Ignore share |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + if ($include_tags) { |
|
| 659 | + $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + return new DataResponse($formatted); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * @NoAdminRequired |
|
| 667 | + * |
|
| 668 | + * @param int $id |
|
| 669 | + * @param int $permissions |
|
| 670 | + * @param string $password |
|
| 671 | + * @param string $publicUpload |
|
| 672 | + * @param string $expireDate |
|
| 673 | + * @return DataResponse |
|
| 674 | + * @throws OCSNotFoundException |
|
| 675 | + * @throws OCSBadRequestException |
|
| 676 | + * @throws OCSForbiddenException |
|
| 677 | + */ |
|
| 678 | + public function updateShare( |
|
| 679 | + $id, |
|
| 680 | + $permissions = null, |
|
| 681 | + $password = null, |
|
| 682 | + $publicUpload = null, |
|
| 683 | + $expireDate = null |
|
| 684 | + ) { |
|
| 685 | + try { |
|
| 686 | + $share = $this->getShareById($id); |
|
| 687 | + } catch (ShareNotFound $e) { |
|
| 688 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + $this->lock($share->getNode()); |
|
| 692 | + |
|
| 693 | + if (!$this->canAccessShare($share, false)) { |
|
| 694 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
| 698 | + throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + /* |
|
| 702 | 702 | * expirationdate, password and publicUpload only make sense for link shares |
| 703 | 703 | */ |
| 704 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 705 | - |
|
| 706 | - $newPermissions = null; |
|
| 707 | - if ($publicUpload === 'true') { |
|
| 708 | - $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
| 709 | - } else if ($publicUpload === 'false') { |
|
| 710 | - $newPermissions = Constants::PERMISSION_READ; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - if ($permissions !== null) { |
|
| 714 | - $newPermissions = (int)$permissions; |
|
| 715 | - $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - if ($newPermissions !== null && |
|
| 719 | - !in_array($newPermissions, [ |
|
| 720 | - Constants::PERMISSION_READ, |
|
| 721 | - Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy |
|
| 722 | - Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct |
|
| 723 | - Constants::PERMISSION_CREATE, // hidden file list |
|
| 724 | - Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files |
|
| 725 | - ]) |
|
| 726 | - ) { |
|
| 727 | - throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - if ( |
|
| 731 | - // legacy |
|
| 732 | - $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) || |
|
| 733 | - // correct |
|
| 734 | - $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 735 | - ) { |
|
| 736 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 737 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 741 | - throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - // normalize to correct public upload permissions |
|
| 745 | - $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - if ($newPermissions !== null) { |
|
| 749 | - $share->setPermissions($newPermissions); |
|
| 750 | - $permissions = $newPermissions; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - if ($expireDate === '') { |
|
| 754 | - $share->setExpirationDate(null); |
|
| 755 | - } else if ($expireDate !== null) { |
|
| 756 | - try { |
|
| 757 | - $expireDate = $this->parseDate($expireDate); |
|
| 758 | - } catch (\Exception $e) { |
|
| 759 | - throw new OCSBadRequestException($e->getMessage()); |
|
| 760 | - } |
|
| 761 | - $share->setExpirationDate($expireDate); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - if ($password === '') { |
|
| 765 | - $share->setPassword(null); |
|
| 766 | - } else if ($password !== null) { |
|
| 767 | - $share->setPassword($password); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - } else { |
|
| 771 | - if ($permissions !== null) { |
|
| 772 | - $permissions = (int)$permissions; |
|
| 773 | - $share->setPermissions($permissions); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 777 | - if ($password === '') { |
|
| 778 | - $share->setPassword(null); |
|
| 779 | - } else if ($password !== null) { |
|
| 780 | - $share->setPassword($password); |
|
| 781 | - } |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - if ($expireDate === '') { |
|
| 785 | - $share->setExpirationDate(null); |
|
| 786 | - } else if ($expireDate !== null) { |
|
| 787 | - try { |
|
| 788 | - $expireDate = $this->parseDate($expireDate); |
|
| 789 | - } catch (\Exception $e) { |
|
| 790 | - throw new OCSBadRequestException($e->getMessage()); |
|
| 791 | - } |
|
| 792 | - $share->setExpirationDate($expireDate); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
| 798 | - /* Check if this is an incomming share */ |
|
| 799 | - $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
| 800 | - $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
| 801 | - |
|
| 802 | - /** @var \OCP\Share\IShare[] $incomingShares */ |
|
| 803 | - if (!empty($incomingShares)) { |
|
| 804 | - $maxPermissions = 0; |
|
| 805 | - foreach ($incomingShares as $incomingShare) { |
|
| 806 | - $maxPermissions |= $incomingShare->getPermissions(); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if ($share->getPermissions() & ~$maxPermissions) { |
|
| 810 | - throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - |
|
| 816 | - try { |
|
| 817 | - $share = $this->shareManager->updateShare($share); |
|
| 818 | - } catch (\Exception $e) { |
|
| 819 | - throw new OCSBadRequestException($e->getMessage()); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - return new DataResponse($this->formatShare($share)); |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * @param \OCP\Share\IShare $share |
|
| 827 | - * @return bool |
|
| 828 | - */ |
|
| 829 | - protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
| 830 | - // A file with permissions 0 can't be accessed by us. So Don't show it |
|
| 831 | - if ($share->getPermissions() === 0) { |
|
| 832 | - return false; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - // Owner of the file and the sharer of the file can always get share |
|
| 836 | - if ($share->getShareOwner() === $this->currentUser || |
|
| 837 | - $share->getSharedBy() === $this->currentUser |
|
| 838 | - ) { |
|
| 839 | - return true; |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - // If the share is shared with you (or a group you are a member of) |
|
| 843 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 844 | - $share->getSharedWith() === $this->currentUser |
|
| 845 | - ) { |
|
| 846 | - return true; |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 850 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 851 | - $user = $this->userManager->get($this->currentUser); |
|
| 852 | - if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
| 853 | - return true; |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 858 | - // TODO: have a sanity check like above? |
|
| 859 | - return true; |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - return false; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * Make sure that the passed date is valid ISO 8601 |
|
| 867 | - * So YYYY-MM-DD |
|
| 868 | - * If not throw an exception |
|
| 869 | - * |
|
| 870 | - * @param string $expireDate |
|
| 871 | - * |
|
| 872 | - * @throws \Exception |
|
| 873 | - * @return \DateTime |
|
| 874 | - */ |
|
| 875 | - private function parseDate($expireDate) { |
|
| 876 | - try { |
|
| 877 | - $date = new \DateTime($expireDate); |
|
| 878 | - } catch (\Exception $e) { |
|
| 879 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - if ($date === false) { |
|
| 883 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - $date->setTime(0, 0, 0); |
|
| 887 | - |
|
| 888 | - return $date; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * Since we have multiple providers but the OCS Share API v1 does |
|
| 893 | - * not support this we need to check all backends. |
|
| 894 | - * |
|
| 895 | - * @param string $id |
|
| 896 | - * @return \OCP\Share\IShare |
|
| 897 | - * @throws ShareNotFound |
|
| 898 | - */ |
|
| 899 | - private function getShareById($id) { |
|
| 900 | - $share = null; |
|
| 901 | - |
|
| 902 | - // First check if it is an internal share. |
|
| 903 | - try { |
|
| 904 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
| 905 | - return $share; |
|
| 906 | - } catch (ShareNotFound $e) { |
|
| 907 | - // Do nothing, just try the other share type |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - try { |
|
| 912 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 913 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
| 914 | - return $share; |
|
| 915 | - } |
|
| 916 | - } catch (ShareNotFound $e) { |
|
| 917 | - // Do nothing, just try the other share type |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - try { |
|
| 921 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 922 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
| 923 | - return $share; |
|
| 924 | - } |
|
| 925 | - } catch (ShareNotFound $e) { |
|
| 926 | - // Do nothing, just try the other share type |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 930 | - throw new ShareNotFound(); |
|
| 931 | - } |
|
| 932 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
| 933 | - |
|
| 934 | - return $share; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - /** |
|
| 938 | - * Lock a Node |
|
| 939 | - * |
|
| 940 | - * @param \OCP\Files\Node $node |
|
| 941 | - */ |
|
| 942 | - private function lock(\OCP\Files\Node $node) { |
|
| 943 | - $node->lock(ILockingProvider::LOCK_SHARED); |
|
| 944 | - $this->lockedNode = $node; |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * Cleanup the remaining locks |
|
| 949 | - */ |
|
| 950 | - public function cleanup() { |
|
| 951 | - if ($this->lockedNode !== null) { |
|
| 952 | - $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
| 953 | - } |
|
| 954 | - } |
|
| 704 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 705 | + |
|
| 706 | + $newPermissions = null; |
|
| 707 | + if ($publicUpload === 'true') { |
|
| 708 | + $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
| 709 | + } else if ($publicUpload === 'false') { |
|
| 710 | + $newPermissions = Constants::PERMISSION_READ; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + if ($permissions !== null) { |
|
| 714 | + $newPermissions = (int)$permissions; |
|
| 715 | + $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + if ($newPermissions !== null && |
|
| 719 | + !in_array($newPermissions, [ |
|
| 720 | + Constants::PERMISSION_READ, |
|
| 721 | + Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy |
|
| 722 | + Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct |
|
| 723 | + Constants::PERMISSION_CREATE, // hidden file list |
|
| 724 | + Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files |
|
| 725 | + ]) |
|
| 726 | + ) { |
|
| 727 | + throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + if ( |
|
| 731 | + // legacy |
|
| 732 | + $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) || |
|
| 733 | + // correct |
|
| 734 | + $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 735 | + ) { |
|
| 736 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 737 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 741 | + throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + // normalize to correct public upload permissions |
|
| 745 | + $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + if ($newPermissions !== null) { |
|
| 749 | + $share->setPermissions($newPermissions); |
|
| 750 | + $permissions = $newPermissions; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + if ($expireDate === '') { |
|
| 754 | + $share->setExpirationDate(null); |
|
| 755 | + } else if ($expireDate !== null) { |
|
| 756 | + try { |
|
| 757 | + $expireDate = $this->parseDate($expireDate); |
|
| 758 | + } catch (\Exception $e) { |
|
| 759 | + throw new OCSBadRequestException($e->getMessage()); |
|
| 760 | + } |
|
| 761 | + $share->setExpirationDate($expireDate); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + if ($password === '') { |
|
| 765 | + $share->setPassword(null); |
|
| 766 | + } else if ($password !== null) { |
|
| 767 | + $share->setPassword($password); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + } else { |
|
| 771 | + if ($permissions !== null) { |
|
| 772 | + $permissions = (int)$permissions; |
|
| 773 | + $share->setPermissions($permissions); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 777 | + if ($password === '') { |
|
| 778 | + $share->setPassword(null); |
|
| 779 | + } else if ($password !== null) { |
|
| 780 | + $share->setPassword($password); |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + if ($expireDate === '') { |
|
| 785 | + $share->setExpirationDate(null); |
|
| 786 | + } else if ($expireDate !== null) { |
|
| 787 | + try { |
|
| 788 | + $expireDate = $this->parseDate($expireDate); |
|
| 789 | + } catch (\Exception $e) { |
|
| 790 | + throw new OCSBadRequestException($e->getMessage()); |
|
| 791 | + } |
|
| 792 | + $share->setExpirationDate($expireDate); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
| 798 | + /* Check if this is an incomming share */ |
|
| 799 | + $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
| 800 | + $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
| 801 | + |
|
| 802 | + /** @var \OCP\Share\IShare[] $incomingShares */ |
|
| 803 | + if (!empty($incomingShares)) { |
|
| 804 | + $maxPermissions = 0; |
|
| 805 | + foreach ($incomingShares as $incomingShare) { |
|
| 806 | + $maxPermissions |= $incomingShare->getPermissions(); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if ($share->getPermissions() & ~$maxPermissions) { |
|
| 810 | + throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + |
|
| 816 | + try { |
|
| 817 | + $share = $this->shareManager->updateShare($share); |
|
| 818 | + } catch (\Exception $e) { |
|
| 819 | + throw new OCSBadRequestException($e->getMessage()); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + return new DataResponse($this->formatShare($share)); |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * @param \OCP\Share\IShare $share |
|
| 827 | + * @return bool |
|
| 828 | + */ |
|
| 829 | + protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
| 830 | + // A file with permissions 0 can't be accessed by us. So Don't show it |
|
| 831 | + if ($share->getPermissions() === 0) { |
|
| 832 | + return false; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + // Owner of the file and the sharer of the file can always get share |
|
| 836 | + if ($share->getShareOwner() === $this->currentUser || |
|
| 837 | + $share->getSharedBy() === $this->currentUser |
|
| 838 | + ) { |
|
| 839 | + return true; |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + // If the share is shared with you (or a group you are a member of) |
|
| 843 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 844 | + $share->getSharedWith() === $this->currentUser |
|
| 845 | + ) { |
|
| 846 | + return true; |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 850 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 851 | + $user = $this->userManager->get($this->currentUser); |
|
| 852 | + if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
| 853 | + return true; |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 858 | + // TODO: have a sanity check like above? |
|
| 859 | + return true; |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + return false; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * Make sure that the passed date is valid ISO 8601 |
|
| 867 | + * So YYYY-MM-DD |
|
| 868 | + * If not throw an exception |
|
| 869 | + * |
|
| 870 | + * @param string $expireDate |
|
| 871 | + * |
|
| 872 | + * @throws \Exception |
|
| 873 | + * @return \DateTime |
|
| 874 | + */ |
|
| 875 | + private function parseDate($expireDate) { |
|
| 876 | + try { |
|
| 877 | + $date = new \DateTime($expireDate); |
|
| 878 | + } catch (\Exception $e) { |
|
| 879 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + if ($date === false) { |
|
| 883 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + $date->setTime(0, 0, 0); |
|
| 887 | + |
|
| 888 | + return $date; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * Since we have multiple providers but the OCS Share API v1 does |
|
| 893 | + * not support this we need to check all backends. |
|
| 894 | + * |
|
| 895 | + * @param string $id |
|
| 896 | + * @return \OCP\Share\IShare |
|
| 897 | + * @throws ShareNotFound |
|
| 898 | + */ |
|
| 899 | + private function getShareById($id) { |
|
| 900 | + $share = null; |
|
| 901 | + |
|
| 902 | + // First check if it is an internal share. |
|
| 903 | + try { |
|
| 904 | + $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
| 905 | + return $share; |
|
| 906 | + } catch (ShareNotFound $e) { |
|
| 907 | + // Do nothing, just try the other share type |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + try { |
|
| 912 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 913 | + $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
| 914 | + return $share; |
|
| 915 | + } |
|
| 916 | + } catch (ShareNotFound $e) { |
|
| 917 | + // Do nothing, just try the other share type |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + try { |
|
| 921 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 922 | + $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
| 923 | + return $share; |
|
| 924 | + } |
|
| 925 | + } catch (ShareNotFound $e) { |
|
| 926 | + // Do nothing, just try the other share type |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 930 | + throw new ShareNotFound(); |
|
| 931 | + } |
|
| 932 | + $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
| 933 | + |
|
| 934 | + return $share; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + /** |
|
| 938 | + * Lock a Node |
|
| 939 | + * |
|
| 940 | + * @param \OCP\Files\Node $node |
|
| 941 | + */ |
|
| 942 | + private function lock(\OCP\Files\Node $node) { |
|
| 943 | + $node->lock(ILockingProvider::LOCK_SHARED); |
|
| 944 | + $this->lockedNode = $node; |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * Cleanup the remaining locks |
|
| 949 | + */ |
|
| 950 | + public function cleanup() { |
|
| 951 | + if ($this->lockedNode !== null) { |
|
| 952 | + $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | 955 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
| 230 | 230 | $result = \OC::$server->getContactsManager()->search($query, [$property]); |
| 231 | 231 | foreach ($result as $r) { |
| 232 | - foreach($r[$property] as $value) { |
|
| 232 | + foreach ($r[$property] as $value) { |
|
| 233 | 233 | if ($value === $query) { |
| 234 | 234 | return $r['FN']; |
| 235 | 235 | } |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | |
| 511 | 511 | $shares = array_merge($userShares, $groupShares, $circleShares); |
| 512 | 512 | |
| 513 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 513 | + $shares = array_filter($shares, function(IShare $share) { |
|
| 514 | 514 | return $share->getShareOwner() !== $this->currentUser; |
| 515 | 515 | }); |
| 516 | 516 | |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
| 550 | 550 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
| 551 | 551 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
| 552 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 552 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 553 | 553 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
| 554 | 554 | } |
| 555 | 555 | if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | if ($permissions !== null) { |
| 714 | - $newPermissions = (int)$permissions; |
|
| 714 | + $newPermissions = (int) $permissions; |
|
| 715 | 715 | $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
| 716 | 716 | } |
| 717 | 717 | |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | |
| 770 | 770 | } else { |
| 771 | 771 | if ($permissions !== null) { |
| 772 | - $permissions = (int)$permissions; |
|
| 772 | + $permissions = (int) $permissions; |
|
| 773 | 773 | $share->setPermissions($permissions); |
| 774 | 774 | } |
| 775 | 775 | |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | |
| 902 | 902 | // First check if it is an internal share. |
| 903 | 903 | try { |
| 904 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
| 904 | + $share = $this->shareManager->getShareById('ocinternal:'.$id); |
|
| 905 | 905 | return $share; |
| 906 | 906 | } catch (ShareNotFound $e) { |
| 907 | 907 | // Do nothing, just try the other share type |
@@ -910,7 +910,7 @@ discard block |
||
| 910 | 910 | |
| 911 | 911 | try { |
| 912 | 912 | if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
| 913 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
| 913 | + $share = $this->shareManager->getShareById('ocCircleShare:'.$id); |
|
| 914 | 914 | return $share; |
| 915 | 915 | } |
| 916 | 916 | } catch (ShareNotFound $e) { |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | |
| 920 | 920 | try { |
| 921 | 921 | if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
| 922 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
| 922 | + $share = $this->shareManager->getShareById('ocMailShare:'.$id); |
|
| 923 | 923 | return $share; |
| 924 | 924 | } |
| 925 | 925 | } catch (ShareNotFound $e) { |
@@ -929,7 +929,7 @@ discard block |
||
| 929 | 929 | if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
| 930 | 930 | throw new ShareNotFound(); |
| 931 | 931 | } |
| 932 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
| 932 | + $share = $this->shareManager->getShareById('ocFederatedSharing:'.$id); |
|
| 933 | 933 | |
| 934 | 934 | return $share; |
| 935 | 935 | } |
@@ -27,94 +27,94 @@ |
||
| 27 | 27 | ?> |
| 28 | 28 | |
| 29 | 29 | <div class="section" id="shareAPI"> |
| 30 | - <h2><?php p($l->t('Sharing'));?></h2> |
|
| 30 | + <h2><?php p($l->t('Sharing')); ?></h2> |
|
| 31 | 31 | <a target="_blank" rel="noreferrer noopener" class="icon-info" |
| 32 | - title="<?php p($l->t('Open documentation'));?>" |
|
| 32 | + title="<?php p($l->t('Open documentation')); ?>" |
|
| 33 | 33 | href="<?php p(link_to_docs('admin-sharing')); ?>"></a> |
| 34 | - <p class="settings-hint"><?php p($l->t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.'));?></p> |
|
| 34 | + <p class="settings-hint"><?php p($l->t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.')); ?></p> |
|
| 35 | 35 | <p id="enable"> |
| 36 | 36 | <input type="checkbox" name="shareapi_enabled" id="shareAPIEnabled" class="checkbox" |
| 37 | 37 | value="1" <?php if ($_['shareAPIEnabled'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
| 38 | - <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API'));?></label><br/> |
|
| 38 | + <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API')); ?></label><br/> |
|
| 39 | 39 | </p> |
| 40 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 40 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 41 | 41 | <input type="checkbox" name="shareapi_allow_links" id="allowLinks" class="checkbox" |
| 42 | 42 | value="1" <?php if ($_['allowLinks'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
| 43 | - <label for="allowLinks"><?php p($l->t('Allow users to share via link'));?></label><br/> |
|
| 43 | + <label for="allowLinks"><?php p($l->t('Allow users to share via link')); ?></label><br/> |
|
| 44 | 44 | </p> |
| 45 | 45 | |
| 46 | 46 | <p id="publicLinkSettings" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
| 47 | 47 | <input type="checkbox" name="shareapi_allow_public_upload" id="allowPublicUpload" class="checkbox" |
| 48 | 48 | value="1" <?php if ($_['allowPublicUpload'] == 'yes') print_unescaped('checked="checked"'); ?> /> |
| 49 | - <label for="allowPublicUpload"><?php p($l->t('Allow public uploads'));?></label><br/> |
|
| 49 | + <label for="allowPublicUpload"><?php p($l->t('Allow public uploads')); ?></label><br/> |
|
| 50 | 50 | <input type="checkbox" name="shareapi_enable_link_password_by_default" id="enableLinkPasswordByDefault" class="checkbox" |
| 51 | 51 | value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
| 52 | - <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password'));?></label><br/> |
|
| 52 | + <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password')); ?></label><br/> |
|
| 53 | 53 | <input type="checkbox" name="shareapi_enforce_links_password" id="enforceLinkPassword" class="checkbox" |
| 54 | 54 | value="1" <?php if ($_['enforceLinkPassword']) print_unescaped('checked="checked"'); ?> /> |
| 55 | - <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection'));?></label><br/> |
|
| 55 | + <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection')); ?></label><br/> |
|
| 56 | 56 | |
| 57 | 57 | <input type="checkbox" name="shareapi_default_expire_date" id="shareapiDefaultExpireDate" class="checkbox" |
| 58 | 58 | value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
| 59 | - <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date'));?></label><br/> |
|
| 59 | + <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date')); ?></label><br/> |
|
| 60 | 60 | |
| 61 | 61 | </p> |
| 62 | - <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 63 | - <?php p($l->t( 'Expire after ' )); ?> |
|
| 62 | + <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 63 | + <?php p($l->t('Expire after ')); ?> |
|
| 64 | 64 | <input type="text" name='shareapi_expire_after_n_days' id="shareapiExpireAfterNDays" placeholder="<?php p('7')?>" |
| 65 | 65 | value='<?php p($_['shareExpireAfterNDays']) ?>' /> |
| 66 | - <?php p($l->t( 'days' )); ?> |
|
| 66 | + <?php p($l->t('days')); ?> |
|
| 67 | 67 | <input type="checkbox" name="shareapi_enforce_expire_date" id="shareapiEnforceExpireDate" class="checkbox" |
| 68 | 68 | value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
| 69 | - <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
|
| 69 | + <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date')); ?></label><br/> |
|
| 70 | 70 | </p> |
| 71 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 71 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 72 | 72 | <input type="checkbox" name="shareapi_allow_resharing" id="allowResharing" class="checkbox" |
| 73 | 73 | value="1" <?php if ($_['allowResharing'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
| 74 | - <label for="allowResharing"><?php p($l->t('Allow resharing'));?></label><br/> |
|
| 74 | + <label for="allowResharing"><?php p($l->t('Allow resharing')); ?></label><br/> |
|
| 75 | 75 | </p> |
| 76 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 76 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 77 | 77 | <input type="checkbox" name="shareapi_allow_group_sharing" id="allowGroupSharing" class="checkbox" |
| 78 | 78 | value="1" <?php if ($_['allowGroupSharing'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
| 79 | - <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups'));?></label><br /> |
|
| 79 | + <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups')); ?></label><br /> |
|
| 80 | 80 | </p> |
| 81 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 81 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 82 | 82 | <input type="checkbox" name="shareapi_only_share_with_group_members" id="onlyShareWithGroupMembers" class="checkbox" |
| 83 | 83 | value="1" <?php if ($_['onlyShareWithGroupMembers']) print_unescaped('checked="checked"'); ?> /> |
| 84 | - <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups'));?></label><br/> |
|
| 84 | + <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups')); ?></label><br/> |
|
| 85 | 85 | </p> |
| 86 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 86 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 87 | 87 | <input type="checkbox" name="shareapi_exclude_groups" id="shareapiExcludeGroups" class="checkbox" |
| 88 | 88 | value="1" <?php if ($_['shareExcludeGroups']) print_unescaped('checked="checked"'); ?> /> |
| 89 | - <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/> |
|
| 89 | + <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing')); ?></label><br/> |
|
| 90 | 90 | </p> |
| 91 | 91 | <p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
| 92 | 92 | <input name="shareapi_exclude_groups_list" type="hidden" id="excludedGroups" value="<?php p($_['shareExcludedGroupsList']) ?>" style="width: 400px" class="noJSAutoUpdate"/> |
| 93 | 93 | <br /> |
| 94 | 94 | <em><?php p($l->t('These groups will still be able to receive shares, but not to initiate them.')); ?></em> |
| 95 | 95 | </p> |
| 96 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 96 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 97 | 97 | <input type="checkbox" name="shareapi_allow_share_dialog_user_enumeration" value="1" id="shareapi_allow_share_dialog_user_enumeration" class="checkbox" |
| 98 | 98 | <?php if ($_['allowShareDialogUserEnumeration'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
| 99 | - <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog. If this is disabled the full username or email address needs to be entered.'));?></label><br /> |
|
| 99 | + <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog. If this is disabled the full username or email address needs to be entered.')); ?></label><br /> |
|
| 100 | 100 | </p> |
| 101 | 101 | <p> |
| 102 | 102 | <input type="checkbox" id="publicShareDisclaimer" class="checkbox noJSAutoUpdate" |
| 103 | 103 | <?php if ($_['publicShareDisclaimerText'] !== null) print_unescaped('checked="checked"'); ?> /> |
| 104 | - <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page. (Only shown when the file list is hidden.)'));?></label> |
|
| 104 | + <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page. (Only shown when the file list is hidden.)')); ?></label> |
|
| 105 | 105 | <span id="publicShareDisclaimerStatus" class="msg" style="display:none"></span> |
| 106 | 106 | <br/> |
| 107 | 107 | <textarea placeholder="<?php p($l->t('This text will be shown on the public link upload page when the file list is hidden.')) ?>" id="publicShareDisclaimerText" <?php if ($_['publicShareDisclaimerText'] === null) { print_unescaped('class="hidden"'); } ?>><?php p($_['publicShareDisclaimerText']) ?></textarea> |
| 108 | 108 | </p> |
| 109 | 109 | |
| 110 | - <h3><?php p($l->t('Default share permissions'));?></h3> |
|
| 110 | + <h3><?php p($l->t('Default share permissions')); ?></h3> |
|
| 111 | 111 | <input type="hidden" name="shareapi_default_permissions" id="shareApiDefaultPermissions" class="checkbox" |
| 112 | 112 | value="<?php p($_['shareApiDefaultPermissions']) ?>" /> |
| 113 | 113 | <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
| 114 | 114 | <?php foreach ($_['shareApiDefaultPermissionsCheckboxes'] as $perm): ?> |
| 115 | 115 | <input type="checkbox" name="shareapi_default_permission_<?php p($perm['id']) ?>" id="shareapi_default_permission_<?php p($perm['id']) ?>" |
| 116 | 116 | class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) print_unescaped('checked="checked"'); ?> /> |
| 117 | - <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']);?></label> |
|
| 117 | + <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']); ?></label> |
|
| 118 | 118 | <?php endforeach ?> |
| 119 | 119 | </p> |
| 120 | 120 | </div> |
@@ -34,73 +34,139 @@ discard block |
||
| 34 | 34 | <p class="settings-hint"><?php p($l->t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.'));?></p> |
| 35 | 35 | <p id="enable"> |
| 36 | 36 | <input type="checkbox" name="shareapi_enabled" id="shareAPIEnabled" class="checkbox" |
| 37 | - value="1" <?php if ($_['shareAPIEnabled'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 37 | + value="1" <?php if ($_['shareAPIEnabled'] === 'yes') { |
|
| 38 | + print_unescaped('checked="checked"'); |
|
| 39 | +} |
|
| 40 | +?> /> |
|
| 38 | 41 | <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API'));?></label><br/> |
| 39 | 42 | </p> |
| 40 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 43 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
| 44 | + p('hidden'); |
|
| 45 | +} |
|
| 46 | +?>"> |
|
| 41 | 47 | <input type="checkbox" name="shareapi_allow_links" id="allowLinks" class="checkbox" |
| 42 | - value="1" <?php if ($_['allowLinks'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 48 | + value="1" <?php if ($_['allowLinks'] === 'yes') { |
|
| 49 | + print_unescaped('checked="checked"'); |
|
| 50 | +} |
|
| 51 | +?> /> |
|
| 43 | 52 | <label for="allowLinks"><?php p($l->t('Allow users to share via link'));?></label><br/> |
| 44 | 53 | </p> |
| 45 | 54 | |
| 46 | - <p id="publicLinkSettings" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 55 | + <p id="publicLinkSettings" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareAPIEnabled'] === 'no') { |
|
| 56 | + p('hidden'); |
|
| 57 | +} |
|
| 58 | +?>"> |
|
| 47 | 59 | <input type="checkbox" name="shareapi_allow_public_upload" id="allowPublicUpload" class="checkbox" |
| 48 | - value="1" <?php if ($_['allowPublicUpload'] == 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 60 | + value="1" <?php if ($_['allowPublicUpload'] == 'yes') { |
|
| 61 | + print_unescaped('checked="checked"'); |
|
| 62 | +} |
|
| 63 | +?> /> |
|
| 49 | 64 | <label for="allowPublicUpload"><?php p($l->t('Allow public uploads'));?></label><br/> |
| 50 | 65 | <input type="checkbox" name="shareapi_enable_link_password_by_default" id="enableLinkPasswordByDefault" class="checkbox" |
| 51 | - value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 66 | + value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') { |
|
| 67 | + print_unescaped('checked="checked"'); |
|
| 68 | +} |
|
| 69 | +?> /> |
|
| 52 | 70 | <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password'));?></label><br/> |
| 53 | 71 | <input type="checkbox" name="shareapi_enforce_links_password" id="enforceLinkPassword" class="checkbox" |
| 54 | - value="1" <?php if ($_['enforceLinkPassword']) print_unescaped('checked="checked"'); ?> /> |
|
| 72 | + value="1" <?php if ($_['enforceLinkPassword']) { |
|
| 73 | + print_unescaped('checked="checked"'); |
|
| 74 | +} |
|
| 75 | +?> /> |
|
| 55 | 76 | <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection'));?></label><br/> |
| 56 | 77 | |
| 57 | 78 | <input type="checkbox" name="shareapi_default_expire_date" id="shareapiDefaultExpireDate" class="checkbox" |
| 58 | - value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 79 | + value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') { |
|
| 80 | + print_unescaped('checked="checked"'); |
|
| 81 | +} |
|
| 82 | +?> /> |
|
| 59 | 83 | <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date'));?></label><br/> |
| 60 | 84 | |
| 61 | 85 | </p> |
| 62 | - <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 86 | + <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') { |
|
| 87 | + p('hidden'); |
|
| 88 | +} |
|
| 89 | +?>"> |
|
| 63 | 90 | <?php p($l->t( 'Expire after ' )); ?> |
| 64 | 91 | <input type="text" name='shareapi_expire_after_n_days' id="shareapiExpireAfterNDays" placeholder="<?php p('7')?>" |
| 65 | 92 | value='<?php p($_['shareExpireAfterNDays']) ?>' /> |
| 66 | 93 | <?php p($l->t( 'days' )); ?> |
| 67 | 94 | <input type="checkbox" name="shareapi_enforce_expire_date" id="shareapiEnforceExpireDate" class="checkbox" |
| 68 | - value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 95 | + value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') { |
|
| 96 | + print_unescaped('checked="checked"'); |
|
| 97 | +} |
|
| 98 | +?> /> |
|
| 69 | 99 | <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
| 70 | 100 | </p> |
| 71 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 101 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
| 102 | + p('hidden'); |
|
| 103 | +} |
|
| 104 | +?>"> |
|
| 72 | 105 | <input type="checkbox" name="shareapi_allow_resharing" id="allowResharing" class="checkbox" |
| 73 | - value="1" <?php if ($_['allowResharing'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 106 | + value="1" <?php if ($_['allowResharing'] === 'yes') { |
|
| 107 | + print_unescaped('checked="checked"'); |
|
| 108 | +} |
|
| 109 | +?> /> |
|
| 74 | 110 | <label for="allowResharing"><?php p($l->t('Allow resharing'));?></label><br/> |
| 75 | 111 | </p> |
| 76 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 112 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
| 113 | + p('hidden'); |
|
| 114 | +} |
|
| 115 | +?>"> |
|
| 77 | 116 | <input type="checkbox" name="shareapi_allow_group_sharing" id="allowGroupSharing" class="checkbox" |
| 78 | - value="1" <?php if ($_['allowGroupSharing'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 117 | + value="1" <?php if ($_['allowGroupSharing'] === 'yes') { |
|
| 118 | + print_unescaped('checked="checked"'); |
|
| 119 | +} |
|
| 120 | +?> /> |
|
| 79 | 121 | <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups'));?></label><br /> |
| 80 | 122 | </p> |
| 81 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 123 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
| 124 | + p('hidden'); |
|
| 125 | +} |
|
| 126 | +?>"> |
|
| 82 | 127 | <input type="checkbox" name="shareapi_only_share_with_group_members" id="onlyShareWithGroupMembers" class="checkbox" |
| 83 | - value="1" <?php if ($_['onlyShareWithGroupMembers']) print_unescaped('checked="checked"'); ?> /> |
|
| 128 | + value="1" <?php if ($_['onlyShareWithGroupMembers']) { |
|
| 129 | + print_unescaped('checked="checked"'); |
|
| 130 | +} |
|
| 131 | +?> /> |
|
| 84 | 132 | <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups'));?></label><br/> |
| 85 | 133 | </p> |
| 86 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 134 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
| 135 | + p('hidden'); |
|
| 136 | +} |
|
| 137 | +?>"> |
|
| 87 | 138 | <input type="checkbox" name="shareapi_exclude_groups" id="shareapiExcludeGroups" class="checkbox" |
| 88 | - value="1" <?php if ($_['shareExcludeGroups']) print_unescaped('checked="checked"'); ?> /> |
|
| 139 | + value="1" <?php if ($_['shareExcludeGroups']) { |
|
| 140 | + print_unescaped('checked="checked"'); |
|
| 141 | +} |
|
| 142 | +?> /> |
|
| 89 | 143 | <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/> |
| 90 | 144 | </p> |
| 91 | - <p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 145 | + <p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') { |
|
| 146 | + p('hidden'); |
|
| 147 | +} |
|
| 148 | +?>"> |
|
| 92 | 149 | <input name="shareapi_exclude_groups_list" type="hidden" id="excludedGroups" value="<?php p($_['shareExcludedGroupsList']) ?>" style="width: 400px" class="noJSAutoUpdate"/> |
| 93 | 150 | <br /> |
| 94 | 151 | <em><?php p($l->t('These groups will still be able to receive shares, but not to initiate them.')); ?></em> |
| 95 | 152 | </p> |
| 96 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
| 153 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
| 154 | + p('hidden'); |
|
| 155 | +} |
|
| 156 | +?>"> |
|
| 97 | 157 | <input type="checkbox" name="shareapi_allow_share_dialog_user_enumeration" value="1" id="shareapi_allow_share_dialog_user_enumeration" class="checkbox" |
| 98 | - <?php if ($_['allowShareDialogUserEnumeration'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
| 158 | + <?php if ($_['allowShareDialogUserEnumeration'] === 'yes') { |
|
| 159 | + print_unescaped('checked="checked"'); |
|
| 160 | +} |
|
| 161 | +?> /> |
|
| 99 | 162 | <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog. If this is disabled the full username or email address needs to be entered.'));?></label><br /> |
| 100 | 163 | </p> |
| 101 | 164 | <p> |
| 102 | 165 | <input type="checkbox" id="publicShareDisclaimer" class="checkbox noJSAutoUpdate" |
| 103 | - <?php if ($_['publicShareDisclaimerText'] !== null) print_unescaped('checked="checked"'); ?> /> |
|
| 166 | + <?php if ($_['publicShareDisclaimerText'] !== null) { |
|
| 167 | + print_unescaped('checked="checked"'); |
|
| 168 | +} |
|
| 169 | +?> /> |
|
| 104 | 170 | <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page. (Only shown when the file list is hidden.)'));?></label> |
| 105 | 171 | <span id="publicShareDisclaimerStatus" class="msg" style="display:none"></span> |
| 106 | 172 | <br/> |
@@ -110,10 +176,16 @@ discard block |
||
| 110 | 176 | <h3><?php p($l->t('Default share permissions'));?></h3> |
| 111 | 177 | <input type="hidden" name="shareapi_default_permissions" id="shareApiDefaultPermissions" class="checkbox" |
| 112 | 178 | value="<?php p($_['shareApiDefaultPermissions']) ?>" /> |
| 113 | - <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
| 179 | + <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
|
| 180 | + p('hidden'); |
|
| 181 | +} |
|
| 182 | +?>"> |
|
| 114 | 183 | <?php foreach ($_['shareApiDefaultPermissionsCheckboxes'] as $perm): ?> |
| 115 | 184 | <input type="checkbox" name="shareapi_default_permission_<?php p($perm['id']) ?>" id="shareapi_default_permission_<?php p($perm['id']) ?>" |
| 116 | - class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) print_unescaped('checked="checked"'); ?> /> |
|
| 185 | + class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) { |
|
| 186 | + print_unescaped('checked="checked"'); |
|
| 187 | +} |
|
| 188 | +?> /> |
|
| 117 | 189 | <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']);?></label> |
| 118 | 190 | <?php endforeach ?> |
| 119 | 191 | </p> |
@@ -35,97 +35,97 @@ |
||
| 35 | 35 | use OCP\Util; |
| 36 | 36 | |
| 37 | 37 | class Sharing implements ISettings { |
| 38 | - /** @var IConfig */ |
|
| 39 | - private $config; |
|
| 38 | + /** @var IConfig */ |
|
| 39 | + private $config; |
|
| 40 | 40 | |
| 41 | - /** @var IL10N */ |
|
| 42 | - private $l; |
|
| 41 | + /** @var IL10N */ |
|
| 42 | + private $l; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param IConfig $config |
|
| 46 | - */ |
|
| 47 | - public function __construct(IConfig $config, IL10N $l) { |
|
| 48 | - $this->config = $config; |
|
| 49 | - $this->l = $l; |
|
| 50 | - } |
|
| 44 | + /** |
|
| 45 | + * @param IConfig $config |
|
| 46 | + */ |
|
| 47 | + public function __construct(IConfig $config, IL10N $l) { |
|
| 48 | + $this->config = $config; |
|
| 49 | + $this->l = $l; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return TemplateResponse |
|
| 54 | - */ |
|
| 55 | - public function getForm() { |
|
| 56 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 57 | - $excludeGroupsList = !is_null(json_decode($excludedGroups)) |
|
| 58 | - ? implode('|', json_decode($excludedGroups, true)) : ''; |
|
| 52 | + /** |
|
| 53 | + * @return TemplateResponse |
|
| 54 | + */ |
|
| 55 | + public function getForm() { |
|
| 56 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 57 | + $excludeGroupsList = !is_null(json_decode($excludedGroups)) |
|
| 58 | + ? implode('|', json_decode($excludedGroups, true)) : ''; |
|
| 59 | 59 | |
| 60 | - $parameters = [ |
|
| 61 | - // Built-In Sharing |
|
| 62 | - 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), |
|
| 63 | - 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), |
|
| 64 | - 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), |
|
| 65 | - 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), |
|
| 66 | - 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), |
|
| 67 | - 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), |
|
| 68 | - 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(), |
|
| 69 | - 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), |
|
| 70 | - 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), |
|
| 71 | - 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), |
|
| 72 | - 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), |
|
| 73 | - 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false, |
|
| 74 | - 'shareExcludedGroupsList' => $excludeGroupsList, |
|
| 75 | - 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), |
|
| 76 | - 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'), |
|
| 77 | - 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL), |
|
| 78 | - 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(), |
|
| 79 | - ]; |
|
| 60 | + $parameters = [ |
|
| 61 | + // Built-In Sharing |
|
| 62 | + 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), |
|
| 63 | + 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), |
|
| 64 | + 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), |
|
| 65 | + 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), |
|
| 66 | + 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), |
|
| 67 | + 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), |
|
| 68 | + 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(), |
|
| 69 | + 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), |
|
| 70 | + 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), |
|
| 71 | + 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), |
|
| 72 | + 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), |
|
| 73 | + 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false, |
|
| 74 | + 'shareExcludedGroupsList' => $excludeGroupsList, |
|
| 75 | + 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), |
|
| 76 | + 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'), |
|
| 77 | + 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL), |
|
| 78 | + 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(), |
|
| 79 | + ]; |
|
| 80 | 80 | |
| 81 | - return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, ''); |
|
| 82 | - } |
|
| 81 | + return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, ''); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * get share permission list for template |
|
| 86 | - * |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - private function getSharePermissionList() { |
|
| 90 | - return [ |
|
| 91 | - [ |
|
| 92 | - 'id' => 'cancreate', |
|
| 93 | - 'label' => $this->l->t('Create'), |
|
| 94 | - 'value' => Constants::PERMISSION_CREATE |
|
| 95 | - ], |
|
| 96 | - [ |
|
| 97 | - 'id' => 'canupdate', |
|
| 98 | - 'label' => $this->l->t('Change'), |
|
| 99 | - 'value' => Constants::PERMISSION_UPDATE |
|
| 100 | - ], |
|
| 101 | - [ |
|
| 102 | - 'id' => 'candelete', |
|
| 103 | - 'label' => $this->l->t('Delete'), |
|
| 104 | - 'value' => Constants::PERMISSION_DELETE |
|
| 105 | - ], |
|
| 106 | - [ |
|
| 107 | - 'id' => 'canshare', |
|
| 108 | - 'label' => $this->l->t('Share'), |
|
| 109 | - 'value' => Constants::PERMISSION_SHARE |
|
| 110 | - ], |
|
| 111 | - ]; |
|
| 112 | - } |
|
| 84 | + /** |
|
| 85 | + * get share permission list for template |
|
| 86 | + * |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + private function getSharePermissionList() { |
|
| 90 | + return [ |
|
| 91 | + [ |
|
| 92 | + 'id' => 'cancreate', |
|
| 93 | + 'label' => $this->l->t('Create'), |
|
| 94 | + 'value' => Constants::PERMISSION_CREATE |
|
| 95 | + ], |
|
| 96 | + [ |
|
| 97 | + 'id' => 'canupdate', |
|
| 98 | + 'label' => $this->l->t('Change'), |
|
| 99 | + 'value' => Constants::PERMISSION_UPDATE |
|
| 100 | + ], |
|
| 101 | + [ |
|
| 102 | + 'id' => 'candelete', |
|
| 103 | + 'label' => $this->l->t('Delete'), |
|
| 104 | + 'value' => Constants::PERMISSION_DELETE |
|
| 105 | + ], |
|
| 106 | + [ |
|
| 107 | + 'id' => 'canshare', |
|
| 108 | + 'label' => $this->l->t('Share'), |
|
| 109 | + 'value' => Constants::PERMISSION_SHARE |
|
| 110 | + ], |
|
| 111 | + ]; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * @return string the section ID, e.g. 'sharing' |
|
| 116 | - */ |
|
| 117 | - public function getSection() { |
|
| 118 | - return 'sharing'; |
|
| 119 | - } |
|
| 114 | + /** |
|
| 115 | + * @return string the section ID, e.g. 'sharing' |
|
| 116 | + */ |
|
| 117 | + public function getSection() { |
|
| 118 | + return 'sharing'; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @return int whether the form should be rather on the top or bottom of |
|
| 123 | - * the admin section. The forms are arranged in ascending order of the |
|
| 124 | - * priority values. It is required to return a value between 0 and 100. |
|
| 125 | - * |
|
| 126 | - * E.g.: 70 |
|
| 127 | - */ |
|
| 128 | - public function getPriority() { |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 121 | + /** |
|
| 122 | + * @return int whether the form should be rather on the top or bottom of |
|
| 123 | + * the admin section. The forms are arranged in ascending order of the |
|
| 124 | + * priority values. It is required to return a value between 0 and 100. |
|
| 125 | + * |
|
| 126 | + * E.g.: 70 |
|
| 127 | + */ |
|
| 128 | + public function getPriority() { |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | 131 | } |