From 9a95f97e227f15165c46b3f2f2f0eafbdafe1675 Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 14:12:35 -0400 Subject: [PATCH 01/12] Update user from backend instead of from LocalStorage to avoid overwriting recent user updates --- src/components/GoalTimeline/GoalsActions.tsx | 23 +++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/components/GoalTimeline/GoalsActions.tsx b/src/components/GoalTimeline/GoalsActions.tsx index baa130a62e..c374fd083f 100644 --- a/src/components/GoalTimeline/GoalsActions.tsx +++ b/src/components/GoalTimeline/GoalsActions.tsx @@ -70,7 +70,14 @@ function asyncCreateNewUserEditsObject(projectId: string) { return async () => { await Backend.createUserEdit() .then(async (userEditId: string) => { - let updatedUser: User = updateUserIfExists(projectId, userEditId); + const currentUserId = LocalStorage.getUserId(); + const currentUser = await Backend.getUser(currentUserId); + const updatedUser = updateUserWithUserEditId( + currentUser, + projectId, + userEditId + ); + LocalStorage.setCurrentUser(updatedUser); await Backend.updateUser(updatedUser); }) .catch((err) => { @@ -82,8 +89,8 @@ function asyncCreateNewUserEditsObject(projectId: string) { export function asyncGetUserEdits() { return async (dispatch: ThunkDispatch) => { const user: User | null = LocalStorage.getCurrentUser(); - if (user) { - const projectId: string = LocalStorage.getProjectId(); + const projectId: string = LocalStorage.getProjectId(); + if (user && projectId) { const userEditId: string | undefined = getUserEditId(user); if (userEditId !== undefined) { @@ -200,16 +207,6 @@ export function getUserEditId(user: User): string | undefined { } } -function updateUserIfExists(projectId: string, userEditId: string): User { - let currentUser: User | null = LocalStorage.getCurrentUser(); - let updatedUser: User = new User("", "", ""); - if (currentUser) { - updatedUser = updateUserWithUserEditId(currentUser, projectId, userEditId); - LocalStorage.setCurrentUser(updatedUser); - } - return updatedUser; -} - function updateUserWithUserEditId( user: User, projectId: string, From b274c19e414e6530c5c19fdc195645ec95893dab Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 14:23:11 -0400 Subject: [PATCH 02/12] Maintain user's login token in LocalStorage --- src/components/GoalTimeline/GoalsActions.tsx | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/GoalTimeline/GoalsActions.tsx b/src/components/GoalTimeline/GoalsActions.tsx index c374fd083f..be0711ea3b 100644 --- a/src/components/GoalTimeline/GoalsActions.tsx +++ b/src/components/GoalTimeline/GoalsActions.tsx @@ -70,15 +70,18 @@ function asyncCreateNewUserEditsObject(projectId: string) { return async () => { await Backend.createUserEdit() .then(async (userEditId: string) => { - const currentUserId = LocalStorage.getUserId(); - const currentUser = await Backend.getUser(currentUserId); - const updatedUser = updateUserWithUserEditId( - currentUser, - projectId, - userEditId - ); - LocalStorage.setCurrentUser(updatedUser); - await Backend.updateUser(updatedUser); + const LocalUser = LocalStorage.getCurrentUser(); + if (LocalUser) { + const currentUser = await Backend.getUser(LocalUser.id); + const updatedUser = updateUserWithUserEditId( + currentUser, + projectId, + userEditId + ); + updatedUser.token = LocalUser.token; + LocalStorage.setCurrentUser(updatedUser); + await Backend.updateUser(updatedUser); + } }) .catch((err) => { console.log(err); From 9d5585f76b93850159e33d5fd1931ce00696284e Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 14:33:01 -0400 Subject: [PATCH 03/12] Fix variable name --- src/components/GoalTimeline/GoalsActions.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/GoalTimeline/GoalsActions.tsx b/src/components/GoalTimeline/GoalsActions.tsx index be0711ea3b..bb96604740 100644 --- a/src/components/GoalTimeline/GoalsActions.tsx +++ b/src/components/GoalTimeline/GoalsActions.tsx @@ -70,15 +70,15 @@ function asyncCreateNewUserEditsObject(projectId: string) { return async () => { await Backend.createUserEdit() .then(async (userEditId: string) => { - const LocalUser = LocalStorage.getCurrentUser(); - if (LocalUser) { - const currentUser = await Backend.getUser(LocalUser.id); + const localUser = LocalStorage.getCurrentUser(); + if (localUser) { + const currentUser = await Backend.getUser(localUser.id); const updatedUser = updateUserWithUserEditId( currentUser, projectId, userEditId ); - updatedUser.token = LocalUser.token; + updatedUser.token = localUser.token; LocalStorage.setCurrentUser(updatedUser); await Backend.updateUser(updatedUser); } From 5099deded731962c81c2145780b0d2df0465d2f3 Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 15:18:40 -0400 Subject: [PATCH 04/12] Update user in localStorage upon project creation --- src/components/GoalTimeline/GoalsActions.tsx | 7 +++---- .../ProjectScreen/CreateProject/CreateProjectActions.tsx | 2 ++ src/types/project.tsx | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/GoalTimeline/GoalsActions.tsx b/src/components/GoalTimeline/GoalsActions.tsx index bb96604740..f3c521ef75 100644 --- a/src/components/GoalTimeline/GoalsActions.tsx +++ b/src/components/GoalTimeline/GoalsActions.tsx @@ -70,15 +70,14 @@ function asyncCreateNewUserEditsObject(projectId: string) { return async () => { await Backend.createUserEdit() .then(async (userEditId: string) => { - const localUser = LocalStorage.getCurrentUser(); - if (localUser) { - const currentUser = await Backend.getUser(localUser.id); + const currentUserId = LocalStorage.getUserId(); + if (currentUserId) { + const currentUser = await Backend.getUser(currentUserId); const updatedUser = updateUserWithUserEditId( currentUser, projectId, userEditId ); - updatedUser.token = localUser.token; LocalStorage.setCurrentUser(updatedUser); await Backend.updateUser(updatedUser); } diff --git a/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx b/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx index 1f8d8d4cb7..5a2db8006a 100644 --- a/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx +++ b/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx @@ -1,6 +1,7 @@ import { ThunkDispatch } from "redux-thunk"; import * as backend from "../../../backend"; +import { setCurrentUser } from "../../../backend/localStorage"; import history from "../../../history"; import { StoreState } from "../../../types"; import { defaultProject, Project, WritingSystem } from "../../../types/project"; @@ -59,6 +60,7 @@ export function asyncCreateProject( backend .createProject(project) .then((createdProject) => { + setCurrentUser(createdProject.user); dispatch(setCurrentProject(createdProject)); // Upload words diff --git a/src/types/project.tsx b/src/types/project.tsx index bea8c49107..792d028312 100644 --- a/src/types/project.tsx +++ b/src/types/project.tsx @@ -1,5 +1,6 @@ import { randomIntString } from "../utilities"; import { AutoComplete } from "./AutoComplete"; +import { User } from "./user"; import { SemanticDomain, testWordList, Word } from "./word"; export interface CustomField { @@ -28,6 +29,10 @@ export interface Project { autocompleteSetting: AutoComplete; } +export interface ProjectWithUser extends Project { + user: User; +} + export const defaultProject = { id: "", name: "", From c2c40554435a9e96ea28eaa4308151cd682f2876 Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 16:29:43 -0400 Subject: [PATCH 05/12] Move userEdit creation to backend --- Backend/Controllers/UserEditController.cs | 27 +++++++++++++++++++ Backend/Models/User.cs | 8 ++++++ src/backend/index.tsx | 4 +-- src/components/GoalTimeline/GoalsActions.tsx | 24 +---------------- .../tests/GoalTimelineActions.test.tsx | 4 +-- .../CreateProject/CreateProjectActions.tsx | 1 - 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/Backend/Controllers/UserEditController.cs b/Backend/Controllers/UserEditController.cs index eccecfd830..7c53447494 100644 --- a/Backend/Controllers/UserEditController.cs +++ b/Backend/Controllers/UserEditController.cs @@ -119,6 +119,33 @@ public async Task Post(string projectId) return new OkObjectResult(userEdit.Id); } + /// Creates a for user + /// POST: v1/projects/{projectId}/useredits/{userId} + /// UpdatedUser + [HttpPost("{userId}")] + public async Task Post(string projectId, string userId) + { + if (!_permissionService.HasProjectPermission(HttpContext, Permission.MergeAndCharSet)) + { + return new ForbidResult(); + } + + // Generate the new userEdit + var userEdit = new UserEdit { ProjectId = projectId }; + await _repo.Create(userEdit); + // Update the user + var currentUser = await _userService.GetUser(userId); + currentUser.WorkedProjects.Add(projectId, userEdit.Id); + await _userService.Update(userId, currentUser); + // Generate the JWT based on those new userEdit + currentUser = await _userService.MakeJwt(currentUser); + await _userService.Update(userId, currentUser); + + var output = new WithUser() { UpdatedUser = currentUser }; + + return new OkObjectResult(output); + } + /// Adds a goal to with specified id /// POST: v1/projects/{projectId}/useredits/{userEditId} /// Index of newest edit diff --git a/Backend/Models/User.cs b/Backend/Models/User.cs index b9a1c3f9b2..7e10ef38e2 100644 --- a/Backend/Models/User.cs +++ b/Backend/Models/User.cs @@ -166,4 +166,12 @@ public class Credentials public string Username { get; set; } public string Password { get; set; } } + + /// Contains UpdatedUser for Axios interceptor. + public class WithUser + { + public User UpdatedUser; + + public WithUser() { } + } } diff --git a/src/backend/index.tsx b/src/backend/index.tsx index d9745a6dcc..2a5ce02880 100644 --- a/src/backend/index.tsx +++ b/src/backend/index.tsx @@ -458,9 +458,9 @@ function goalNameToGoalTypeId(goalName: string): string { return goalType.toString(); } -export async function createUserEdit(): Promise { +export async function createUserEditForUser(): Promise { let resp = await backendServer.post( - `projects/${LocalStorage.getProjectId()}/useredits`, + `projects/${LocalStorage.getProjectId()}/useredits/${LocalStorage.getUserId()}`, "", { headers: authHeader(), diff --git a/src/components/GoalTimeline/GoalsActions.tsx b/src/components/GoalTimeline/GoalsActions.tsx index f3c521ef75..01bc2f20a6 100644 --- a/src/components/GoalTimeline/GoalsActions.tsx +++ b/src/components/GoalTimeline/GoalsActions.tsx @@ -66,28 +66,6 @@ export function asyncLoadExistingUserEdits( }; } -function asyncCreateNewUserEditsObject(projectId: string) { - return async () => { - await Backend.createUserEdit() - .then(async (userEditId: string) => { - const currentUserId = LocalStorage.getUserId(); - if (currentUserId) { - const currentUser = await Backend.getUser(currentUserId); - const updatedUser = updateUserWithUserEditId( - currentUser, - projectId, - userEditId - ); - LocalStorage.setCurrentUser(updatedUser); - await Backend.updateUser(updatedUser); - } - }) - .catch((err) => { - console.log(err); - }); - }; -} - export function asyncGetUserEdits() { return async (dispatch: ThunkDispatch) => { const user: User | null = LocalStorage.getCurrentUser(); @@ -98,7 +76,7 @@ export function asyncGetUserEdits() { if (userEditId !== undefined) { dispatch(asyncLoadExistingUserEdits(projectId, userEditId)); } else { - dispatch(asyncCreateNewUserEditsObject(projectId)); + dispatch(Backend.createUserEditForUser); } } }; diff --git a/src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx b/src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx index 308dd354b6..7571ce3651 100644 --- a/src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx +++ b/src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx @@ -40,8 +40,8 @@ jest.mock("../../../backend", () => { getUserEditById: jest.fn((_projId: string, _index: string) => { return Promise.resolve(mockUserEdit); }), - createUserEdit: jest.fn(() => { - return Promise.resolve(mockUserEditId); + createUserEditForUser: jest.fn(() => { + return Promise.resolve({}); }), updateUser: jest.fn((_user: User) => { return Promise.resolve(mockUser); diff --git a/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx b/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx index 5a2db8006a..edf7a5de78 100644 --- a/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx +++ b/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx @@ -60,7 +60,6 @@ export function asyncCreateProject( backend .createProject(project) .then((createdProject) => { - setCurrentUser(createdProject.user); dispatch(setCurrentProject(createdProject)); // Upload words From 550434a9a17437d2cafef4bd28854eef83d145c7 Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 17:08:42 -0400 Subject: [PATCH 06/12] Fix interceptor --- Backend/Controllers/UserEditController.cs | 4 ++-- src/backend/index.tsx | 8 ++++---- .../ProjectScreen/CreateProject/CreateProjectActions.tsx | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Backend/Controllers/UserEditController.cs b/Backend/Controllers/UserEditController.cs index 7c53447494..97c1b0a0c6 100644 --- a/Backend/Controllers/UserEditController.cs +++ b/Backend/Controllers/UserEditController.cs @@ -120,9 +120,9 @@ public async Task Post(string projectId) } /// Creates a for user - /// POST: v1/projects/{projectId}/useredits/{userId} + /// POST: v1/projects/{projectId}/useredits/new/{userId} /// UpdatedUser - [HttpPost("{userId}")] + [HttpPost("new/{userId}")] public async Task Post(string projectId, string userId) { if (!_permissionService.HasProjectPermission(HttpContext, Permission.MergeAndCharSet)) diff --git a/src/backend/index.tsx b/src/backend/index.tsx index 2a5ce02880..79198b6985 100644 --- a/src/backend/index.tsx +++ b/src/backend/index.tsx @@ -20,10 +20,10 @@ const backendServer = axios.create({ backendServer.interceptors.response.use( (resp) => { - if (resp.data.__UpdatedUser) { - LocalStorage.setCurrentUser(resp.data.__UpdatedUser); + if (resp.data.updatedUser) { + LocalStorage.setCurrentUser(resp.data.updatedUser); } - delete resp.data.__UpdatedUser; + delete resp.data.updatedUser; return resp; }, (err) => { @@ -460,7 +460,7 @@ function goalNameToGoalTypeId(goalName: string): string { export async function createUserEditForUser(): Promise { let resp = await backendServer.post( - `projects/${LocalStorage.getProjectId()}/useredits/${LocalStorage.getUserId()}`, + `projects/${LocalStorage.getProjectId()}/useredits/new/${LocalStorage.getUserId()}`, "", { headers: authHeader(), diff --git a/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx b/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx index edf7a5de78..09f22da775 100644 --- a/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx +++ b/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx @@ -1,7 +1,6 @@ import { ThunkDispatch } from "redux-thunk"; import * as backend from "../../../backend"; -import { setCurrentUser } from "../../../backend/localStorage"; import history from "../../../history"; import { StoreState } from "../../../types"; import { defaultProject, Project, WritingSystem } from "../../../types/project"; @@ -64,7 +63,7 @@ export function asyncCreateProject( // Upload words if (languageData) { - backend.uploadLift(createdProject, languageData).then((res) => { + backend.uploadLift(createdProject, languageData).then(() => { backend .getProject(createdProject.id) .then((res) => { From 892255323d8183af1c0b981b9a657a85a7b8db3c Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 17:11:00 -0400 Subject: [PATCH 07/12] Remove unused function --- src/components/GoalTimeline/GoalsActions.tsx | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/components/GoalTimeline/GoalsActions.tsx b/src/components/GoalTimeline/GoalsActions.tsx index 01bc2f20a6..b69c4ce658 100644 --- a/src/components/GoalTimeline/GoalsActions.tsx +++ b/src/components/GoalTimeline/GoalsActions.tsx @@ -187,15 +187,6 @@ export function getUserEditId(user: User): string | undefined { } } -function updateUserWithUserEditId( - user: User, - projectId: string, - userEditId: string -): User { - user.workedProjects[projectId] = userEditId; - return user; -} - export function getIndexInHistory(history: Goal[], currentGoal: Goal): number { for (let i = 0; i < history.length; i++) { if (history[i].hash === currentGoal.hash) { From 84a1090b5f486028bff9d9683819be0e8e9c5c08 Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 17:29:23 -0400 Subject: [PATCH 08/12] Cleanup --- .../Controllers/UserEditControllerTests.cs | 4 +-- Backend/Controllers/UserEditController.cs | 29 +++++-------------- src/backend/index.tsx | 4 +-- src/components/GoalTimeline/GoalsActions.tsx | 2 +- .../tests/GoalTimelineActions.test.tsx | 2 +- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/Backend.Tests/Controllers/UserEditControllerTests.cs b/Backend.Tests/Controllers/UserEditControllerTests.cs index 6bdbdce3b2..3d77123e97 100644 --- a/Backend.Tests/Controllers/UserEditControllerTests.cs +++ b/Backend.Tests/Controllers/UserEditControllerTests.cs @@ -89,8 +89,8 @@ public void TestGetUserEdit() public void TestCreateUserEdit() { var userEdit = new UserEdit { ProjectId = _projId }; - var id = (_userEditController.Post(_projId).Result as ObjectResult).Value as string; - userEdit.Id = id; + var withUser = (_userEditController.Post(_projId).Result as ObjectResult).Value as WithUser; + userEdit.Id = withUser.UpdatedUser.WorkedProjects[_projId]; Assert.Contains(userEdit, _userEditRepo.GetAllUserEdits(_projId).Result); } diff --git a/Backend/Controllers/UserEditController.cs b/Backend/Controllers/UserEditController.cs index 97c1b0a0c6..aad741d996 100644 --- a/Backend/Controllers/UserEditController.cs +++ b/Backend/Controllers/UserEditController.cs @@ -105,7 +105,7 @@ public async Task Get(string projectId, string userEditId) /// Creates a /// POST: v1/projects/{projectId}/useredits - /// Id of create UserEdit + /// UpdatedUser [HttpPost] public async Task Post(string projectId) { @@ -114,32 +114,17 @@ public async Task Post(string projectId) return new ForbidResult(); } - var userEdit = new UserEdit { ProjectId = projectId }; - await _repo.Create(userEdit); - return new OkObjectResult(userEdit.Id); - } - - /// Creates a for user - /// POST: v1/projects/{projectId}/useredits/new/{userId} - /// UpdatedUser - [HttpPost("new/{userId}")] - public async Task Post(string projectId, string userId) - { - if (!_permissionService.HasProjectPermission(HttpContext, Permission.MergeAndCharSet)) - { - return new ForbidResult(); - } - // Generate the new userEdit var userEdit = new UserEdit { ProjectId = projectId }; await _repo.Create(userEdit); - // Update the user - var currentUser = await _userService.GetUser(userId); + // Update current user + var currentUserId = _permissionService.GetUserId(HttpContext); + var currentUser = await _userService.GetUser(currentUserId); currentUser.WorkedProjects.Add(projectId, userEdit.Id); - await _userService.Update(userId, currentUser); - // Generate the JWT based on those new userEdit + await _userService.Update(currentUserId, currentUser); + // Generate the JWT based on the new userEdit currentUser = await _userService.MakeJwt(currentUser); - await _userService.Update(userId, currentUser); + await _userService.Update(currentUserId, currentUser); var output = new WithUser() { UpdatedUser = currentUser }; diff --git a/src/backend/index.tsx b/src/backend/index.tsx index 79198b6985..0ede4a7935 100644 --- a/src/backend/index.tsx +++ b/src/backend/index.tsx @@ -458,9 +458,9 @@ function goalNameToGoalTypeId(goalName: string): string { return goalType.toString(); } -export async function createUserEditForUser(): Promise { +export async function createUserEdit(): Promise { let resp = await backendServer.post( - `projects/${LocalStorage.getProjectId()}/useredits/new/${LocalStorage.getUserId()}`, + `projects/${LocalStorage.getProjectId()}/useredits`, "", { headers: authHeader(), diff --git a/src/components/GoalTimeline/GoalsActions.tsx b/src/components/GoalTimeline/GoalsActions.tsx index b69c4ce658..39e685bdd8 100644 --- a/src/components/GoalTimeline/GoalsActions.tsx +++ b/src/components/GoalTimeline/GoalsActions.tsx @@ -76,7 +76,7 @@ export function asyncGetUserEdits() { if (userEditId !== undefined) { dispatch(asyncLoadExistingUserEdits(projectId, userEditId)); } else { - dispatch(Backend.createUserEditForUser); + dispatch(Backend.createUserEdit); } } }; diff --git a/src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx b/src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx index 7571ce3651..c5ba7b5375 100644 --- a/src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx +++ b/src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx @@ -40,7 +40,7 @@ jest.mock("../../../backend", () => { getUserEditById: jest.fn((_projId: string, _index: string) => { return Promise.resolve(mockUserEdit); }), - createUserEditForUser: jest.fn(() => { + createUserEdit: jest.fn(() => { return Promise.resolve({}); }), updateUser: jest.fn((_user: User) => { From 01e06d24ea9670686c0c480e3ffc30d2a1d340a0 Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 17:52:09 -0400 Subject: [PATCH 09/12] Fix test --- Backend.Tests/Controllers/UserEditControllerTests.cs | 7 ++++++- Backend/Controllers/UserEditController.cs | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Backend.Tests/Controllers/UserEditControllerTests.cs b/Backend.Tests/Controllers/UserEditControllerTests.cs index 3d77123e97..7fc4cc49a4 100644 --- a/Backend.Tests/Controllers/UserEditControllerTests.cs +++ b/Backend.Tests/Controllers/UserEditControllerTests.cs @@ -21,6 +21,7 @@ public class UserEditControllerTests private string _projId; private IPermissionService _permissionService; private IUserService _userService; + private User _jwtAuthenticatedUser; [SetUp] public void Setup() @@ -36,7 +37,11 @@ public void Setup() { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; - + _jwtAuthenticatedUser = new User { Username = "user", Password = "pass" }; + _userService.Create(_jwtAuthenticatedUser); + _jwtAuthenticatedUser = _userService.Authenticate( + _jwtAuthenticatedUser.Username, _jwtAuthenticatedUser.Password).Result; + _userEditController.ControllerContext.HttpContext.Request.Headers["UserId"] = _jwtAuthenticatedUser.Id; } private UserEdit RandomUserEdit() diff --git a/Backend/Controllers/UserEditController.cs b/Backend/Controllers/UserEditController.cs index aad741d996..92cf52777d 100644 --- a/Backend/Controllers/UserEditController.cs +++ b/Backend/Controllers/UserEditController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using BackendFramework.Interfaces; using BackendFramework.Models; From a88b36eed44fd93bf4535e6e47ce88e8f52803bf Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 18:00:23 -0400 Subject: [PATCH 10/12] Retract unused ProjectWithUser from frontend --- .../ProjectScreen/CreateProject/CreateProjectActions.tsx | 2 +- src/types/project.tsx | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx b/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx index 09f22da775..1f8d8d4cb7 100644 --- a/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx +++ b/src/components/ProjectScreen/CreateProject/CreateProjectActions.tsx @@ -63,7 +63,7 @@ export function asyncCreateProject( // Upload words if (languageData) { - backend.uploadLift(createdProject, languageData).then(() => { + backend.uploadLift(createdProject, languageData).then((res) => { backend .getProject(createdProject.id) .then((res) => { diff --git a/src/types/project.tsx b/src/types/project.tsx index 792d028312..bea8c49107 100644 --- a/src/types/project.tsx +++ b/src/types/project.tsx @@ -1,6 +1,5 @@ import { randomIntString } from "../utilities"; import { AutoComplete } from "./AutoComplete"; -import { User } from "./user"; import { SemanticDomain, testWordList, Word } from "./word"; export interface CustomField { @@ -29,10 +28,6 @@ export interface Project { autocompleteSetting: AutoComplete; } -export interface ProjectWithUser extends Project { - user: User; -} - export const defaultProject = { id: "", name: "", From 68ac7fbbfa430dae7aff17d1880fa8b74bf80fdd Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Fri, 4 Sep 2020 18:22:11 -0400 Subject: [PATCH 11/12] Retract unused import --- Backend/Controllers/UserEditController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Backend/Controllers/UserEditController.cs b/Backend/Controllers/UserEditController.cs index 92cf52777d..aad741d996 100644 --- a/Backend/Controllers/UserEditController.cs +++ b/Backend/Controllers/UserEditController.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using BackendFramework.Interfaces; using BackendFramework.Models; From d7647348509d2baae743d3bf0fa3097ab5e4a865 Mon Sep 17 00:00:00 2001 From: imnasnainaec Date: Tue, 8 Sep 2020 09:59:50 -0400 Subject: [PATCH 12/12] Encourage implicit types --- src/components/GoalTimeline/GoalsActions.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/GoalTimeline/GoalsActions.tsx b/src/components/GoalTimeline/GoalsActions.tsx index 39e685bdd8..608dec2fc7 100644 --- a/src/components/GoalTimeline/GoalsActions.tsx +++ b/src/components/GoalTimeline/GoalsActions.tsx @@ -68,10 +68,10 @@ export function asyncLoadExistingUserEdits( export function asyncGetUserEdits() { return async (dispatch: ThunkDispatch) => { - const user: User | null = LocalStorage.getCurrentUser(); - const projectId: string = LocalStorage.getProjectId(); + const user = LocalStorage.getCurrentUser(); + const projectId = LocalStorage.getProjectId(); if (user && projectId) { - const userEditId: string | undefined = getUserEditId(user); + const userEditId = getUserEditId(user); if (userEditId !== undefined) { dispatch(asyncLoadExistingUserEdits(projectId, userEditId)); @@ -86,7 +86,7 @@ export function asyncAddGoalToHistory(goal: Goal) { return async (dispatch: ThunkDispatch) => { const user = LocalStorage.getCurrentUser(); if (user) { - let userEditId: string | undefined = getUserEditId(user); + const userEditId = getUserEditId(user); if (userEditId !== undefined) { dispatch(loadGoalData(goal)).then( (returnedGoal) => (goal = returnedGoal)