Uploaded image for project: 'OpenOLAT'
  1. OpenOLAT
  2. OO-1819

Rest-API: Creating a course with a specific initial author

    XMLWordPrintable

    Details

      Description

      When creating a course with REST, the initial author is always the person who executes the REST request. When creating courses automatically it can be recommended that the initial author is the person who will be the owner of the course after creation.

      This patch adds the new parameter initialAuthor to createEmptyCourse:

      diff --git a/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java b/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java
      --- a/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java
      +++ b/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java
      @@ -225,7 +225,7 @@
       			@QueryParam("access") Integer access, @QueryParam("membersOnly") Boolean membersOnly, 
       			@QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef,
       			@QueryParam("managedFlags") String managedFlags, @QueryParam("sharedFolderSoftKey") String sharedFolderSoftKey,
      -			@QueryParam("copyFrom") Long copyFrom,
      +			@QueryParam("copyFrom") Long copyFrom, @QueryParam("initialAuthor") Long initialAuthor,
       			@Context HttpServletRequest request) {
       		if(!isAuthor(request)) {
       			return Response.serverError().status(Status.UNAUTHORIZED).build();
      @@ -241,10 +241,15 @@
       		
       		ICourse course;
       		UserRequest ureq = getUserRequest(request);
      +		Identity id = null;
      +		if (initialAuthor != null)
      +			id = getIdentity(initialAuthor);
      +		if (id == null)
      +			id = ureq.getIdentity();
       		if(copyFrom != null) {
       			course = copyCourse(copyFrom, ureq, shortTitle, title, displayName, softKey, accessInt, membersOnlyBool, externalId, externalRef, managedFlags, configVO);
       		} else {
      -			course = createEmptyCourse(ureq.getIdentity(), shortTitle, title, displayName, softKey, accessInt, membersOnlyBool, externalId, externalRef, managedFlags, configVO);
      +			course = createEmptyCourse(id, shortTitle, title, displayName, softKey, accessInt, membersOnlyBool, externalId, externalRef, managedFlags, configVO);
       		}
       		CourseVO vo = ObjectFactory.get(course);
       		return Response.ok(vo).build();
      diff --git a/src/main/java/org/olat/restapi/security/RestSecurityHelper.java b/src/main/java/org/olat/restapi/security/RestSecurityHelper.java
      --- a/src/main/java/org/olat/restapi/security/RestSecurityHelper.java
      +++ b/src/main/java/org/olat/restapi/security/RestSecurityHelper.java
      @@ -65,6 +65,10 @@
       		return ureq.getIdentity();
       	}
       	
      +	public static Identity getIdentity(Long identityKey) {
      +		return BaseSecurityManager.getInstance().loadIdentityByKey(identityKey);
      +	}
      +	
       	public static boolean isUserManager(HttpServletRequest request) {
       		try {
       			Roles roles = getRoles(request);
      

        Attachments

          Activity

            People

            • Assignee:
              srosse Stéphane Rossé
              Reporter:
              stephan Stephan Clemenz
              Tester:
              Stephan Clemenz
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 20 minutes
                20m