yangzhang75 commented on code in PR #8125:
URL: https://github.com/apache/texera/pull/8125#discussion_r3899674400


##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowResource.scala:
##########
@@ -726,6 +758,41 @@ class WorkflowResource extends LazyLogging {
     workflowDao.update(workflow)
   }
 
+  /**
+    * Set which view a workflow opens in by default (CANVAS or FORM). Only 
this preference lives
+    * in a column; the form's definition travels in workflow.content under 
`formBinding`, so
+    * switching the default never touches it.
+    */
+  @PUT
+  @Consumes(Array(MediaType.APPLICATION_JSON))
+  @RolesAllowed(Array("REGULAR", "ADMIN"))
+  @Path("/set-default-view/{wid}")
+  def setDefaultView(
+      @PathParam("wid") wid: Integer,
+      request: DefaultViewRequest,
+      @Auth user: SessionUser
+  ): Unit = {
+    if (!WorkflowAccessResource.hasWriteAccess(wid, user.getUid)) {
+      throw new ForbiddenException(s"You do not have permission to modify 
workflow $wid")
+    }
+    val view =
+      try DefaultViewEnum.valueOf(request.view)
+      catch {
+        case _: IllegalArgumentException =>
+          throw new BadRequestException(
+            s"default_view must be CANVAS or FORM, got: ${request.view}"
+          )
+      }

Review Comment:
   Good catch. Fixed it a bit differently: 
`DefaultViewEnum.lookupLiteral(request.view)` returns null for an unknown 
literal and for a null/missing body value, so both map to a 400 rather than a 
500 (no valueOf NPE, and no separate null branch needed). Added the null case 
to the invalid-value test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to