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


##########
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:
   A request with a missing or `null` `view` reaches 
`DefaultViewEnum.valueOf(null)`, which throws `NullPointerException` rather 
than the caught `IllegalArgumentException`, so invalid JSON input returns a 500 
instead of the promised 400. Normalize/check the nullable request value before 
calling `valueOf` (and add the null case to the endpoint spec).



-- 
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