Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
65e8ff34
Commit
65e8ff34
authored
11 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-948: rewrite the method to return without retrieving the owners
parent
3605ca2a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/olat/repository/RepositoryManager.java
+19
-10
19 additions, 10 deletions
src/main/java/org/olat/repository/RepositoryManager.java
src/test/java/org/olat/repository/RepositoryManagerTest.java
+43
-0
43 additions, 0 deletions
src/test/java/org/olat/repository/RepositoryManagerTest.java
with
62 additions
and
10 deletions
src/main/java/org/olat/repository/RepositoryManager.java
+
19
−
10
View file @
65e8ff34
...
...
@@ -63,6 +63,7 @@ import org.olat.core.gui.control.WindowControl;
import
org.olat.core.id.Identity
;
import
org.olat.core.id.OLATResourceable
;
import
org.olat.core.id.Roles
;
import
org.olat.core.id.UserConstants
;
import
org.olat.core.logging.AssertException
;
import
org.olat.core.logging.OLog
;
import
org.olat.core.logging.Tracing
;
...
...
@@ -2211,22 +2212,30 @@ public class RepositoryManager extends BasicManager {
* @param Identity identity
*/
public
boolean
isInstitutionalRessourceManagerFor
(
RepositoryEntry
repositoryEntry
,
Identity
identity
)
{
if
(
repositoryEntry
==
null
||
repositoryEntry
.
getOwnerGroup
()
==
null
)
return
false
;
BaseSecurity
secMgr
=
BaseSecurityManager
.
getInstance
();
// list of owners
List
<
Identity
>
listIdentities
=
secMgr
.
getIdentitiesOfSecurityGroup
(
repositoryEntry
.
getOwnerGroup
());
String
currentUserInstitutionalName
=
identity
.
getUser
().
getProperty
(
"institutionalName"
,
null
);
boolean
isInstitutionalResourceManager
=
BaseSecurityManager
.
getInstance
().
isIdentityPermittedOnResourceable
(
identity
,
Constants
.
PERMISSION_HASROLE
,
Constants
.
ORESOURCE_INSTORESMANAGER
);
if
(
repositoryEntry
==
null
||
repositoryEntry
.
getOwnerGroup
()
==
null
)
{
return
false
;
}
String
currentUserInstitutionalName
=
identity
.
getUser
().
getProperty
(
UserConstants
.
INSTITUTIONALNAME
,
null
);
if
(!
StringHelper
.
containsNonWhitespace
(
currentUserInstitutionalName
))
{
return
false
;
}
boolean
isInstitutionalResourceManager
=
securityManager
.
isIdentityPermittedOnResourceable
(
identity
,
Constants
.
PERMISSION_HASROLE
,
Constants
.
ORESOURCE_INSTORESMANAGER
);
if
(!
isInstitutionalResourceManager
)
{
return
false
;
}
boolean
sameInstitutional
=
false
;
String
identInstitutionalName
=
""
;
List
<
Identity
>
listIdentities
=
securityManager
.
getIdentitiesOfSecurityGroup
(
repositoryEntry
.
getOwnerGroup
())
;
for
(
Identity
ident
:
listIdentities
)
{
identInstitutionalName
=
ident
.
getUser
().
getProperty
(
"institutionalName"
,
null
);
if
(
(
identInstitutionalName
!=
null
)
&&
(
identInstitutionalName
.
equals
(
currentUserInstitutionalName
))
)
{
String
identInstitutionalName
=
ident
.
getUser
().
getProperty
(
UserConstants
.
INSTITUTIONALNAME
,
null
);
if
(
identInstitutionalName
!=
null
&&
identInstitutionalName
.
equals
(
currentUserInstitutionalName
))
{
sameInstitutional
=
true
;
break
;
}
}
return
isInstitutionalResourceManager
&&
sameInstitutional
;
return
sameInstitutional
;
}
public
int
countLearningResourcesAsStudent
(
Identity
identity
)
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/olat/repository/RepositoryManagerTest.java
+
43
−
0
View file @
65e8ff34
...
...
@@ -42,6 +42,7 @@ import org.junit.After;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.olat.basesecurity.BaseSecurity
;
import
org.olat.basesecurity.Constants
;
import
org.olat.basesecurity.SecurityGroup
;
import
org.olat.core.commons.persistence.DB
;
import
org.olat.core.commons.persistence.DBFactory
;
...
...
@@ -49,6 +50,7 @@ import org.olat.core.commons.services.mark.MarkManager;
import
org.olat.core.id.Identity
;
import
org.olat.core.id.OLATResourceable
;
import
org.olat.core.id.Roles
;
import
org.olat.core.id.UserConstants
;
import
org.olat.core.logging.AssertException
;
import
org.olat.core.logging.OLog
;
import
org.olat.core.logging.Tracing
;
...
...
@@ -64,6 +66,7 @@ import org.olat.resource.OLATResourceManager;
import
org.olat.test.JMSCodePointServerJunitHelper
;
import
org.olat.test.JunitTestHelper
;
import
org.olat.test.OlatTestCase
;
import
org.olat.user.UserManager
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -79,6 +82,8 @@ public class RepositoryManagerTest extends OlatTestCase {
@Autowired
private
DB
dbInstance
;
@Autowired
private
UserManager
userManager
;
@Autowired
private
BaseSecurity
securityManager
;
@Autowired
private
OLATResourceManager
resourceManager
;
...
...
@@ -707,6 +712,44 @@ public class RepositoryManagerTest extends OlatTestCase {
Assert
.
assertNotNull
(
membership2s
);
Assert
.
assertTrue
(
membership2s
.
isEmpty
());
}
/**
* How can be a resource manager if Constants.ORESOURCE_USERMANAGER is never used?
*/
@Test
public
void
isInstitutionalRessourceManagerFor
()
{
Identity
owner1
=
JunitTestHelper
.
createAndPersistIdentityAsUser
(
"instit-"
+
UUID
.
randomUUID
().
toString
());
Identity
owner2
=
JunitTestHelper
.
createAndPersistIdentityAsUser
(
"instit-"
+
UUID
.
randomUUID
().
toString
());
Identity
part3
=
JunitTestHelper
.
createAndPersistIdentityAsUser
(
"instit-"
+
UUID
.
randomUUID
().
toString
());
RepositoryEntry
re
=
JunitTestHelper
.
createAndPersistRepositoryEntry
();
securityManager
.
addIdentityToSecurityGroup
(
owner1
,
re
.
getOwnerGroup
());
securityManager
.
addIdentityToSecurityGroup
(
owner2
,
re
.
getOwnerGroup
());
securityManager
.
addIdentityToSecurityGroup
(
part3
,
re
.
getParticipantGroup
());
dbInstance
.
commit
();
//set the institutions
owner1
.
getUser
().
setProperty
(
UserConstants
.
INSTITUTIONALNAME
,
"volks"
);
owner2
.
getUser
().
setProperty
(
UserConstants
.
INSTITUTIONALNAME
,
"volks"
);
part3
.
getUser
().
setProperty
(
UserConstants
.
INSTITUTIONALNAME
,
"volks"
);
userManager
.
updateUserFromIdentity
(
owner1
);
userManager
.
updateUserFromIdentity
(
owner2
);
userManager
.
updateUserFromIdentity
(
part3
);
dbInstance
.
commit
();
//promote owner1 to institution resource manager
SecurityGroup
institutionalResourceManagerGroup
=
securityManager
.
findSecurityGroupByName
(
Constants
.
GROUP_INST_ORES_MANAGER
);
securityManager
.
addIdentityToSecurityGroup
(
owner1
,
institutionalResourceManagerGroup
);
dbInstance
.
commitAndCloseSession
();
//check
boolean
institutionMgr1
=
repositoryManager
.
isInstitutionalRessourceManagerFor
(
re
,
owner1
);
boolean
institutionMgr2
=
repositoryManager
.
isInstitutionalRessourceManagerFor
(
re
,
owner2
);
boolean
institutionMgr3
=
repositoryManager
.
isInstitutionalRessourceManagerFor
(
re
,
part3
);
Assert
.
assertTrue
(
institutionMgr1
);
Assert
.
assertFalse
(
institutionMgr2
);
Assert
.
assertFalse
(
institutionMgr3
);
}
@Test
public
void
testCountByTypeLimitAccess
()
{
...
...
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