Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
2b58e848
Commit
2b58e848
authored
10 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
Add getInstalledApps and getAppsForUser to the app manager
parent
9c47ab91
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/private/app/appmanager.php
+49
-17
49 additions, 17 deletions
lib/private/app/appmanager.php
lib/public/app/iappmanager.php
+17
-0
17 additions, 0 deletions
lib/public/app/iappmanager.php
tests/lib/app/manager.php
+32
-0
32 additions, 0 deletions
tests/lib/app/manager.php
with
98 additions
and
17 deletions
lib/private/app/appmanager.php
+
49
−
17
View file @
2b58e848
...
@@ -12,6 +12,7 @@ namespace OC\App;
...
@@ -12,6 +12,7 @@ namespace OC\App;
use
OCP\App\IAppManager
;
use
OCP\App\IAppManager
;
use
OCP\IAppConfig
;
use
OCP\IAppConfig
;
use
OCP\IGroupManager
;
use
OCP\IGroupManager
;
use
OCP\IUser
;
use
OCP\IUserSession
;
use
OCP\IUserSession
;
class
AppManager
implements
IAppManager
{
class
AppManager
implements
IAppManager
{
...
@@ -49,7 +50,7 @@ class AppManager implements IAppManager {
...
@@ -49,7 +50,7 @@ class AppManager implements IAppManager {
/**
/**
* @return string[] $appId => $enabled
* @return string[] $appId => $enabled
*/
*/
private
function
getInstalledApps
()
{
private
function
getInstalledApps
Values
()
{
if
(
!
$this
->
installedAppsCache
)
{
if
(
!
$this
->
installedAppsCache
)
{
$values
=
$this
->
appConfig
->
getValues
(
false
,
'enabled'
);
$values
=
$this
->
appConfig
->
getValues
(
false
,
'enabled'
);
$this
->
installedAppsCache
=
array_filter
(
$values
,
function
(
$value
)
{
$this
->
installedAppsCache
=
array_filter
(
$values
,
function
(
$value
)
{
...
@@ -60,6 +61,29 @@ class AppManager implements IAppManager {
...
@@ -60,6 +61,29 @@ class AppManager implements IAppManager {
return
$this
->
installedAppsCache
;
return
$this
->
installedAppsCache
;
}
}
/**
* List all installed apps
*
* @return string[]
*/
public
function
getInstalledApps
()
{
return
array_keys
(
$this
->
getInstalledAppsValues
());
}
/**
* List all apps enabled for a user
*
* @param \OCP\IUser $user
* @return string[]
*/
public
function
getAppsEnabledForUser
(
IUser
$user
)
{
$apps
=
$this
->
getInstalledAppsValues
();
$appsForUser
=
array_filter
(
$apps
,
function
(
$enabled
)
use
(
$user
)
{
return
$this
->
checkAppForUser
(
$enabled
,
$user
);
});
return
array_keys
(
$appsForUser
);
}
/**
/**
* Check if an app is enabled for user
* Check if an app is enabled for user
*
*
...
@@ -71,24 +95,32 @@ class AppManager implements IAppManager {
...
@@ -71,24 +95,32 @@ class AppManager implements IAppManager {
if
(
is_null
(
$user
))
{
if
(
is_null
(
$user
))
{
$user
=
$this
->
userSession
->
getUser
();
$user
=
$this
->
userSession
->
getUser
();
}
}
$installedApps
=
$this
->
getInstalledApps
();
$installedApps
=
$this
->
getInstalledApps
Values
();
if
(
isset
(
$installedApps
[
$appId
]))
{
if
(
isset
(
$installedApps
[
$appId
]))
{
$enabled
=
$installedApps
[
$appId
];
return
$this
->
checkAppForUser
(
$installedApps
[
$appId
],
$user
);
if
(
$enabled
===
'yes'
)
{
}
else
{
return
true
;
return
false
;
}
elseif
(
is_null
(
$user
))
{
}
return
false
;
}
}
else
{
$groupIds
=
json_decode
(
$enabled
);
/**
$userGroups
=
$this
->
groupManager
->
getUserGroupIds
(
$user
);
* @param string $enabled
foreach
(
$userGroups
as
$groupId
)
{
* @param IUser $user
if
(
array_search
(
$groupId
,
$groupIds
)
!==
false
)
{
* @return bool
return
true
;
*/
}
private
function
checkAppForUser
(
$enabled
,
$user
)
{
if
(
$enabled
===
'yes'
)
{
return
true
;
}
elseif
(
is_null
(
$user
))
{
return
false
;
}
else
{
$groupIds
=
json_decode
(
$enabled
);
$userGroups
=
$this
->
groupManager
->
getUserGroupIds
(
$user
);
foreach
(
$userGroups
as
$groupId
)
{
if
(
array_search
(
$groupId
,
$groupIds
)
!==
false
)
{
return
true
;
}
}
return
false
;
}
}
}
else
{
return
false
;
return
false
;
}
}
}
}
...
@@ -100,7 +132,7 @@ class AppManager implements IAppManager {
...
@@ -100,7 +132,7 @@ class AppManager implements IAppManager {
* @return bool
* @return bool
*/
*/
public
function
isInstalled
(
$appId
)
{
public
function
isInstalled
(
$appId
)
{
$installedApps
=
$this
->
getInstalledApps
();
$installedApps
=
$this
->
getInstalledApps
Values
();
return
isset
(
$installedApps
[
$appId
]);
return
isset
(
$installedApps
[
$appId
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/public/app/iappmanager.php
+
17
−
0
View file @
2b58e848
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
namespace
OCP\App
;
namespace
OCP\App
;
use
OCP\IUser
;
interface
IAppManager
{
interface
IAppManager
{
/**
/**
* Check if an app is enabled for user
* Check if an app is enabled for user
...
@@ -48,4 +50,19 @@ interface IAppManager {
...
@@ -48,4 +50,19 @@ interface IAppManager {
* @param string $appId
* @param string $appId
*/
*/
public
function
disableApp
(
$appId
);
public
function
disableApp
(
$appId
);
/**
* List all apps enabled for a user
*
* @param \OCP\IUser $user
* @return string[]
*/
public
function
getAppsEnabledForUser
(
IUser
$user
);
/**
* List all installed apps
*
* @return string[]
*/
public
function
getInstalledApps
();
}
}
This diff is collapsed.
Click to expand it.
tests/lib/app/manager.php
+
32
−
0
View file @
2b58e848
...
@@ -192,4 +192,36 @@ class Manager extends \PHPUnit_Framework_TestCase {
...
@@ -192,4 +192,36 @@ class Manager extends \PHPUnit_Framework_TestCase {
$appConfig
->
setValue
(
'test'
,
'enabled'
,
'["foo"]'
);
$appConfig
->
setValue
(
'test'
,
'enabled'
,
'["foo"]'
);
$this
->
assertTrue
(
$manager
->
isEnabledForUser
(
'test'
));
$this
->
assertTrue
(
$manager
->
isEnabledForUser
(
'test'
));
}
}
public
function
testGetInstalledApps
()
{
$userSession
=
$this
->
getMock
(
'\OCP\IUserSession'
);
$groupManager
=
$this
->
getMock
(
'\OCP\IGroupManager'
);
$appConfig
=
$this
->
getAppConfig
();
$manager
=
new
\OC\App\AppManager
(
$userSession
,
$appConfig
,
$groupManager
);
$appConfig
->
setValue
(
'test1'
,
'enabled'
,
'yes'
);
$appConfig
->
setValue
(
'test2'
,
'enabled'
,
'no'
);
$appConfig
->
setValue
(
'test3'
,
'enabled'
,
'["foo"]'
);
$this
->
assertEquals
([
'test1'
,
'test3'
],
$manager
->
getInstalledApps
());
}
public
function
testGetAppsForUser
()
{
$userSession
=
$this
->
getMock
(
'\OCP\IUserSession'
);
$groupManager
=
$this
->
getMock
(
'\OCP\IGroupManager'
);
$user
=
new
User
(
'user1'
,
null
);
$groupManager
->
expects
(
$this
->
any
())
->
method
(
'getUserGroupIds'
)
->
with
(
$user
)
->
will
(
$this
->
returnValue
(
array
(
'foo'
,
'bar'
)));
$appConfig
=
$this
->
getAppConfig
();
$manager
=
new
\OC\App\AppManager
(
$userSession
,
$appConfig
,
$groupManager
);
$appConfig
->
setValue
(
'test1'
,
'enabled'
,
'yes'
);
$appConfig
->
setValue
(
'test2'
,
'enabled'
,
'no'
);
$appConfig
->
setValue
(
'test3'
,
'enabled'
,
'["foo"]'
);
$appConfig
->
setValue
(
'test4'
,
'enabled'
,
'["asd"]'
);
$this
->
assertEquals
([
'test1'
,
'test3'
],
$manager
->
getAppsEnabledForUser
(
$user
));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment