Compare commits
51 commits
cbb62438c8
...
5803c7b29b
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5803c7b29b | ||
![]() |
d0d0e311e5 | ||
![]() |
03819aff44 | ||
![]() |
7fd128e1f3 | ||
![]() |
09a7cbced1 | ||
![]() |
ee2fb6d543 | ||
![]() |
a30a6a4988 | ||
![]() |
cda2b72d08 | ||
![]() |
4f53f9de94 | ||
![]() |
53f468d7c8 | ||
![]() |
d775a6e381 | ||
![]() |
08532444f0 | ||
![]() |
3b8b9bb3f2 | ||
![]() |
3df9ddcd4b | ||
![]() |
2ce1837223 | ||
![]() |
502cd67b4c | ||
![]() |
4dbbee3249 | ||
![]() |
e3fd9f52ca | ||
![]() |
8081f289b5 | ||
![]() |
7db03e8dbd | ||
![]() |
5f88e92415 | ||
![]() |
3125b511bb | ||
![]() |
09014c6659 | ||
![]() |
e498f0ed63 | ||
![]() |
77a24421e9 | ||
![]() |
de234c12f2 | ||
![]() |
68b01f2144 | ||
![]() |
58d9001be3 | ||
![]() |
5bcca0202b | ||
![]() |
0217f2b512 | ||
![]() |
9434c31013 | ||
![]() |
c03be8c5d9 | ||
![]() |
ba2bb1fc5e | ||
![]() |
847427a543 | ||
![]() |
b174ec8922 | ||
![]() |
b8c69fabf5 | ||
![]() |
2cfbcd15a7 | ||
![]() |
9ce70e74e9 | ||
![]() |
3e35586bbe | ||
![]() |
7e4e35f597 | ||
![]() |
17c30f5dd9 | ||
![]() |
8711f9a20d | ||
![]() |
a2bc13ec22 | ||
![]() |
652f74884f | ||
![]() |
2ffbc2f9fd | ||
![]() |
2eab030212 | ||
![]() |
ff9eba039f | ||
![]() |
ad85194d4f | ||
![]() |
f3c5abf4f3 | ||
![]() |
2be4afd0e0 | ||
![]() |
2aade5d2fe |
14 changed files with 586 additions and 168 deletions
|
@ -19,19 +19,174 @@ const docTemplate = `{
|
||||||
"host": "{{.Host}}",
|
"host": "{{.Host}}",
|
||||||
"basePath": "{{.BasePath}}",
|
"basePath": "{{.BasePath}}",
|
||||||
"paths": {
|
"paths": {
|
||||||
"/api/register": {
|
"/login": {
|
||||||
|
"post": {
|
||||||
|
"description": "logs the user in and returns a jwt token",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"User"
|
||||||
|
],
|
||||||
|
"summary": "login",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "login info",
|
||||||
|
"name": "NewUser",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/types.NewUser"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Successfully signed token for user",
|
||||||
|
"schema": {
|
||||||
|
"type": "Token"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad request",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal server error",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/loginerenew": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"bererToken": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "renews the users token",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"User"
|
||||||
|
],
|
||||||
|
"summary": "LoginRenews",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Successfully signed token for user",
|
||||||
|
"schema": {
|
||||||
|
"type": "Token"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal server error",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/promoteToAdmin": {
|
||||||
|
"post": {
|
||||||
|
"description": "promote chosen user to admin",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"User"
|
||||||
|
],
|
||||||
|
"summary": "PromoteToAdmin",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "user info",
|
||||||
|
"name": "NewUser",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/types.NewUser"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Successfully prometed user",
|
||||||
|
"schema": {
|
||||||
|
"type": "json"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "bad request",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal server error",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/register": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Register a new user",
|
"description": "Register a new user",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"text/plain"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"User"
|
"User"
|
||||||
],
|
],
|
||||||
"summary": "Register a new user",
|
"summary": "Register",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "User to register",
|
||||||
|
"name": "NewUser",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/types.NewUser"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "User added",
|
"description": "User added",
|
||||||
|
@ -53,6 +208,102 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/userdelete/{username}": {
|
||||||
|
"delete": {
|
||||||
|
"description": "UserDelete deletes a user from the database",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"User"
|
||||||
|
],
|
||||||
|
"summary": "UserDelete",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "User deleted",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"403": {
|
||||||
|
"description": "You can only delete yourself",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal server error",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/users/all": {
|
||||||
|
"get": {
|
||||||
|
"description": "lists all users",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"User"
|
||||||
|
],
|
||||||
|
"summary": "ListsAllUsers",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Successfully signed token for user",
|
||||||
|
"schema": {
|
||||||
|
"type": "json"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal server error",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"types.NewUser": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"password": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"securityDefinitions": {
|
||||||
|
"bererToken": {
|
||||||
|
"type": "apiKey",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"externalDocs": {
|
"externalDocs": {
|
||||||
|
|
|
@ -201,7 +201,25 @@ func (d *Db) GetProjectId(projectname string) (int, error) {
|
||||||
|
|
||||||
// Creates a new project in the database, associated with a user
|
// Creates a new project in the database, associated with a user
|
||||||
func (d *Db) AddProject(name string, description string, username string) error {
|
func (d *Db) AddProject(name string, description string, username string) error {
|
||||||
_, err := d.Exec(projectInsert, name, description, username)
|
tx := d.MustBegin()
|
||||||
|
_, err := tx.Exec(projectInsert, name, description, username)
|
||||||
|
if err != nil {
|
||||||
|
if err := tx.Rollback(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec(changeUserRole, "project_manager", username, name)
|
||||||
|
if err != nil {
|
||||||
|
if err := tx.Rollback(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Commit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,16 @@ import (
|
||||||
|
|
||||||
// Register is a simple handler that registers a new user
|
// Register is a simple handler that registers a new user
|
||||||
//
|
//
|
||||||
// @Summary Register a new user
|
// @Summary Register
|
||||||
// @Description Register a new user
|
// @Description Register a new user
|
||||||
// @Tags User
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce plain
|
||||||
|
// @Param NewUser body types.NewUser true "User to register"
|
||||||
// @Success 200 {string} string "User added"
|
// @Success 200 {string} string "User added"
|
||||||
// @Failure 400 {string} string "Bad request"
|
// @Failure 400 {string} string "Bad request"
|
||||||
// @Failure 500 {string} string "Internal server error"
|
// @Failure 500 {string} string "Internal server error"
|
||||||
// @Router /api/register [post]
|
// @Router /register [post]
|
||||||
func (gs *GState) Register(c *fiber.Ctx) error {
|
func (gs *GState) Register(c *fiber.Ctx) error {
|
||||||
u := new(types.NewUser)
|
u := new(types.NewUser)
|
||||||
if err := c.BodyParser(u); err != nil {
|
if err := c.BodyParser(u); err != nil {
|
||||||
|
@ -40,6 +41,17 @@ func (gs *GState) Register(c *fiber.Ctx) error {
|
||||||
|
|
||||||
// This path should obviously be protected in the future
|
// This path should obviously be protected in the future
|
||||||
// UserDelete deletes a user from the database
|
// UserDelete deletes a user from the database
|
||||||
|
//
|
||||||
|
// @Summary UserDelete
|
||||||
|
// @Description UserDelete deletes a user from the database
|
||||||
|
// @Tags User
|
||||||
|
// @Accept json
|
||||||
|
// @Produce plain
|
||||||
|
// @Success 200 {string} string "User deleted"
|
||||||
|
// @Failure 403 {string} string "You can only delete yourself"
|
||||||
|
// @Failure 500 {string} string "Internal server error"
|
||||||
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
|
// @Router /userdelete/{username} [delete]
|
||||||
func (gs *GState) UserDelete(c *fiber.Ctx) error {
|
func (gs *GState) UserDelete(c *fiber.Ctx) error {
|
||||||
// Read from path parameters
|
// Read from path parameters
|
||||||
username := c.Params("username")
|
username := c.Params("username")
|
||||||
|
@ -62,8 +74,21 @@ func (gs *GState) UserDelete(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login is a simple login handler that returns a JWT token
|
// Login is a simple login handler that returns a JWT token
|
||||||
|
//
|
||||||
|
// @Summary login
|
||||||
|
// @Description logs the user in and returns a jwt token
|
||||||
|
// @Tags User
|
||||||
|
// @Accept json
|
||||||
|
// @Param NewUser body types.NewUser true "login info"
|
||||||
|
// @Produce plain
|
||||||
|
// @Success 200 Token types.Token "Successfully signed token for user"
|
||||||
|
// @Failure 400 {string} string "Bad request"
|
||||||
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
|
// @Failure 500 {string} string "Internal server error"
|
||||||
|
// @Router /login [post]
|
||||||
func (gs *GState) Login(c *fiber.Ctx) error {
|
func (gs *GState) Login(c *fiber.Ctx) error {
|
||||||
// The body type is identical to a NewUser
|
// The body type is identical to a NewUser
|
||||||
|
|
||||||
u := new(types.NewUser)
|
u := new(types.NewUser)
|
||||||
if err := c.BodyParser(u); err != nil {
|
if err := c.BodyParser(u); err != nil {
|
||||||
log.Warn("Error parsing body")
|
log.Warn("Error parsing body")
|
||||||
|
@ -94,11 +119,22 @@ func (gs *GState) Login(c *fiber.Ctx) error {
|
||||||
return c.SendStatus(fiber.StatusInternalServerError)
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Successfully signed token for user:", u.Username)
|
println("Successfully signed token for user:", u.Username)
|
||||||
return c.JSON(fiber.Map{"token": t})
|
return c.JSON(types.Token{Token: t})
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoginRenew is a simple handler that renews the token
|
// LoginRenew is a simple handler that renews the token
|
||||||
|
//
|
||||||
|
// @Summary LoginRenews
|
||||||
|
// @Description renews the users token
|
||||||
|
// @Security bererToken
|
||||||
|
// @Tags User
|
||||||
|
// @Accept json
|
||||||
|
// @Produce plain
|
||||||
|
// @Success 200 Token types.Token "Successfully signed token for user"
|
||||||
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
|
// @Failure 500 {string} string "Internal server error"
|
||||||
|
// @Router /loginerenew [post]
|
||||||
func (gs *GState) LoginRenew(c *fiber.Ctx) error {
|
func (gs *GState) LoginRenew(c *fiber.Ctx) error {
|
||||||
user := c.Locals("user").(*jwt.Token)
|
user := c.Locals("user").(*jwt.Token)
|
||||||
|
|
||||||
|
@ -119,10 +155,20 @@ func (gs *GState) LoginRenew(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Successfully renewed token for user:", user.Claims.(jwt.MapClaims)["name"])
|
log.Info("Successfully renewed token for user:", user.Claims.(jwt.MapClaims)["name"])
|
||||||
return c.JSON(fiber.Map{"token": t})
|
return c.JSON(types.Token{Token: t})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAllUsers is a handler that returns a list of all users in the application database
|
// ListAllUsers is a handler that returns a list of all users in the application database
|
||||||
|
//
|
||||||
|
// @Summary ListsAllUsers
|
||||||
|
// @Description lists all users
|
||||||
|
// @Tags User
|
||||||
|
// @Accept json
|
||||||
|
// @Produce plain
|
||||||
|
// @Success 200 {json} json "Successfully signed token for user"
|
||||||
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
|
// @Failure 500 {string} string "Internal server error"
|
||||||
|
// @Router /users/all [get]
|
||||||
func (gs *GState) ListAllUsers(c *fiber.Ctx) error {
|
func (gs *GState) ListAllUsers(c *fiber.Ctx) error {
|
||||||
// Get all users from the database
|
// Get all users from the database
|
||||||
users, err := gs.Db.GetAllUsersApplication()
|
users, err := gs.Db.GetAllUsersApplication()
|
||||||
|
@ -136,6 +182,17 @@ func (gs *GState) ListAllUsers(c *fiber.Ctx) error {
|
||||||
return c.JSON(users)
|
return c.JSON(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Summary PromoteToAdmin
|
||||||
|
// @Description promote chosen user to admin
|
||||||
|
// @Tags User
|
||||||
|
// @Accept json
|
||||||
|
// @Produce plain
|
||||||
|
// @Param NewUser body types.NewUser true "user info"
|
||||||
|
// @Success 200 {json} json "Successfully prometed user"
|
||||||
|
// @Failure 400 {string} string "bad request"
|
||||||
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
|
// @Failure 500 {string} string "Internal server error"
|
||||||
|
// @Router /promoteToAdmin [post]
|
||||||
func (gs *GState) PromoteToAdmin(c *fiber.Ctx) error {
|
func (gs *GState) PromoteToAdmin(c *fiber.Ctx) error {
|
||||||
// Extract the username from the request body
|
// Extract the username from the request body
|
||||||
var newUser types.NewUser
|
var newUser types.NewUser
|
||||||
|
|
|
@ -27,3 +27,8 @@ type PublicUser struct {
|
||||||
UserId string `json:"userId"`
|
UserId string `json:"userId"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wrapper type for token
|
||||||
|
type Token struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ import (
|
||||||
// @license.name AGPL
|
// @license.name AGPL
|
||||||
// @license.url https://www.gnu.org/licenses/agpl-3.0.html
|
// @license.url https://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
|
||||||
|
//@securityDefinitions.apikey bererToken
|
||||||
|
//@in header
|
||||||
|
//@name Authorization
|
||||||
|
|
||||||
// @host localhost:8080
|
// @host localhost:8080
|
||||||
// @BasePath /api
|
// @BasePath /api
|
||||||
|
|
||||||
|
@ -79,7 +83,7 @@ func main() {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Protected routes (require a valid JWT bearer token authentication header)
|
// Protected routes (require a valid JWT bearer token authentication header)
|
||||||
server.Post("/api/submitReport", gs.SubmitWeeklyReport)
|
server.Post("/api/submitWeeklyReport", gs.SubmitWeeklyReport)
|
||||||
server.Get("/api/getUserProjects", gs.GetUserProjects)
|
server.Get("/api/getUserProjects", gs.GetUserProjects)
|
||||||
server.Post("/api/loginrenew", gs.LoginRenew)
|
server.Post("/api/loginrenew", gs.LoginRenew)
|
||||||
server.Delete("/api/userdelete/:username", gs.UserDelete) // Perhaps just use POST to avoid headaches
|
server.Delete("/api/userdelete/:username", gs.UserDelete) // Perhaps just use POST to avoid headaches
|
||||||
|
@ -89,7 +93,7 @@ func main() {
|
||||||
server.Post("/api/signReport", gs.SignReport)
|
server.Post("/api/signReport", gs.SignReport)
|
||||||
server.Put("/api/addUserToProject", gs.AddUserToProjectHandler)
|
server.Put("/api/addUserToProject", gs.AddUserToProjectHandler)
|
||||||
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
||||||
|
server.Get("/api/users/all", gs.ListAllUsers)
|
||||||
// Announce the port we are listening on and start the server
|
// Announce the port we are listening on and start the server
|
||||||
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
109
frontend/src/Components/AllTimeReportsInProject.tsx
Normal file
109
frontend/src/Components/AllTimeReportsInProject.tsx
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { NewWeeklyReport } from "../Types/goTypes";
|
||||||
|
import { Link, useParams } from "react-router-dom";
|
||||||
|
|
||||||
|
function AllTimeReportsInProject(): JSX.Element {
|
||||||
|
const { projectName } = useParams();
|
||||||
|
const [weeklyReports, setWeeklyReports] = useState<NewWeeklyReport[]>([]);
|
||||||
|
|
||||||
|
/* const getWeeklyReports = async (): Promise<void> => {
|
||||||
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
|
const response = await api.getWeeklyReports(token);
|
||||||
|
console.log(response);
|
||||||
|
if (response.success) {
|
||||||
|
setWeeklyReports(response.data ?? []);
|
||||||
|
} else {
|
||||||
|
console.error(response.message);
|
||||||
|
}
|
||||||
|
}; */
|
||||||
|
|
||||||
|
const getWeeklyReports = async (): Promise<void> => {
|
||||||
|
const report: NewWeeklyReport[] = [
|
||||||
|
{
|
||||||
|
projectName: projectName ?? "",
|
||||||
|
week: 10,
|
||||||
|
developmentTime: 1,
|
||||||
|
meetingTime: 1,
|
||||||
|
adminTime: 1,
|
||||||
|
ownWorkTime: 1,
|
||||||
|
studyTime: 1,
|
||||||
|
testingTime: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
projectName: projectName ?? "",
|
||||||
|
week: 11,
|
||||||
|
developmentTime: 1,
|
||||||
|
meetingTime: 1,
|
||||||
|
adminTime: 1,
|
||||||
|
ownWorkTime: 100,
|
||||||
|
studyTime: 1,
|
||||||
|
testingTime: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
projectName: projectName ?? "",
|
||||||
|
week: 12,
|
||||||
|
developmentTime: 1,
|
||||||
|
meetingTime: 1,
|
||||||
|
adminTime: 1,
|
||||||
|
ownWorkTime: 1,
|
||||||
|
studyTime: 1,
|
||||||
|
testingTime: 1000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
projectName: projectName ?? "",
|
||||||
|
week: 20,
|
||||||
|
developmentTime: 1,
|
||||||
|
meetingTime: 1,
|
||||||
|
adminTime: 1,
|
||||||
|
ownWorkTime: 1,
|
||||||
|
studyTime: 1,
|
||||||
|
testingTime: 10000,
|
||||||
|
},
|
||||||
|
// Add more reports as needed
|
||||||
|
];
|
||||||
|
setWeeklyReports(report);
|
||||||
|
await Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Call getProjects when the component mounts
|
||||||
|
useEffect(() => {
|
||||||
|
void getWeeklyReports();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px] text-[30px]">
|
||||||
|
{weeklyReports.map((newWeeklyReport, index) => (
|
||||||
|
<Link
|
||||||
|
to={`/editTimeReport/${projectName}/${newWeeklyReport.week}`}
|
||||||
|
key={index}
|
||||||
|
className="border-b-2 border-black w-full"
|
||||||
|
>
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<h1>
|
||||||
|
<span className="font-bold">{"Week: "}</span>
|
||||||
|
{newWeeklyReport.week}
|
||||||
|
</h1>
|
||||||
|
<h1>
|
||||||
|
<span className="font-bold">{"Total Time: "}</span>
|
||||||
|
{newWeeklyReport.developmentTime +
|
||||||
|
newWeeklyReport.meetingTime +
|
||||||
|
newWeeklyReport.adminTime +
|
||||||
|
newWeeklyReport.ownWorkTime +
|
||||||
|
newWeeklyReport.studyTime +
|
||||||
|
newWeeklyReport.testingTime}{" "}
|
||||||
|
min
|
||||||
|
</h1>
|
||||||
|
<h1>
|
||||||
|
<span className="font-bold">{"Signed: "}</span>
|
||||||
|
YES
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AllTimeReportsInProject;
|
|
@ -1,11 +1,10 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { NewWeeklyReport } from "../Types/goTypes";
|
import { NewWeeklyReport } from "../Types/goTypes";
|
||||||
import { api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
|
|
||||||
export default function GetWeeklyReport(): JSX.Element {
|
export default function GetWeeklyReport(): JSX.Element {
|
||||||
const [projectName, setProjectName] = useState("");
|
|
||||||
const [week, setWeek] = useState(0);
|
const [week, setWeek] = useState(0);
|
||||||
const [developmentTime, setDevelopmentTime] = useState(0);
|
const [developmentTime, setDevelopmentTime] = useState(0);
|
||||||
const [meetingTime, setMeetingTime] = useState(0);
|
const [meetingTime, setMeetingTime] = useState(0);
|
||||||
|
@ -16,13 +15,14 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
|
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const username = localStorage.getItem("username") ?? "";
|
const username = localStorage.getItem("username") ?? "";
|
||||||
|
const { projectName } = useParams();
|
||||||
|
const { fetchedWeek } = useParams();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchWeeklyReport = async (): Promise<void> => {
|
const fetchWeeklyReport = async (): Promise<void> => {
|
||||||
const response = await api.getWeeklyReport(
|
const response = await api.getWeeklyReport(
|
||||||
username,
|
username,
|
||||||
projectName,
|
projectName ?? "",
|
||||||
week.toString(),
|
fetchedWeek?.toString() ?? "0",
|
||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
studyTime: 0,
|
studyTime: 0,
|
||||||
testingTime: 0,
|
testingTime: 0,
|
||||||
};
|
};
|
||||||
setProjectName(report.projectName);
|
|
||||||
setWeek(report.week);
|
setWeek(report.week);
|
||||||
setDevelopmentTime(report.developmentTime);
|
setDevelopmentTime(report.developmentTime);
|
||||||
setMeetingTime(report.meetingTime);
|
setMeetingTime(report.meetingTime);
|
||||||
|
@ -50,12 +50,13 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
void fetchWeeklyReport();
|
void fetchWeeklyReport();
|
||||||
}, [projectName, token, username, week]);
|
});
|
||||||
|
|
||||||
const handleNewWeeklyReport = async (): Promise<void> => {
|
const handleNewWeeklyReport = async (): Promise<void> => {
|
||||||
const newWeeklyReport: NewWeeklyReport = {
|
const newWeeklyReport: NewWeeklyReport = {
|
||||||
projectName,
|
projectName: projectName ?? "",
|
||||||
week,
|
week,
|
||||||
developmentTime,
|
developmentTime,
|
||||||
meetingTime,
|
meetingTime,
|
||||||
|
@ -82,7 +83,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void handleNewWeeklyReport();
|
void handleNewWeeklyReport();
|
||||||
navigate("/project");
|
navigate(-1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="flex flex-col items-center">
|
<div className="flex flex-col items-center">
|
||||||
|
@ -233,7 +234,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<Button
|
<Button
|
||||||
text="Submit"
|
text="Submit changes"
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { NewWeeklyReport } from "../Types/goTypes";
|
import type { NewWeeklyReport } from "../Types/goTypes";
|
||||||
import { api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
|
|
||||||
export default function NewWeeklyReport(): JSX.Element {
|
export default function NewWeeklyReport(): JSX.Element {
|
||||||
const [week, setWeek] = useState(0);
|
const [week, setWeek] = useState<number>(0);
|
||||||
const [developmentTime, setDevelopmentTime] = useState(0);
|
const [developmentTime, setDevelopmentTime] = useState<number>();
|
||||||
const [meetingTime, setMeetingTime] = useState(0);
|
const [meetingTime, setMeetingTime] = useState<number>();
|
||||||
const [adminTime, setAdminTime] = useState(0);
|
const [adminTime, setAdminTime] = useState<number>();
|
||||||
const [ownWorkTime, setOwnWorkTime] = useState(0);
|
const [ownWorkTime, setOwnWorkTime] = useState<number>();
|
||||||
const [studyTime, setStudyTime] = useState(0);
|
const [studyTime, setStudyTime] = useState<number>();
|
||||||
const [testingTime, setTestingTime] = useState(0);
|
const [testingTime, setTestingTime] = useState<number>();
|
||||||
|
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
|
@ -19,13 +19,13 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
const handleNewWeeklyReport = async (): Promise<void> => {
|
const handleNewWeeklyReport = async (): Promise<void> => {
|
||||||
const newWeeklyReport: NewWeeklyReport = {
|
const newWeeklyReport: NewWeeklyReport = {
|
||||||
projectName: projectName ?? "",
|
projectName: projectName ?? "",
|
||||||
week,
|
week: week,
|
||||||
developmentTime,
|
developmentTime: developmentTime ?? 0,
|
||||||
meetingTime,
|
meetingTime: meetingTime ?? 0,
|
||||||
adminTime,
|
adminTime: adminTime ?? 0,
|
||||||
ownWorkTime,
|
ownWorkTime: ownWorkTime ?? 0,
|
||||||
studyTime,
|
studyTime: studyTime ?? 0,
|
||||||
testingTime,
|
testingTime: testingTime ?? 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
await api.submitWeeklyReport(newWeeklyReport, token);
|
await api.submitWeeklyReport(newWeeklyReport, token);
|
||||||
|
@ -58,6 +58,8 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
setWeek(weekNumber);
|
setWeek(weekNumber);
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
|
const keyValue = event.key;
|
||||||
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
onPaste={(event) => {
|
onPaste={(event) => {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
import BackButton from "../../Components/BackButton";
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
import BasicWindow from "../../Components/BasicWindow";
|
||||||
import Button from "../../Components/Button";
|
|
||||||
import NewWeeklyReport from "../../Components/NewWeeklyReport";
|
import NewWeeklyReport from "../../Components/NewWeeklyReport";
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
|
|
||||||
function UserNewTimeReportPage(): JSX.Element {
|
function UserNewTimeReportPage(): JSX.Element {
|
||||||
const content = (
|
const content = (
|
||||||
|
@ -13,15 +12,7 @@ function UserNewTimeReportPage(): JSX.Element {
|
||||||
|
|
||||||
const buttons = (
|
const buttons = (
|
||||||
<>
|
<>
|
||||||
<Link to="/project">
|
<BackButton />
|
||||||
<Button
|
|
||||||
text="Back"
|
|
||||||
onClick={(): void => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
/>
|
|
||||||
</Link>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Link, useLocation, useParams } from "react-router-dom";
|
import { Link, useParams } from "react-router-dom";
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
import BasicWindow from "../../Components/BasicWindow";
|
||||||
import BackButton from "../../Components/BackButton";
|
import BackButton from "../../Components/BackButton";
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ function UserProjectPage(): JSX.Element {
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
<>
|
<>
|
||||||
<h1 className="font-bold text-[30px] mb-[20px]">{useLocation().state}</h1>
|
<h1 className="font-bold text-[40px] mb-[20px]">{projectName}</h1>
|
||||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
||||||
<Link to={`/projectPage/${projectName}`}>
|
<Link to={`/timeReports/${projectName}/`}>
|
||||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||||
Your Time Reports
|
Your Time Reports
|
||||||
</h1>
|
</h1>
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
import BasicWindow from "../../Components/BasicWindow";
|
||||||
import BackButton from "../../Components/BackButton";
|
import BackButton from "../../Components/BackButton";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import AllTimeReportsInProject from "../../Components/AllTimeReportsInProject";
|
||||||
|
|
||||||
function UserViewTimeReportsPage(): JSX.Element {
|
function UserViewTimeReportsPage(): JSX.Element {
|
||||||
|
const { projectName } = useParams();
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
<>
|
<>
|
||||||
<h1 className="font-bold text-[30px] mb-[20px]">Your Time Reports</h1>
|
<h1 className="font-bold text-[30px] mb-[20px]">
|
||||||
{/* Här kan du inkludera logiken för att visa användarens tidrapporter */}
|
Your Time Reports In: {projectName}
|
||||||
|
</h1>
|
||||||
|
<AllTimeReportsInProject />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
import { useState, createContext } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Project } from "../Types/goTypes";
|
import { Project } from "../Types/goTypes";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import BasicWindow from "../Components/BasicWindow";
|
import BasicWindow from "../Components/BasicWindow";
|
||||||
|
import { api } from "../API/API";
|
||||||
export const ProjectNameContext = createContext("");
|
|
||||||
|
|
||||||
function UserProjectPage(): JSX.Element {
|
function UserProjectPage(): JSX.Element {
|
||||||
/* const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
*/ const [selectedProject, setSelectedProject] = useState("");
|
|
||||||
|
|
||||||
/* const getProjects = async (): Promise<void> => {
|
const getProjects = async (): Promise<void> => {
|
||||||
const username = localStorage.getItem("username") ?? ""; // replace with actual username
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const token = localStorage.getItem("accessToken") ?? ""; // replace with actual token
|
const response = await api.getUserProjects(token);
|
||||||
const response = await api.getUserProjects(username, token);
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setProjects(response.data ?? []);
|
setProjects(response.data ?? []);
|
||||||
|
@ -22,55 +19,22 @@ function UserProjectPage(): JSX.Element {
|
||||||
};
|
};
|
||||||
// Call getProjects when the component mounts
|
// Call getProjects when the component mounts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getProjects();
|
void getProjects();
|
||||||
}, []); */
|
}, []);
|
||||||
|
|
||||||
// Mock data
|
|
||||||
const projects: Project[] = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "Project Test App",
|
|
||||||
description: "Description 1",
|
|
||||||
owner: "Owner 1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "Project 2",
|
|
||||||
description: "Description 2",
|
|
||||||
owner: "Owner 2",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
name: "Project 3",
|
|
||||||
description: "Description 3",
|
|
||||||
owner: "Owner 3",
|
|
||||||
},
|
|
||||||
// Add more mock projects as neededects as needed
|
|
||||||
];
|
|
||||||
|
|
||||||
const handleProjectClick = (projectName: string): void => {
|
|
||||||
setSelectedProject(projectName);
|
|
||||||
};
|
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
<ProjectNameContext.Provider value={selectedProject}>
|
<>
|
||||||
<h1 className="font-bold text-[30px] mb-[20px]">Your Projects</h1>
|
<h1 className="font-bold text-[30px] mb-[20px]">Your Projects</h1>
|
||||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
||||||
{projects.map((project, index) => (
|
{projects.map((project, index) => (
|
||||||
<Link
|
<Link to={`/project/${project.name}`} key={index}>
|
||||||
to={`/project/${project.name}`}
|
|
||||||
onClick={() => {
|
|
||||||
handleProjectClick(project.name);
|
|
||||||
}}
|
|
||||||
key={index}
|
|
||||||
>
|
|
||||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||||
{project.name}
|
{project.name}
|
||||||
</h1>
|
</h1>
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</ProjectNameContext.Provider>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const buttons = <></>;
|
const buttons = <></>;
|
||||||
|
|
|
@ -59,11 +59,11 @@ const router = createBrowserRouter([
|
||||||
element: <UserNewTimeReportPage />,
|
element: <UserNewTimeReportPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/projectPage/:projectName",
|
path: "/timeReports/:projectName",
|
||||||
element: <UserViewTimeReportsPage />,
|
element: <UserViewTimeReportsPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/editTimeReport",
|
path: "/editTimeReport/:projectName/:weekNumber",
|
||||||
element: <UserEditTimeReportPage />,
|
element: <UserEditTimeReportPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
78
testing.py
78
testing.py
|
@ -2,6 +2,16 @@ import requests
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
debug_output = False
|
||||||
|
|
||||||
|
def gprint(*args, **kwargs):
|
||||||
|
print("\033[92m", *args, "\033[00m", **kwargs)
|
||||||
|
|
||||||
|
print("Running Tests...")
|
||||||
|
|
||||||
|
def dprint(*args, **kwargs):
|
||||||
|
if debug_output:
|
||||||
|
print(*args, **kwargs)
|
||||||
|
|
||||||
def randomString(len=10):
|
def randomString(len=10):
|
||||||
"""Generate a random string of fixed length"""
|
"""Generate a random string of fixed length"""
|
||||||
|
@ -20,7 +30,7 @@ base_url = "http://localhost:8080"
|
||||||
registerPath = base_url + "/api/register"
|
registerPath = base_url + "/api/register"
|
||||||
loginPath = base_url + "/api/login"
|
loginPath = base_url + "/api/login"
|
||||||
addProjectPath = base_url + "/api/project"
|
addProjectPath = base_url + "/api/project"
|
||||||
submitReportPath = base_url + "/api/submitReport"
|
submitReportPath = base_url + "/api/submitWeeklyReport"
|
||||||
getWeeklyReportPath = base_url + "/api/getWeeklyReport"
|
getWeeklyReportPath = base_url + "/api/getWeeklyReport"
|
||||||
getProjectPath = base_url + "/api/project"
|
getProjectPath = base_url + "/api/project"
|
||||||
signReportPath = base_url + "/api/signReport"
|
signReportPath = base_url + "/api/signReport"
|
||||||
|
@ -31,7 +41,7 @@ getUserProjectsPath = base_url + "/api/getUserProjects"
|
||||||
|
|
||||||
def test_get_user_projects():
|
def test_get_user_projects():
|
||||||
|
|
||||||
print("Testing get user projects")
|
dprint("Testing get user projects")
|
||||||
loginResponse = login("user2", "123")
|
loginResponse = login("user2", "123")
|
||||||
# Check if the user is added to the project
|
# Check if the user is added to the project
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
|
@ -39,29 +49,29 @@ def test_get_user_projects():
|
||||||
json={"username": "user2"},
|
json={"username": "user2"},
|
||||||
headers={"Authorization": "Bearer " + loginResponse.json()["token"]},
|
headers={"Authorization": "Bearer " + loginResponse.json()["token"]},
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
print(response.json())
|
dprint(response.json())
|
||||||
assert response.status_code == 200, "Get user projects failed"
|
assert response.status_code == 200, "Get user projects failed"
|
||||||
print("got user projects successfully")
|
gprint("test_get_user_projects successful")
|
||||||
|
|
||||||
|
|
||||||
# Posts the username and password to the register endpoint
|
# Posts the username and password to the register endpoint
|
||||||
def register(username: string, password: string):
|
def register(username: string, password: string):
|
||||||
print("Registering with username: ", username, " and password: ", password)
|
dprint("Registering with username: ", username, " and password: ", password)
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
registerPath, json={"username": username, "password": password}
|
registerPath, json={"username": username, "password": password}
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
# Posts the username and password to the login endpoint
|
# Posts the username and password to the login endpoint
|
||||||
def login(username: string, password: string):
|
def login(username: string, password: string):
|
||||||
print("Logging in with username: ", username, " and password: ", password)
|
dprint("Logging in with username: ", username, " and password: ", password)
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
loginPath, json={"username": username, "password": password}
|
loginPath, json={"username": username, "password": password}
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +79,8 @@ def login(username: string, password: string):
|
||||||
def test_login():
|
def test_login():
|
||||||
response = login(username, "always_same")
|
response = login(username, "always_same")
|
||||||
assert response.status_code == 200, "Login failed"
|
assert response.status_code == 200, "Login failed"
|
||||||
print("Login successful")
|
dprint("Login successful")
|
||||||
|
gprint("test_login successful")
|
||||||
return response.json()["token"]
|
return response.json()["token"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,8 +88,7 @@ def test_login():
|
||||||
def test_create_user():
|
def test_create_user():
|
||||||
response = register(username, "always_same")
|
response = register(username, "always_same")
|
||||||
assert response.status_code == 200, "Registration failed"
|
assert response.status_code == 200, "Registration failed"
|
||||||
print("Registration successful")
|
gprint("test_create_user successful")
|
||||||
|
|
||||||
|
|
||||||
# Test function to add a project
|
# Test function to add a project
|
||||||
def test_add_project():
|
def test_add_project():
|
||||||
|
@ -89,10 +99,9 @@ def test_add_project():
|
||||||
json={"name": projectName, "description": "This is a project"},
|
json={"name": projectName, "description": "This is a project"},
|
||||||
headers={"Authorization": "Bearer " + token},
|
headers={"Authorization": "Bearer " + token},
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
assert response.status_code == 200, "Add project failed"
|
assert response.status_code == 200, "Add project failed"
|
||||||
print("Add project successful")
|
gprint("test_add_project successful")
|
||||||
|
|
||||||
|
|
||||||
# Test function to submit a report
|
# Test function to submit a report
|
||||||
def test_submit_report():
|
def test_submit_report():
|
||||||
|
@ -111,10 +120,9 @@ def test_submit_report():
|
||||||
},
|
},
|
||||||
headers={"Authorization": "Bearer " + token},
|
headers={"Authorization": "Bearer " + token},
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
assert response.status_code == 200, "Submit report failed"
|
assert response.status_code == 200, "Submit report failed"
|
||||||
print("Submit report successful")
|
gprint("test_submit_report successful")
|
||||||
|
|
||||||
|
|
||||||
# Test function to get a weekly report
|
# Test function to get a weekly report
|
||||||
def test_get_weekly_report():
|
def test_get_weekly_report():
|
||||||
|
@ -124,8 +132,9 @@ def test_get_weekly_report():
|
||||||
headers={"Authorization": "Bearer " + token},
|
headers={"Authorization": "Bearer " + token},
|
||||||
params={"username": username, "projectName": projectName, "week": 1},
|
params={"username": username, "projectName": projectName, "week": 1},
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
assert response.status_code == 200, "Get weekly report failed"
|
assert response.status_code == 200, "Get weekly report failed"
|
||||||
|
gprint("test_get_weekly_report successful")
|
||||||
|
|
||||||
|
|
||||||
# Tests getting a project by id
|
# Tests getting a project by id
|
||||||
|
@ -135,8 +144,9 @@ def test_get_project():
|
||||||
getProjectPath + "/1", # Assumes that the project with id 1 exists
|
getProjectPath + "/1", # Assumes that the project with id 1 exists
|
||||||
headers={"Authorization": "Bearer " + token},
|
headers={"Authorization": "Bearer " + token},
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
assert response.status_code == 200, "Get project failed"
|
assert response.status_code == 200, "Get project failed"
|
||||||
|
gprint("test_get_project successful")
|
||||||
|
|
||||||
|
|
||||||
# Test function to add a user to a project
|
# Test function to add a user to a project
|
||||||
|
@ -144,13 +154,13 @@ def test_add_user_to_project():
|
||||||
# Log in as a site admin
|
# Log in as a site admin
|
||||||
admin_username = randomString()
|
admin_username = randomString()
|
||||||
admin_password = "admin_password"
|
admin_password = "admin_password"
|
||||||
print(
|
dprint(
|
||||||
"Registering with username: ", admin_username, " and password: ", admin_password
|
"Registering with username: ", admin_username, " and password: ", admin_password
|
||||||
)
|
)
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
registerPath, json={"username": admin_username, "password": admin_password}
|
registerPath, json={"username": admin_username, "password": admin_password}
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
|
|
||||||
admin_token = login(admin_username, admin_password).json()["token"]
|
admin_token = login(admin_username, admin_password).json()["token"]
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
|
@ -158,9 +168,9 @@ def test_add_user_to_project():
|
||||||
json={"username": admin_username},
|
json={"username": admin_username},
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
headers={"Authorization": "Bearer " + admin_token},
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
assert response.status_code == 200, "Promote to site admin failed"
|
assert response.status_code == 200, "Promote to site admin failed"
|
||||||
print("Admin promoted to site admin successfully")
|
dprint("Admin promoted to site admin successfully")
|
||||||
|
|
||||||
# Create a new user to add to the project
|
# Create a new user to add to the project
|
||||||
new_user = randomString()
|
new_user = randomString()
|
||||||
|
@ -173,10 +183,9 @@ def test_add_user_to_project():
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
headers={"Authorization": "Bearer " + admin_token},
|
||||||
)
|
)
|
||||||
|
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
assert response.status_code == 200, "Add user to project failed"
|
assert response.status_code == 200, "Add user to project failed"
|
||||||
print("Add user to project successful")
|
gprint("test_add_user_to_project successful")
|
||||||
|
|
||||||
|
|
||||||
# Test function to sign a report
|
# Test function to sign a report
|
||||||
def test_sign_report():
|
def test_sign_report():
|
||||||
|
@ -187,13 +196,13 @@ def test_sign_report():
|
||||||
# Register an admin
|
# Register an admin
|
||||||
admin_username = randomString()
|
admin_username = randomString()
|
||||||
admin_password = "admin_password2"
|
admin_password = "admin_password2"
|
||||||
print(
|
dprint(
|
||||||
"Registering with username: ", admin_username, " and password: ", admin_password
|
"Registering with username: ", admin_username, " and password: ", admin_password
|
||||||
)
|
)
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
registerPath, json={"username": admin_username, "password": admin_password}
|
registerPath, json={"username": admin_username, "password": admin_password}
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
|
|
||||||
# Log in as the admin
|
# Log in as the admin
|
||||||
admin_token = login(admin_username, admin_password).json()["token"]
|
admin_token = login(admin_username, admin_password).json()["token"]
|
||||||
|
@ -213,7 +222,7 @@ def test_sign_report():
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
headers={"Authorization": "Bearer " + admin_token},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, "Add project manager to project failed"
|
assert response.status_code == 200, "Add project manager to project failed"
|
||||||
print("Project manager added to project successfully")
|
dprint("Project manager added to project successfully")
|
||||||
|
|
||||||
# Log in as the project manager
|
# Log in as the project manager
|
||||||
project_manager_token = login(project_manager, "project_manager_password").json()[
|
project_manager_token = login(project_manager, "project_manager_password").json()[
|
||||||
|
@ -237,7 +246,7 @@ def test_sign_report():
|
||||||
headers={"Authorization": "Bearer " + token},
|
headers={"Authorization": "Bearer " + token},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, "Submit report failed"
|
assert response.status_code == 200, "Submit report failed"
|
||||||
print("Submit report successful")
|
dprint("Submit report successful")
|
||||||
|
|
||||||
# Retrieve the report ID
|
# Retrieve the report ID
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
|
@ -245,7 +254,7 @@ def test_sign_report():
|
||||||
headers={"Authorization": "Bearer " + token},
|
headers={"Authorization": "Bearer " + token},
|
||||||
params={"username": username, "projectName": projectName, "week": 1},
|
params={"username": username, "projectName": projectName, "week": 1},
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
report_id = response.json()["reportId"]
|
report_id = response.json()["reportId"]
|
||||||
|
|
||||||
# Sign the report as the project manager
|
# Sign the report as the project manager
|
||||||
|
@ -255,7 +264,7 @@ def test_sign_report():
|
||||||
headers={"Authorization": "Bearer " + project_manager_token},
|
headers={"Authorization": "Bearer " + project_manager_token},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, "Sign report failed"
|
assert response.status_code == 200, "Sign report failed"
|
||||||
print("Sign report successful")
|
dprint("Sign report successful")
|
||||||
|
|
||||||
# Retrieve the report ID again for confirmation
|
# Retrieve the report ID again for confirmation
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
|
@ -263,7 +272,8 @@ def test_sign_report():
|
||||||
headers={"Authorization": "Bearer " + token},
|
headers={"Authorization": "Bearer " + token},
|
||||||
params={"username": username, "projectName": projectName, "week": 1},
|
params={"username": username, "projectName": projectName, "week": 1},
|
||||||
)
|
)
|
||||||
print(response.text)
|
dprint(response.text)
|
||||||
|
gprint("test_sign_report successful")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue