expose capabilities in js

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2017-12-01 10:36:13 +01:00 committed by Roeland Jago Douma
parent d0a6368a8b
commit 7d0102bf73
No known key found for this signature in database
GPG key ID: F941078878347C0C
4 changed files with 38 additions and 4 deletions

View file

@ -26,6 +26,7 @@
namespace OC\Core\Controller;
use bantu\IniGetWrapper\IniGetWrapper;
use OC\CapabilitiesManager;
use OC\Template\JSConfigHelper;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
@ -59,6 +60,7 @@ class OCJSController extends Controller {
* @param IGroupManager $groupManager
* @param IniGetWrapper $iniWrapper
* @param IURLGenerator $urlGenerator
* @param CapabilitiesManager $capabilitiesManager
*/
public function __construct($appName,
IRequest $request,
@ -70,7 +72,8 @@ class OCJSController extends Controller {
IConfig $config,
IGroupManager $groupManager,
IniGetWrapper $iniWrapper,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
CapabilitiesManager $capabilitiesManager) {
parent::__construct($appName, $request);
$this->helper = new JSConfigHelper(
@ -82,7 +85,8 @@ class OCJSController extends Controller {
$config,
$groupManager,
$iniWrapper,
$urlGenerator
$urlGenerator,
$capabilitiesManager
);
}

View file

@ -80,6 +80,13 @@ var OCP = {},
*/
webroot:oc_webroot,
/**
* Capabilities
*
* @type array
*/
_capabilities: window.oc_capabilities || null,
appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false,
/**
* Currently logged in user or null if none
@ -308,6 +315,18 @@ var OCP = {},
return OC.webroot;
},
/**
* Returns the capabilities
*
* @return {array} capabilities
*
* @since 13.0
*/
getCapabilities: function() {
return OC._capabilities;
},
/**
* Returns the currently logged in user or null if there is no logged in
* user (public page mode)

View file

@ -28,6 +28,7 @@
namespace OC\Template;
use bantu\IniGetWrapper\IniGetWrapper;
use OC\CapabilitiesManager;
use OCP\App\IAppManager;
use OCP\Defaults;
use OCP\IConfig;
@ -66,6 +67,9 @@ class JSConfigHelper {
/** @var IURLGenerator */
private $urlGenerator;
/** @var CapabilitiesManager */
private $capabilitiesManager;
/**
* @param IL10N $l
* @param Defaults $defaults
@ -76,6 +80,7 @@ class JSConfigHelper {
* @param IGroupManager $groupManager
* @param IniGetWrapper $iniWrapper
* @param IURLGenerator $urlGenerator
* @param CapabilitiesManager $capabilitiesManager
*/
public function __construct(IL10N $l,
Defaults $defaults,
@ -85,7 +90,8 @@ class JSConfigHelper {
IConfig $config,
IGroupManager $groupManager,
IniGetWrapper $iniWrapper,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
CapabilitiesManager $capabilitiesManager) {
$this->l = $l;
$this->defaults = $defaults;
$this->appManager = $appManager;
@ -95,6 +101,7 @@ class JSConfigHelper {
$this->groupManager = $groupManager;
$this->iniWrapper = $iniWrapper;
$this->urlGenerator = $urlGenerator;
$this->capabilitiesManager = $capabilitiesManager;
}
public function getConfig() {
@ -146,6 +153,8 @@ class JSConfigHelper {
$lastConfirmTimestamp = 0;
}
$capabilities = $this->capabilitiesManager->getCapabilities();
$array = [
"oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
"oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
@ -252,6 +261,7 @@ class JSConfigHelper {
'longFooter' => $this->defaults->getLongFooter(),
'folder' => \OC_Util::getTheme(),
]),
"oc_capabilities" => json_encode($capabilities),
];
if ($this->currentUser !== null) {

View file

@ -156,7 +156,8 @@ class TemplateLayout extends \OC_Template {
$this->config,
\OC::$server->getGroupManager(),
\OC::$server->getIniWrapper(),
\OC::$server->getURLGenerator()
\OC::$server->getURLGenerator(),
\OC::$server->getCapabilitiesManager()
);
$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
} else {