Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
expose capabilities in js
Signed-off-by: Bjoern Schiessle <[email protected]>
  • Loading branch information
schiessle authored and rullzer committed Feb 27, 2018
commit 7d0102bf7302a483209e0d1c926260713f0e56c6
8 changes: 6 additions & 2 deletions core/Controller/OCJSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -70,7 +72,8 @@ public function __construct($appName,
IConfig $config,
IGroupManager $groupManager,
IniGetWrapper $iniWrapper,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
CapabilitiesManager $capabilitiesManager) {
parent::__construct($appName, $request);

$this->helper = new JSConfigHelper(
Expand All @@ -82,7 +85,8 @@ public function __construct($appName,
$config,
$groupManager,
$iniWrapper,
$urlGenerator
$urlGenerator,
$capabilitiesManager
);
}

Expand Down
19 changes: 19 additions & 0 deletions core/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
namespace OC\Template;

use bantu\IniGetWrapper\IniGetWrapper;
use OC\CapabilitiesManager;
use OCP\App\IAppManager;
use OCP\Defaults;
use OCP\IConfig;
Expand Down Expand Up @@ -66,6 +67,9 @@ class JSConfigHelper {
/** @var IURLGenerator */
private $urlGenerator;

/** @var CapabilitiesManager */
private $capabilitiesManager;

/**
* @param IL10N $l
* @param Defaults $defaults
Expand All @@ -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,
Expand All @@ -85,7 +90,8 @@ public function __construct(IL10N $l,
IConfig $config,
IGroupManager $groupManager,
IniGetWrapper $iniWrapper,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
CapabilitiesManager $capabilitiesManager) {
$this->l = $l;
$this->defaults = $defaults;
$this->appManager = $appManager;
Expand All @@ -95,6 +101,7 @@ public function __construct(IL10N $l,
$this->groupManager = $groupManager;
$this->iniWrapper = $iniWrapper;
$this->urlGenerator = $urlGenerator;
$this->capabilitiesManager = $capabilitiesManager;
}

public function getConfig() {
Expand Down Expand Up @@ -146,6 +153,8 @@ public function getConfig() {
$lastConfirmTimestamp = 0;
}

$capabilities = $this->capabilitiesManager->getCapabilities();

$array = [
"oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
"oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
Expand Down Expand Up @@ -252,6 +261,7 @@ public function getConfig() {
'longFooter' => $this->defaults->getLongFooter(),
'folder' => \OC_Util::getTheme(),
]),
"oc_capabilities" => json_encode($capabilities),
];

if ($this->currentUser !== null) {
Expand Down
3 changes: 2 additions & 1 deletion lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public function __construct( $renderAs, $appId = '' ) {
$this->config,
\OC::$server->getGroupManager(),
\OC::$server->getIniWrapper(),
\OC::$server->getURLGenerator()
\OC::$server->getURLGenerator(),
\OC::$server->getCapabilitiesManager()
);
$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
} else {
Expand Down