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
fe96a2cd
Commit
fe96a2cd
authored
7 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-3287: change the access rules of the export course in the REST API
parent
cdbaab8c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/olat/restapi/repository/course/CourseWebService.java
+12
-17
12 additions, 17 deletions
.../org/olat/restapi/repository/course/CourseWebService.java
src/test/java/org/olat/restapi/CourseTest.java
+56
-0
56 additions, 0 deletions
src/test/java/org/olat/restapi/CourseTest.java
with
68 additions
and
17 deletions
src/main/java/org/olat/restapi/repository/course/CourseWebService.java
+
12
−
17
View file @
fe96a2cd
...
@@ -93,7 +93,6 @@ import org.olat.resource.OLATResource;
...
@@ -93,7 +93,6 @@ import org.olat.resource.OLATResource;
import
org.olat.resource.OLATResourceManager
;
import
org.olat.resource.OLATResourceManager
;
import
org.olat.resource.accesscontrol.ACService
;
import
org.olat.resource.accesscontrol.ACService
;
import
org.olat.resource.accesscontrol.AccessResult
;
import
org.olat.resource.accesscontrol.AccessResult
;
import
org.olat.restapi.security.RestSecurityHelper
;
import
org.olat.restapi.support.ObjectFactory
;
import
org.olat.restapi.support.ObjectFactory
;
import
org.olat.restapi.support.vo.CourseConfigVO
;
import
org.olat.restapi.support.vo.CourseConfigVO
;
import
org.olat.restapi.support.vo.CourseVO
;
import
org.olat.restapi.support.vo.CourseVO
;
...
@@ -276,37 +275,33 @@ public class CourseWebService {
...
@@ -276,37 +275,33 @@ public class CourseWebService {
@Path
(
"file"
)
@Path
(
"file"
)
@Produces
({
"application/zip"
,
MediaType
.
APPLICATION_OCTET_STREAM
})
@Produces
({
"application/zip"
,
MediaType
.
APPLICATION_OCTET_STREAM
})
public
Response
getRepoFileById
(
@Context
HttpServletRequest
request
)
{
public
Response
getRepoFileById
(
@Context
HttpServletRequest
request
)
{
if
(!
isAuthor
(
request
))
{
return
Response
.
serverError
().
status
(
Status
.
UNAUTHORIZED
).
build
();
}
RepositoryService
rs
=
CoreSpringFactory
.
getImpl
(
RepositoryService
.
class
);
RepositoryService
rs
=
CoreSpringFactory
.
getImpl
(
RepositoryService
.
class
);
RepositoryEntry
re
=
course
.
getCourseEnvironment
().
getCourseGroupManager
().
getCourseEntry
();
RepositoryEntry
re
=
course
.
getCourseEnvironment
().
getCourseGroupManager
().
getCourseEntry
();
if
(
re
==
null
)
{
if
(
re
==
null
)
{
return
Response
.
serverError
().
status
(
Status
.
NOT_FOUND
).
build
();
return
Response
.
serverError
().
status
(
Status
.
NOT_FOUND
).
build
();
}
}
RepositoryHandler
typeToDownload
=
RepositoryHandlerFactory
.
getInstance
().
getRepositoryHandler
(
re
);
RepositoryHandler
typeToDownload
=
RepositoryHandlerFactory
.
getInstance
().
getRepositoryHandler
(
re
);
if
(
typeToDownload
==
null
)
{
if
(
typeToDownload
==
null
)
{
return
Response
.
serverError
().
status
(
Status
.
NOT_FOUND
).
build
();
return
Response
.
serverError
().
status
(
Status
.
NOT_FOUND
).
build
();
}
}
Identity
identity
=
getIdentity
(
request
);
boolean
canDownload
=
re
.
getCanDownload
()
&&
typeToDownload
.
supportsDownload
();
if
(
isAdmin
(
request
)
||
RepositoryManager
.
getInstance
().
isOwnerOfRepositoryEntry
(
identity
,
re
))
{
canDownload
=
true
;
}
else
if
(!
isAuthor
(
request
))
{
return
Response
.
serverError
().
status
(
Status
.
UNAUTHORIZED
).
build
();
}
if
(!
canDownload
)
{
return
Response
.
serverError
().
status
(
Status
.
UNAUTHORIZED
).
build
();
}
OLATResource
ores
=
OLATResourceManager
.
getInstance
().
findResourceable
(
re
.
getOlatResource
());
OLATResource
ores
=
OLATResourceManager
.
getInstance
().
findResourceable
(
re
.
getOlatResource
());
if
(
ores
==
null
)
{
if
(
ores
==
null
)
{
return
Response
.
serverError
().
status
(
Status
.
NOT_FOUND
).
build
();
return
Response
.
serverError
().
status
(
Status
.
NOT_FOUND
).
build
();
}
}
Identity
identity
=
getIdentity
(
request
);
boolean
isAuthor
=
RestSecurityHelper
.
isAuthor
(
request
);
boolean
isOwner
=
RepositoryManager
.
getInstance
().
isOwnerOfRepositoryEntry
(
identity
,
re
);
if
(!(
isAuthor
|
isOwner
))
{
return
Response
.
serverError
().
status
(
Status
.
UNAUTHORIZED
).
build
();
}
boolean
canDownload
=
re
.
getCanDownload
()
&&
typeToDownload
.
supportsDownload
();
if
(!
canDownload
)
{
return
Response
.
serverError
().
status
(
Status
.
NOT_ACCEPTABLE
).
build
();
}
boolean
isAlreadyLocked
=
typeToDownload
.
isLocked
(
ores
);
boolean
isAlreadyLocked
=
typeToDownload
.
isLocked
(
ores
);
LockResult
lockResult
=
null
;
LockResult
lockResult
=
null
;
try
{
try
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/olat/restapi/CourseTest.java
+
56
−
0
View file @
fe96a2cd
...
@@ -614,6 +614,62 @@ public class CourseTest extends OlatJerseyTestCase {
...
@@ -614,6 +614,62 @@ public class CourseTest extends OlatJerseyTestCase {
Assert
.
assertEquals
(
0
,
repositoryEntry
.
getAccess
());
Assert
.
assertEquals
(
0
,
repositoryEntry
.
getAccess
());
}
}
@Test
public
void
exportCourse
()
throws
IOException
,
URISyntaxException
{
Assert
.
assertTrue
(
conn
.
login
(
"administrator"
,
"openolat"
));
Identity
author
=
JunitTestHelper
.
createAndPersistIdentityAsRndUser
(
"course-owner"
);
RepositoryEntry
course
=
JunitTestHelper
.
deployBasicCourse
(
author
);
dbInstance
.
closeSession
();
URI
request
=
UriBuilder
.
fromUri
(
getContextURI
()).
path
(
"repo"
).
path
(
"courses"
)
.
path
(
course
.
getOlatResource
().
getResourceableId
().
toString
()).
path
(
"file"
).
build
();
HttpGet
method
=
conn
.
createGet
(
request
,
"application/zip"
,
true
);
HttpResponse
response
=
conn
.
execute
(
method
);
Assert
.
assertEquals
(
200
,
response
.
getStatusLine
().
getStatusCode
());
byte
[]
exportedFile
=
EntityUtils
.
toByteArray
(
response
.
getEntity
());
Assert
.
assertTrue
(
exportedFile
.
length
>
1000
);
}
@Test
public
void
exportCourse_owner
()
throws
IOException
,
URISyntaxException
{
Identity
author
=
JunitTestHelper
.
createAndPersistIdentityAsRndUser
(
"course-owner-2"
);
RepositoryEntry
course
=
JunitTestHelper
.
deployBasicCourse
(
author
);
dbInstance
.
closeSession
();
Assert
.
assertTrue
(
conn
.
login
(
author
.
getName
(),
"A6B7C8"
));
URI
request
=
UriBuilder
.
fromUri
(
getContextURI
()).
path
(
"repo"
).
path
(
"courses"
)
.
path
(
course
.
getOlatResource
().
getResourceableId
().
toString
()).
path
(
"file"
).
build
();
HttpGet
method
=
conn
.
createGet
(
request
,
"application/zip"
,
true
);
HttpResponse
response
=
conn
.
execute
(
method
);
Assert
.
assertEquals
(
200
,
response
.
getStatusLine
().
getStatusCode
());
byte
[]
exportedFile
=
EntityUtils
.
toByteArray
(
response
.
getEntity
());
Assert
.
assertTrue
(
exportedFile
.
length
>
1000
);
}
@Test
public
void
exportCourse_notOwner
()
throws
IOException
,
URISyntaxException
{
Identity
owner
=
JunitTestHelper
.
createAndPersistIdentityAsRndUser
(
"course-owner-3"
);
Identity
otherUser
=
JunitTestHelper
.
createAndPersistIdentityAsRndUser
(
"course-owner-4"
);
RepositoryEntry
course
=
JunitTestHelper
.
deployBasicCourse
(
owner
);
dbInstance
.
closeSession
();
Assert
.
assertTrue
(
conn
.
login
(
otherUser
.
getName
(),
"A6B7C8"
));
URI
request
=
UriBuilder
.
fromUri
(
getContextURI
()).
path
(
"repo"
).
path
(
"courses"
)
.
path
(
course
.
getOlatResource
().
getResourceableId
().
toString
()).
path
(
"file"
).
build
();
HttpGet
method
=
conn
.
createGet
(
request
,
"application/zip"
,
true
);
HttpResponse
response
=
conn
.
execute
(
method
);
Assert
.
assertEquals
(
401
,
response
.
getStatusLine
().
getStatusCode
());
EntityUtils
.
consume
(
response
.
getEntity
());
}
protected
List
<
UserVO
>
parseUserArray
(
InputStream
body
)
{
protected
List
<
UserVO
>
parseUserArray
(
InputStream
body
)
{
try
{
try
{
ObjectMapper
mapper
=
new
ObjectMapper
(
jsonFactory
);
ObjectMapper
mapper
=
new
ObjectMapper
(
jsonFactory
);
...
...
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