edit backend to accept string id, create auth/helper to extract userId

This commit is contained in:
Ruidy Nemausat 2020-05-05 13:56:12 +02:00
parent e3a1fa0d0a
commit f415e0626a
11 changed files with 26 additions and 18 deletions

View file

@ -64,7 +64,7 @@ namespace TicketManager.Controllers
[HttpGet("{id}")] [HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<AppUserDTO>> GetUser(Guid id) public async Task<ActionResult<AppUserDTO>> GetUser(string id)
{ {
var user = await _context.AppUsers var user = await _context.AppUsers
.Include(u => u.Assignments) .Include(u => u.Assignments)
@ -103,7 +103,7 @@ namespace TicketManager.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> PutUser(Guid id, AppUser user) public async Task<IActionResult> PutUser(string id, AppUser user)
{ {
if (id != user.Id) if (id != user.Id)
{ {
@ -202,7 +202,7 @@ namespace TicketManager.Controllers
} }
[HttpGet("{id}/projects")] [HttpGet("{id}/projects")]
public async Task<ActionResult<IEnumerable<ProjectDTORequest>>> GetAppUserProjects(Guid id) public async Task<ActionResult<IEnumerable<ProjectDTORequest>>> GetAppUserProjects(string id)
{ {
var user = await _context.AppUsers var user = await _context.AppUsers
.Include(u => u.Assignments) .Include(u => u.Assignments)
@ -218,7 +218,7 @@ namespace TicketManager.Controllers
} }
[HttpGet("{id}/tickets/")] [HttpGet("{id}/tickets/")]
public async Task<ActionResult<IEnumerable<TicketDTORead>>> GetAppUserTickets(Guid id) public async Task<ActionResult<IEnumerable<TicketDTORead>>> GetAppUserTickets(string id)
{ {
var user = await _context.AppUsers var user = await _context.AppUsers
.Include(u => u.Assignments) .Include(u => u.Assignments)
@ -233,7 +233,7 @@ namespace TicketManager.Controllers
return user.GetTickets().Select(t => new TicketDTORead(t)).ToList(); return user.GetTickets().Select(t => new TicketDTORead(t)).ToList();
} }
private bool UserExists(Guid id) private bool UserExists(string id)
{ {
return _context.AppUsers.Any(e => e.Id == id); return _context.AppUsers.Any(e => e.Id == id);
} }

View file

@ -271,7 +271,7 @@ namespace TicketManager.Controllers
[HttpPatch("{id}/members")] [HttpPatch("{id}/members")]
public async Task<ActionResult<Project>> SetProjectMembers( public async Task<ActionResult<Project>> SetProjectMembers(
[FromRoute] int id, [FromRoute] int id,
[FromBody] Guid[] membersId) [FromBody] string[] membersId)
{ {
Project project = await _context.Projects Project project = await _context.Projects
.Include(p => p.Assignments) .Include(p => p.Assignments)

View file

@ -8,7 +8,7 @@ namespace TicketManager.Models
{ {
public class AppUser public class AppUser
{ {
public Guid Id { get; set; } public string Id { get; set; }
[Required] [Required]
[StringLength(50)] [StringLength(50)]

View file

@ -5,7 +5,7 @@ namespace TicketManager.Models
public class Assignment public class Assignment
{ {
public AppUser User { get; set; } public AppUser User { get; set; }
public Guid UserId { get; set; } public string UserId { get; set; }
public Project Project { get; set; } public Project Project { get; set; }
public int ProjectId { get; set; } public int ProjectId { get; set; }
} }

View file

@ -23,7 +23,7 @@ namespace TicketManager.Resources
Tickets = user.GetTickets().Select(u => new TicketDTORead(u)).ToList(); Tickets = user.GetTickets().Select(u => new TicketDTORead(u)).ToList();
} }
public Guid Id { get; set; } public string Id { get; set; }
public string FirstName { get; set; } public string FirstName { get; set; }

View file

@ -20,7 +20,7 @@ namespace TicketManager.Resources
Picture = user.Picture; Picture = user.Picture;
} }
public Guid Id { get; set; } public string Id { get; set; }
public string FirstName { get; set; } public string FirstName { get; set; }

View file

@ -4,6 +4,8 @@ namespace TicketManager.Resources
{ {
public class NewAppUserDTO public class NewAppUserDTO
{ {
public string Id { get; set; }
[Required] [Required]
public string FirstName { get; set; } public string FirstName { get; set; }
public string LastName { get; set; } public string LastName { get; set; }

View file

@ -0,0 +1,9 @@
/**
* retrieve userId
* @param user Auth0 user object
*/
export const getUID = (user: any) => {
const { sub } = user;
const uid = sub.split("|")[1];
return uid;
};

View file

@ -3,6 +3,7 @@ import { TextField } from "@material-ui/core";
import { useAuth0 } from "../../authentication/auth0"; import { useAuth0 } from "../../authentication/auth0";
import { ProjectService } from "../../services"; import { ProjectService } from "../../services";
import Modal from "./Modal"; import Modal from "./Modal";
import { getUID } from "../../authentication/helpers";
interface IProps { interface IProps {
show: boolean; show: boolean;
@ -21,7 +22,7 @@ const NewProjectModal: FC<IProps> = ({ show, handleClose }) => {
title: title, title: title,
description: description, description: description,
endingDate: new Date(endingDate).toISOString(), endingDate: new Date(endingDate).toISOString(),
managerId: "cd179eb7-3a54-4060-b22c-3e947bdffcbc", // get current User id managerId: getUID(user), // get current User id
}; };
const token = await getTokenSilently(); const token = await getTokenSilently();

View file

@ -1,8 +1,4 @@
import React, { FC } from "react"; import React, { FC } from "react";
// import { LogInForm } from "../components/LogInForm";
// import { ProfileSelector } from "../components/ProfileSelector";
import SignInSide from "../components/SignInSide";
import { useAuth0 } from "../authentication/auth0";
const HomePage: FC = () => { const HomePage: FC = () => {
return <div>HomePage</div>; return <div>HomePage</div>;

View file

@ -1,7 +1,8 @@
import React, { FC } from "react"; import React, { FC } from "react";
import { Redirect } from "react-router-dom";
import SignInSide from "../components/SignInSide"; import SignInSide from "../components/SignInSide";
import { useAuth0 } from "../authentication/auth0"; import { useAuth0 } from "../authentication/auth0";
import { Redirect } from "react-router-dom"; import { getUID } from "../authentication/helpers";
import * as ROUTES from "../constants/routes"; import * as ROUTES from "../constants/routes";
const SigninPage: FC = () => { const SigninPage: FC = () => {
@ -9,8 +10,7 @@ const SigninPage: FC = () => {
if (isAuthenticated) { if (isAuthenticated) {
// retrieve userId // retrieve userId
const { sub } = user; const uid = getUID(user);
const uid = sub.split("|")[1];
return <Redirect to={`${ROUTES.USERS}/${uid}`} />; return <Redirect to={`${ROUTES.USERS}/${uid}`} />;
} else { } else {
return <SignInSide />; return <SignInSide />;