(ctx context.Context, store database.Store, userID uuid.UUID, templateID uuid.UUID, jobStatus database.ProvisionerJobStatus)
| 787 | } |
| 788 | |
| 789 | func verifyUserCanCancelWorkspaceBuilds(ctx context.Context, store database.Store, userID uuid.UUID, templateID uuid.UUID, jobStatus database.ProvisionerJobStatus) (bool, error) { |
| 790 | // If the jobStatus is pending, we always allow cancellation regardless of |
| 791 | // the template setting as it's non-destructive to Terraform resources. |
| 792 | if jobStatus == database.ProvisionerJobStatusPending { |
| 793 | return true, nil |
| 794 | } |
| 795 | |
| 796 | template, err := store.GetTemplateByID(ctx, templateID) |
| 797 | if err != nil { |
| 798 | return false, xerrors.New("no template exists for this workspace") |
| 799 | } |
| 800 | |
| 801 | if template.AllowUserCancelWorkspaceJobs { |
| 802 | return true, nil // all users can cancel workspace builds |
| 803 | } |
| 804 | |
| 805 | user, err := store.GetUserByID(ctx, userID) |
| 806 | if err != nil { |
| 807 | return false, xerrors.New("user does not exist") |
| 808 | } |
| 809 | return slices.Contains(user.RBACRoles, rbac.RoleOwner().String()), nil // only user with "owner" role can cancel workspace builds |
| 810 | } |
| 811 | |
| 812 | // @Summary Get build parameters for workspace build |
| 813 | // @ID get-build-parameters-for-workspace-build |
no test coverage detected