mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-06 00:36:39 +00:00
Authorized the backend
This commit is contained in:
parent
f15d725a93
commit
6d93e88dcf
12 changed files with 39 additions and 35 deletions
|
|
@ -13,7 +13,7 @@ using TicketManager.DTO;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
// [Authorize]
|
||||
[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route("api/v1/users")]
|
||||
[ApiController]
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ using System;
|
|||
namespace TicketManager.Controllers
|
||||
{
|
||||
// [Authorize(Roles = "Admin")]
|
||||
// [Authorize]
|
||||
[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
|
|
@ -180,6 +180,9 @@ namespace TicketManager.Controllers
|
|||
EndingDate = projectDto.EndingDate,
|
||||
Manager = await _context.AppUsers.FindAsync(projectDto.ManagerId)
|
||||
};
|
||||
// project.LogAction(
|
||||
// $"{project.Title} has been created by {project.Manager.FullName}.",
|
||||
// ActivityType.StartTask);
|
||||
|
||||
_context.Projects.Add(project);
|
||||
await _context.SaveChangesAsync();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using TicketManager.Models;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
// [Authorize]
|
||||
[Authorize]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class TicketsController : ControllerBase
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace TicketManager.Models
|
|||
public string Description { get; set; }
|
||||
public DateTime UpdateDate { get; private set; } = DateTime.Now;
|
||||
public ActivityType ActivityType { get; set; } = ActivityType.Undefined;
|
||||
public AppUser User { get; set; }
|
||||
public int UserId { get; set; }
|
||||
// public Guid UserId { get; set; }
|
||||
public int TaskId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -3,25 +3,13 @@ using System.Collections.Generic;
|
|||
|
||||
namespace TicketManager.Models
|
||||
{
|
||||
// public interface ITask
|
||||
public abstract class ITask
|
||||
public interface ITask
|
||||
{
|
||||
int Id { get; set; }
|
||||
string Title { get; set; }
|
||||
string Description { get; set; }
|
||||
DateTime CreationDate { get; }
|
||||
DateTime PlannedEnding { get; set; }
|
||||
DateTime EndingDate { get; set; }
|
||||
List<Activity> Activities { get; set; }
|
||||
|
||||
public virtual void AddLogEntry(string description)//, User user)
|
||||
{
|
||||
Activity Activity = new Activity()
|
||||
{
|
||||
Description = description,
|
||||
ActivityType = ActivityType.Undefined,
|
||||
// User = user,
|
||||
};
|
||||
Activities.Add(Activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,5 +112,17 @@ namespace TicketManager.Models
|
|||
{
|
||||
this.Status = Status.Done;
|
||||
}
|
||||
|
||||
public void LogAction(string description, ActivityType type = ActivityType.Undefined)//, Guid userId)
|
||||
{
|
||||
Activity Activity = new Activity()
|
||||
{
|
||||
Description = description,
|
||||
ActivityType = type,
|
||||
TaskId = this.Id,
|
||||
// UserId = userId
|
||||
};
|
||||
Activities.Add(Activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,18 @@
|
|||
import React, { FC, useState, ChangeEvent, useEffect, FormEvent } from "react";
|
||||
import React, { FC, useState, ChangeEvent, FormEvent } from "react";
|
||||
import { Modal } from "./Modal";
|
||||
import { AvatarList } from "./AvatarList";
|
||||
import { User } from "../types/User";
|
||||
import { FilterBar } from "./FilterBar";
|
||||
import { HttpResponse } from "../types/HttpResponse";
|
||||
import { get, put, patch } from "../utils/http";
|
||||
import { patch } from "../utils/http";
|
||||
import { Constants } from "../utils/Constants";
|
||||
import { UsersModalEntry } from "./UsersModalEntry";
|
||||
import { useParams } from "react-router-dom";
|
||||
import _ from "underscore";
|
||||
|
||||
interface IProps {
|
||||
show: boolean;
|
||||
handleClose: () => void;
|
||||
users: User[];
|
||||
allUsers: User[];
|
||||
handleClose(): void;
|
||||
}
|
||||
|
||||
export const UsersModal: FC<IProps> = ({
|
||||
|
|
@ -38,13 +36,11 @@ export const UsersModal: FC<IProps> = ({
|
|||
) => {
|
||||
e.preventDefault();
|
||||
|
||||
const response: HttpResponse<User[]> = await patch<User[]>(
|
||||
await patch<User[]>(
|
||||
`${Constants.projectsURI}/${id}/members`,
|
||||
members
|
||||
members.map(m => m.id)
|
||||
);
|
||||
console.log(response);
|
||||
};
|
||||
console.log(allUsers);
|
||||
|
||||
return (
|
||||
<Modal show={show} handleClose={handleClose}>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import React, { FC } from "react";
|
||||
import { User } from "../types/User";
|
||||
import _ from "underscore";
|
||||
|
||||
interface IProps {
|
||||
setMembers: React.Dispatch<React.SetStateAction<User[]>>;
|
||||
|
|
@ -9,7 +8,7 @@ interface IProps {
|
|||
}
|
||||
|
||||
export const UsersModalEntry: FC<IProps> = ({ user, setMembers, members }) => {
|
||||
console.log(members);
|
||||
// console.log(members);
|
||||
const match: (id: string) => boolean = (id: string) => {
|
||||
return Boolean(members.find(m => m.id === id));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import React, { FC } from "react";
|
|||
import { Redirect } from "react-router-dom";
|
||||
|
||||
interface IProps {
|
||||
error: any;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export const ErrorController: FC<IProps> = ({ error }) => {
|
||||
|
|
@ -10,6 +10,9 @@ export const ErrorController: FC<IProps> = ({ error }) => {
|
|||
case "Bad Request":
|
||||
return <Redirect to="/400" />;
|
||||
|
||||
case "Unauthorized":
|
||||
return <Redirect to="/401" />;
|
||||
|
||||
case "Not Found":
|
||||
return <Redirect to="/404" />;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export const ProjectController: FC = () => {
|
|||
setIsLoading(false);
|
||||
}
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
setHasError(true);
|
||||
setError(ex);
|
||||
}
|
||||
|
|
@ -42,8 +43,8 @@ export const ProjectController: FC = () => {
|
|||
setAllUsers((response.parsedBody as unknown) as User[]);
|
||||
}
|
||||
} catch (ex) {
|
||||
// setHasError(true);
|
||||
// setError(ex);
|
||||
setHasError(true);
|
||||
setError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,5 +56,7 @@ export async function patch<T>(
|
|||
|
||||
const headers: Headers = new Headers({
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
Authorization:
|
||||
"Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik1UWkNSRFEzUkRnd1FUQXlNRFExTmtOQ09UQXlSamhGTURaRU1Ea3pNRGxHUkRrelFqZENSZyJ9.eyJpc3MiOiJodHRwczovL2Rldi1meWpydm9oeC5hdXRoMC5jb20vIiwic3ViIjoiR3dlZTlGUnN3ejNWNE5vZFVRTjJIcjJyQjJTMDI1UmZAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vbG9jYWxob3N0OjUwMDEvYXBpL1YxLyIsImlhdCI6MTU4Mjk3MTQyMSwiZXhwIjoxNTgzMDU3ODIxLCJhenAiOiJHd2VlOUZSc3d6M1Y0Tm9kVVFOMkhyMnJCMlMwMjVSZiIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyJ9.mH_ejE0gpMXrMIVUV7afuagTopCxm2x7F7Ash9L7zfOCQnw71E7NPsEh8w2_nFFz3lwm988vGbJhB_1G0oetK3VnqgahHn-ZJfk8RhQeKZQtCddbFCXSZzbsvi8XekpN2qLSZswrfxM4hiNfedQW1sM6wSbVbv4q6MrpPrtnepOo5lu67b9eHQZA5MQGqCLqqAZtEAa4Z8bVUCUcf3wU4e9W38LngrMSEMN62_ZZ8AVnjFVQ97zWEadJhYT54S9tVioY8jNR-38qjuYH_ZP3mVQg8INza9YFiYzIsIgdYufhorb_cSXc1qK1ZhHf4kRHaiHCYan-c9nN9SM9MCYA9A"
|
||||
});
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export const AppRouter = () => {
|
|||
<TicketController />
|
||||
</Route> */}
|
||||
|
||||
<Route path="/404">
|
||||
<Route path="/401">
|
||||
<NotFoundPage />
|
||||
</Route>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue