Skip to content

Commit 27b86aa

Browse files
authored
fix: Removing unnecessary user info returned from the backend (#4138)
### What changes were proposed in this PR? Currently the endpoint `/api/workflow/owner_user/?wid=X` returns all the information about the user, including name, email, etc. But the frontend only needs the name. This PR limits the information returned from the backend to the user name only. The main changes are as follow: 1. Change the endpoint name from `/api/workflow/owner_user` to `/api/workflow/owner_name` 2. Change the SQL query to only return name as plain text. 3. Change related uses of the endpoint in the frontend to match the new signature. 4. Added a new `WorkflowResourceDashboardUserSpec` to test this endpoint and support future testing of related endpoints. ### Any related issues, documentation, discussions? No ### How was this PR tested? Tests: <img width="1778" height="429" alt="image" src="https://github.com/user-attachments/assets/81b91d73-7396-4d97-a53f-80d4ed5ca724" /> Manually tested: <img width="1348" height="658" alt="image" src="https://github.com/user-attachments/assets/1aeba8b4-343c-407f-b1ef-ffc5b4afee1a" /> ### Was this PR authored or co-authored using generative AI tooling? No
1 parent acca01d commit 27b86aa

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowResource.scala

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -712,23 +712,16 @@ class WorkflowResource extends LazyLogging {
712712
}
713713

714714
@GET
715-
@Path("/owner_user")
716-
def getOwnerUser(@QueryParam("wid") wid: Integer): User = {
715+
@Produces(Array(MediaType.TEXT_PLAIN))
716+
@Path("/owner_name")
717+
def getOwnerName(@QueryParam("wid") wid: Integer): String = {
717718
context
718-
.select(
719-
USER.UID,
720-
USER.NAME,
721-
USER.EMAIL,
722-
USER.PASSWORD,
723-
USER.GOOGLE_ID,
724-
USER.ROLE,
725-
USER.GOOGLE_AVATAR
726-
)
727-
.from(WORKFLOW_OF_USER)
728-
.join(USER)
729-
.on(WORKFLOW_OF_USER.UID.eq(USER.UID))
719+
.select(USER.NAME)
720+
.from(USER)
721+
.join(WORKFLOW_OF_USER)
722+
.on(USER.UID.eq(WORKFLOW_OF_USER.UID))
730723
.where(WORKFLOW_OF_USER.WID.eq(wid))
731-
.fetchOneInto(classOf[User])
724+
.fetchOneInto(classOf[String])
732725
}
733726

734727
@GET

amber/src/test/scala/org/apache/texera/web/resource/dashboard/file/WorkflowResourceSpec.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,23 @@ class WorkflowResourceSpec
300300
)
301301
}
302302

303+
"WorkflowResource /owner_name" should "return owner name as plain text" in {
304+
workflowResource.persistWorkflow(testWorkflow1, sessionUser1)
305+
306+
val workflows = workflowResource.retrieveWorkflowsBySessionUser(sessionUser1)
307+
assert(workflows.nonEmpty)
308+
309+
val wid =
310+
workflows
311+
.find(_.workflow.getName == testWorkflow1.getName)
312+
.map(_.workflow.getWid)
313+
.getOrElse(workflows.head.workflow.getWid)
314+
315+
val ownerName = workflowResource.getOwnerName(wid)
316+
317+
assert(ownerName == testUser.getName)
318+
}
319+
303320
"/search API " should "be able to search for workflows in different columns in Workflow table" in {
304321
// testWorkflow1: {name: test_name, descrption: test_description, content: test_content}
305322
// search "test_name" or "test_description" or "test_content" should return testWorkflow1

frontend/src/app/common/service/workflow-persist/workflow-persist.service.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const WORKFLOW_UPDATENAME_URL = WORKFLOW_BASE_URL + "/update/name";
4141
export const WORKFLOW_UPDATEDESCRIPTION_URL = WORKFLOW_BASE_URL + "/update/description";
4242
export const WORKFLOW_OWNER_URL = WORKFLOW_BASE_URL + "/user-workflow-owners";
4343
export const WORKFLOW_ID_URL = WORKFLOW_BASE_URL + "/user-workflow-ids";
44-
export const WORKFLOW_OWNER_USER = WORKFLOW_BASE_URL + "/owner_user";
44+
export const WORKFLOW_OWNER_NAME = WORKFLOW_BASE_URL + "/owner_name";
4545
export const WORKFLOW_NAME = WORKFLOW_BASE_URL + "/workflow_name";
4646
export const WORKFLOW_PUBLIC_WORKFLOW = WORKFLOW_BASE_URL + "/publicised";
4747
export const WORKFLOW_DESCRIPTION = WORKFLOW_BASE_URL + "/workflow_description";
@@ -238,13 +238,12 @@ export class WorkflowPersistService {
238238
}
239239

240240
/**
241-
* retrieve the complete information of the owner corresponding to the wid
242-
* can be used without logging in
243-
* @param wid
241+
* Retrieve workflow owner name (no login required).
242+
* @param wid workflow id
244243
*/
245-
public getOwnerUser(wid: number): Observable<User> {
244+
public getOwnerName(wid: number): Observable<string> {
246245
const params = new HttpParams().set("wid", wid);
247-
return this.http.get<User>(`${AppSettings.getApiEndpoint()}/${WORKFLOW_OWNER_USER}`, { params });
246+
return this.http.get(`${AppSettings.getApiEndpoint()}/${WORKFLOW_OWNER_NAME}`, { params, responseType: "text" });
248247
}
249248

250249
/**

frontend/src/app/hub/component/workflow/detail/hub-workflow-detail.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ export class HubWorkflowDetailComponent implements AfterViewInit, OnDestroy, OnI
9898
this.viewCount = count;
9999
});
100100
this.workflowPersistService
101-
.getOwnerUser(this.wid)
101+
.getOwnerName(this.wid)
102102
.pipe(untilDestroyed(this))
103-
.subscribe(owner => {
104-
this.ownerName = owner.name;
103+
.subscribe(ownerName => {
104+
this.ownerName = ownerName;
105105
});
106106
this.workflowPersistService
107107
.getWorkflowName(this.wid)

0 commit comments

Comments
 (0)