-
Notifications
You must be signed in to change notification settings - Fork 165
feat(dashboard): add custom cover image for workflow cards #5704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ma77Ball
wants to merge
11
commits into
apache:main
Choose a base branch
from
Ma77Ball:feat/workflow-card-cover-image
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
30d4f9b
adding selectable background image for workflows in texera
Ma77Ball b63987a
Merge branch 'main' into feat/workflow-card-cover-image
Ma77Ball 89cf107
added test cases for the background cover image of workflow card view
Ma77Ball 1372059
Merge branch 'main' of github.com:apache/texera into feat/workflow-ca…
Ma77Ball 34163d1
Add workflow_cover_image table to changelog
Ma77Ball 3c5f6ed
Merge branch 'main' into feat/workflow-card-cover-image
Ma77Ball b39d019
Merge branch 'main' into feat/workflow-card-cover-image
Ma77Ball ae35885
Merge branch 'main' into feat/workflow-card-cover-image
Ma77Ball 79446d1
Merge branch 'main' into feat/workflow-card-cover-image
Ma77Ball 00480c7
Merge branch 'main' into feat/workflow-card-cover-image
Ma77Ball 60c5d39
merged main
Ma77Ball File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
253 changes: 253 additions & 0 deletions
253
...la/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowResourceCoverSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,253 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.texera.web.resource.dashboard.user.workflow | ||
|
|
||
| import org.apache.texera.auth.SessionUser | ||
| import org.apache.texera.dao.MockTexeraDB | ||
| import org.apache.texera.dao.jooq.generated.Tables._ | ||
| import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum | ||
| import org.apache.texera.dao.jooq.generated.tables.daos.{ | ||
| UserDao, | ||
| WorkflowDao, | ||
| WorkflowOfUserDao, | ||
| WorkflowUserAccessDao | ||
| } | ||
| import org.apache.texera.dao.jooq.generated.tables.pojos.{ | ||
| User, | ||
| Workflow, | ||
| WorkflowOfUser, | ||
| WorkflowUserAccess | ||
| } | ||
| import org.apache.texera.web.resource.dashboard.user.workflow.WorkflowResource.CoverImageRequest | ||
| import org.scalatest.flatspec.AnyFlatSpec | ||
| import org.scalatest.matchers.should.Matchers | ||
| import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach} | ||
|
|
||
| import java.sql.Timestamp | ||
| import javax.ws.rs.{BadRequestException, ForbiddenException, NotFoundException} | ||
|
|
||
| class WorkflowResourceCoverSpec | ||
| extends AnyFlatSpec | ||
| with Matchers | ||
| with BeforeAndAfterAll | ||
| with BeforeAndAfterEach | ||
| with MockTexeraDB { | ||
|
|
||
| private val ownerUid = 1000 + scala.util.Random.nextInt(1000) | ||
| private val readerUid = 2000 + scala.util.Random.nextInt(1000) | ||
| private val strangerUid = 3000 + scala.util.Random.nextInt(1000) | ||
| private val testWid = 5000 + scala.util.Random.nextInt(1000) | ||
|
|
||
| private val sampleImage = "data:image/jpeg;base64,/9j/4AAQSkZJRg==" | ||
|
|
||
| private var owner: User = _ | ||
| private var reader: User = _ | ||
| private var stranger: User = _ | ||
|
|
||
| private var userDao: UserDao = _ | ||
| private var workflowDao: WorkflowDao = _ | ||
| private var workflowOfUserDao: WorkflowOfUserDao = _ | ||
| private var workflowUserAccessDao: WorkflowUserAccessDao = _ | ||
| private var resource: WorkflowResource = _ | ||
|
|
||
| override protected def beforeAll(): Unit = { | ||
| initializeDBAndReplaceDSLContext() | ||
| } | ||
|
|
||
| override protected def afterAll(): Unit = shutdownDB() | ||
|
|
||
| override protected def beforeEach(): Unit = { | ||
| userDao = new UserDao(getDSLContext.configuration()) | ||
| workflowDao = new WorkflowDao(getDSLContext.configuration()) | ||
| workflowOfUserDao = new WorkflowOfUserDao(getDSLContext.configuration()) | ||
| workflowUserAccessDao = new WorkflowUserAccessDao(getDSLContext.configuration()) | ||
| resource = new WorkflowResource() | ||
|
|
||
| owner = makeUser(ownerUid, "cover_owner") | ||
| reader = makeUser(readerUid, "cover_reader") | ||
| stranger = makeUser(strangerUid, "cover_stranger") | ||
|
|
||
| val workflow = new Workflow | ||
| workflow.setWid(testWid) | ||
| workflow.setName("cover_test_workflow") | ||
| workflow.setContent("{}") | ||
| workflow.setDescription("desc") | ||
| workflow.setIsPublic(false) | ||
| workflow.setCreationTime(new Timestamp(System.currentTimeMillis())) | ||
| workflow.setLastModifiedTime(new Timestamp(System.currentTimeMillis())) | ||
|
|
||
| cleanupTestData() | ||
|
|
||
| userDao.insert(owner) | ||
| userDao.insert(reader) | ||
| userDao.insert(stranger) | ||
| workflowDao.insert(workflow) | ||
|
|
||
| val ownership = new WorkflowOfUser | ||
| ownership.setUid(ownerUid) | ||
| ownership.setWid(testWid) | ||
| workflowOfUserDao.insert(ownership) | ||
|
|
||
| grantAccess(ownerUid, PrivilegeEnum.WRITE) | ||
| grantAccess(readerUid, PrivilegeEnum.READ) | ||
| } | ||
|
|
||
| override protected def afterEach(): Unit = cleanupTestData() | ||
|
|
||
| private def makeUser(uid: Int, name: String): User = { | ||
| val user = new User | ||
| user.setUid(uid) | ||
| user.setName(name) | ||
| user.setEmail(s"$name@test.com") | ||
| user.setPassword("password") | ||
| user | ||
| } | ||
|
|
||
| private def grantAccess(uid: Int, privilege: PrivilegeEnum): Unit = { | ||
| val access = new WorkflowUserAccess | ||
| access.setUid(uid) | ||
| access.setWid(testWid) | ||
| access.setPrivilege(privilege) | ||
| workflowUserAccessDao.insert(access) | ||
| } | ||
|
|
||
| private def session(user: User): SessionUser = new SessionUser(user) | ||
|
|
||
| private def cleanupTestData(): Unit = { | ||
| getDSLContext | ||
| .deleteFrom(WORKFLOW_COVER_IMAGE) | ||
| .where(WORKFLOW_COVER_IMAGE.WID.eq(testWid)) | ||
| .execute() | ||
| getDSLContext | ||
| .deleteFrom(WORKFLOW_USER_ACCESS) | ||
| .where(WORKFLOW_USER_ACCESS.WID.eq(testWid)) | ||
| .execute() | ||
| getDSLContext | ||
| .deleteFrom(WORKFLOW_OF_USER) | ||
| .where(WORKFLOW_OF_USER.WID.eq(testWid)) | ||
| .execute() | ||
| getDSLContext | ||
| .deleteFrom(WORKFLOW) | ||
| .where(WORKFLOW.WID.eq(testWid)) | ||
| .execute() | ||
| getDSLContext | ||
| .deleteFrom(USER) | ||
| .where(USER.UID.in(ownerUid, readerUid, strangerUid)) | ||
| .execute() | ||
| } | ||
|
|
||
| "getCoverImage" should "throw NotFoundException when no cover is set" in { | ||
| assertThrows[NotFoundException] { | ||
| resource.getCoverImage(testWid, session(owner)) | ||
| } | ||
| } | ||
|
|
||
| it should "return the stored cover after it is set" in { | ||
| resource.setCoverImage(testWid, CoverImageRequest(sampleImage), session(owner)) | ||
| resource.getCoverImage(testWid, session(owner)).image shouldBe sampleImage | ||
| } | ||
|
|
||
| it should "be readable by a user with read access" in { | ||
| resource.setCoverImage(testWid, CoverImageRequest(sampleImage), session(owner)) | ||
| resource.getCoverImage(testWid, session(reader)).image shouldBe sampleImage | ||
| } | ||
|
|
||
| it should "throw ForbiddenException for a user without read access" in { | ||
| resource.setCoverImage(testWid, CoverImageRequest(sampleImage), session(owner)) | ||
| assertThrows[ForbiddenException] { | ||
| resource.getCoverImage(testWid, session(stranger)) | ||
| } | ||
| } | ||
|
|
||
| "setCoverImage" should "replace an existing cover (upsert)" in { | ||
| resource.setCoverImage(testWid, CoverImageRequest(sampleImage), session(owner)) | ||
| val replacement = "data:image/png;base64,iVBORw0KGgo=" | ||
| resource.setCoverImage(testWid, CoverImageRequest(replacement), session(owner)) | ||
| resource.getCoverImage(testWid, session(owner)).image shouldBe replacement | ||
| } | ||
|
|
||
| it should "throw BadRequestException for an empty or blank image" in { | ||
| assertThrows[BadRequestException] { | ||
| resource.setCoverImage(testWid, CoverImageRequest(""), session(owner)) | ||
| } | ||
| assertThrows[BadRequestException] { | ||
| resource.setCoverImage(testWid, CoverImageRequest(" "), session(owner)) | ||
| } | ||
| } | ||
|
|
||
| it should "throw BadRequestException for a null image" in { | ||
| assertThrows[BadRequestException] { | ||
| resource.setCoverImage(testWid, CoverImageRequest(null), session(owner)) | ||
| } | ||
| } | ||
|
|
||
| it should "throw BadRequestException when the value is not an image data URL" in { | ||
| assertThrows[BadRequestException] { | ||
| resource.setCoverImage( | ||
| testWid, | ||
| CoverImageRequest("https://example.com/a.png"), | ||
| session(owner) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| it should "throw BadRequestException when the data URL is too large" in { | ||
| val tooLarge = "data:image/jpeg;base64," + ("a" * (4 * 1024 * 1024 + 1)) | ||
| assertThrows[BadRequestException] { | ||
| resource.setCoverImage(testWid, CoverImageRequest(tooLarge), session(owner)) | ||
| } | ||
| } | ||
|
|
||
| it should "throw ForbiddenException for a user with only read access" in { | ||
| assertThrows[ForbiddenException] { | ||
| resource.setCoverImage(testWid, CoverImageRequest(sampleImage), session(reader)) | ||
| } | ||
| } | ||
|
|
||
| it should "not persist a cover when validation fails" in { | ||
| assertThrows[BadRequestException] { | ||
| resource.setCoverImage(testWid, CoverImageRequest("not-a-data-url"), session(owner)) | ||
| } | ||
| assertThrows[NotFoundException] { | ||
| resource.getCoverImage(testWid, session(owner)) | ||
| } | ||
| } | ||
|
|
||
| "deleteCoverImage" should "remove an existing cover" in { | ||
| resource.setCoverImage(testWid, CoverImageRequest(sampleImage), session(owner)) | ||
| resource.deleteCoverImage(testWid, session(owner)) | ||
| assertThrows[NotFoundException] { | ||
| resource.getCoverImage(testWid, session(owner)) | ||
| } | ||
| } | ||
|
|
||
| it should "be idempotent when no cover is set" in { | ||
| noException should be thrownBy resource.deleteCoverImage(testWid, session(owner)) | ||
| } | ||
|
|
||
| it should "throw ForbiddenException for a user with only read access" in { | ||
| resource.setCoverImage(testWid, CoverImageRequest(sampleImage), session(owner)) | ||
| assertThrows[ForbiddenException] { | ||
| resource.deleteCoverImage(testWid, session(reader)) | ||
| } | ||
| // The cover must still be present after the rejected delete. | ||
| resource.getCoverImage(testWid, session(owner)).image shouldBe sampleImage | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.