From d64d30664700b714554ecc4bea3d6bda97bb3731 Mon Sep 17 00:00:00 2001 From: wastilla Date: Mon, 10 Apr 2023 14:02:54 -0400 Subject: [PATCH 1/2] Removed hardcoded user and enabled users present in database to post using their own credentials --- frontend/src/app/post.service.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/post.service.ts b/frontend/src/app/post.service.ts index b30ad81..14a0e97 100644 --- a/frontend/src/app/post.service.ts +++ b/frontend/src/app/post.service.ts @@ -55,17 +55,18 @@ export class PostService { } makePost(id: number, content: string, user: Profile, votes: [], timestamp: string): Observable { - let u: User = {id:2, pid:100000000, onyen:'sol', first_name:"Sol", last_name:"Student", email:"sol@unc.edu", pronouns:"they / them",permissions:[]}; - - let post: Post = {id:id, content: content, user: u, votes: votes, timestamp:timestamp}; - console.log("Made it to api call") - console.log(JSON.stringify(post)) - try{ - return this.http.post("/api/post", post); - }catch (err){ - return throwError(() => new Error("Unable to Post from unregistered user")); + if(user.id && user.first_name && user.last_name && user.email && user.pronouns){ + let u: User = {id: user.id, pid:user.pid, onyen: user.onyen, first_name:user.first_name, last_name:user.last_name, email:user.email, pronouns:user.pronouns,permissions: []}; + let post: Post = {id:id, content: content, user: u, votes: votes, timestamp:timestamp}; + console.log("Made it to api call") + console.log(JSON.stringify(post)) + try{ + return this.http.post("/api/post", post); + }catch (err){ + return throwError(() => new Error("Unable to Post from unregistered user")); + } } - + return throwError(() => new Error("Unable to Post from user")); } // deletePost(id: number) { From 6ce5b2d29dfc8b9d80d19d116341bfb37b12f142 Mon Sep 17 00:00:00 2001 From: wastilla Date: Mon, 10 Apr 2023 14:34:11 -0400 Subject: [PATCH 2/2] Changed user permissions from empty array to the user's permissions from their profile --- frontend/src/app/post.service.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/post.service.ts b/frontend/src/app/post.service.ts index 14a0e97..0e5ec6a 100644 --- a/frontend/src/app/post.service.ts +++ b/frontend/src/app/post.service.ts @@ -14,8 +14,15 @@ export interface User{ last_name: string; email:string; pronouns:string; - permissions: []; + permissions: Permission[]; } + + export interface Permission { + id?: number; + action: string; + resource: string; + } + export interface Post { id: number; content: string; @@ -56,7 +63,7 @@ export class PostService { makePost(id: number, content: string, user: Profile, votes: [], timestamp: string): Observable { if(user.id && user.first_name && user.last_name && user.email && user.pronouns){ - let u: User = {id: user.id, pid:user.pid, onyen: user.onyen, first_name:user.first_name, last_name:user.last_name, email:user.email, pronouns:user.pronouns,permissions: []}; + let u: User = {id: user.id, pid:user.pid, onyen: user.onyen, first_name:user.first_name, last_name:user.last_name, email:user.email, pronouns:user.pronouns, permissions: user.permissions}; let post: Post = {id:id, content: content, user: u, votes: votes, timestamp:timestamp}; console.log("Made it to api call") console.log(JSON.stringify(post))