Compare commits
52 commits
4d7b3e0d57
...
7635791f09
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7635791f09 | ||
![]() |
68e6f94d13 | ||
![]() |
91bccba871 | ||
![]() |
a6f3fc4a1c | ||
![]() |
544383809b | ||
![]() |
abfb79b991 | ||
![]() |
db6fdf3c29 | ||
![]() |
5bc7aadfa3 | ||
![]() |
2d8d200340 | ||
![]() |
0cb6af03e4 | ||
![]() |
f75e6e4a6e | ||
![]() |
10d06767c4 | ||
![]() |
ee49bbde69 | ||
![]() |
266aaa482c | ||
![]() |
194e1d52a8 | ||
![]() |
82e72432f6 | ||
![]() |
620073f688 | ||
![]() |
7313a27b31 | ||
![]() |
d7789ab844 | ||
![]() |
4319f30799 | ||
![]() |
2ca8c60418 | ||
![]() |
0a951ecd2b | ||
![]() |
13eb6597a7 | ||
![]() |
9a0f855d2b | ||
![]() |
7c995573ef | ||
![]() |
a5ea74c996 | ||
![]() |
a0ff329845 | ||
![]() |
e67c54540c | ||
![]() |
91671b2b63 | ||
![]() |
76ae587116 | ||
![]() |
66a064c9f8 | ||
![]() |
be963b2281 | ||
![]() |
c0d36f8df1 | ||
![]() |
f9c30c4951 | ||
![]() |
520e2f74f0 | ||
![]() |
12810075f9 | ||
![]() |
8cc0458e1b | ||
![]() |
12a2691d55 | ||
![]() |
9c5aa10414 | ||
![]() |
fcd035fe6e | ||
![]() |
a39cfedad3 | ||
![]() |
a1d2520d88 | ||
![]() |
903132e56d | ||
![]() |
7c973009ac | ||
![]() |
ffe5d53625 | ||
![]() |
8ea6dec346 | ||
![]() |
61a2d1ce0c | ||
![]() |
9cca8edd9d | ||
![]() |
1f9ccca9bf | ||
![]() |
6b880244a1 | ||
![]() |
46eb3c76a8 | ||
![]() |
632676e3d2 |
34 changed files with 998 additions and 425 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,6 +14,7 @@ diagram.puml
|
||||||
backend/*.png
|
backend/*.png
|
||||||
backend/*.jpg
|
backend/*.jpg
|
||||||
backend/*.svg
|
backend/*.svg
|
||||||
|
__pycache__
|
||||||
|
|
||||||
/go.work.sum
|
/go.work.sum
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
|
|
|
@ -108,6 +108,56 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/promote/{projectName}": {
|
||||||
|
"put": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Promote a user to project manager",
|
||||||
|
"consumes": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Auth"
|
||||||
|
],
|
||||||
|
"summary": "Promote to project manager",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Project name",
|
||||||
|
"name": "projectName",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "User name",
|
||||||
|
"name": "userName",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"403": {
|
||||||
|
"description": "Forbidden",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal server error",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/promoteToAdmin": {
|
"/promoteToAdmin": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
@ -17,6 +17,7 @@ type Database interface {
|
||||||
AddUser(username string, password string) error
|
AddUser(username string, password string) error
|
||||||
CheckUser(username string, password string) bool
|
CheckUser(username string, password string) bool
|
||||||
RemoveUser(username string) error
|
RemoveUser(username string) error
|
||||||
|
RemoveUserFromProject(username string, projectname string) error
|
||||||
PromoteToAdmin(username string) error
|
PromoteToAdmin(username string) error
|
||||||
GetUserId(username string) (int, error)
|
GetUserId(username string) (int, error)
|
||||||
AddProject(name string, description string, username string) error
|
AddProject(name string, description string, username string) error
|
||||||
|
@ -35,7 +36,7 @@ type Database interface {
|
||||||
GetProject(projectId int) (types.Project, error)
|
GetProject(projectId int) (types.Project, error)
|
||||||
GetUserRole(username string, projectname string) (string, error)
|
GetUserRole(username string, projectname string) (string, error)
|
||||||
GetWeeklyReport(username string, projectName string, week int) (types.WeeklyReport, error)
|
GetWeeklyReport(username string, projectName string, week int) (types.WeeklyReport, error)
|
||||||
GetWeeklyReportsUser(username string, projectname string) ([]types.WeeklyReportList, error)
|
GetAllWeeklyReports(username string, projectname string) ([]types.WeeklyReportList, error)
|
||||||
GetUnsignedWeeklyReports(projectName string) ([]types.WeeklyReport, error)
|
GetUnsignedWeeklyReports(projectName string) ([]types.WeeklyReport, error)
|
||||||
SignWeeklyReport(reportId int, projectManagerId int) error
|
SignWeeklyReport(reportId int, projectManagerId int) error
|
||||||
IsSiteAdmin(username string) (bool, error)
|
IsSiteAdmin(username string) (bool, error)
|
||||||
|
@ -43,6 +44,7 @@ type Database interface {
|
||||||
GetProjectTimes(projectName string) (map[string]int, error)
|
GetProjectTimes(projectName string) (map[string]int, error)
|
||||||
UpdateWeeklyReport(projectName string, userName string, week int, developmentTime int, meetingTime int, adminTime int, ownWorkTime int, studyTime int, testingTime int) error
|
UpdateWeeklyReport(projectName string, userName string, week int, developmentTime int, meetingTime int, adminTime int, ownWorkTime int, studyTime int, testingTime int) error
|
||||||
RemoveProject(projectname string) error
|
RemoveProject(projectname string) error
|
||||||
|
GetUserName(id int) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This struct is a wrapper type that holds the database connection
|
// This struct is a wrapper type that holds the database connection
|
||||||
|
@ -86,6 +88,10 @@ const isProjectManagerQuery = `SELECT COUNT(*) > 0 FROM user_roles
|
||||||
JOIN projects ON user_roles.project_id = projects.id
|
JOIN projects ON user_roles.project_id = projects.id
|
||||||
WHERE users.username = ? AND projects.name = ? AND user_roles.p_role = 'project_manager'`
|
WHERE users.username = ? AND projects.name = ? AND user_roles.p_role = 'project_manager'`
|
||||||
|
|
||||||
|
const removeUserFromProjectQuery = `DELETE FROM user_roles
|
||||||
|
WHERE user_id = (SELECT id FROM users WHERE username = ?)
|
||||||
|
AND project_id = (SELECT id FROM projects WHERE name = ?)`
|
||||||
|
|
||||||
// DbConnect connects to the database
|
// DbConnect connects to the database
|
||||||
func DbConnect(dbpath string) Database {
|
func DbConnect(dbpath string) Database {
|
||||||
// Open the database
|
// Open the database
|
||||||
|
@ -147,6 +153,11 @@ func (d *Db) AddUserToProject(username string, projectname string, role string)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Db) RemoveUserFromProject(username string, projectname string) error {
|
||||||
|
_, err := d.Exec(removeUserFromProjectQuery, username, projectname)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// ChangeUserRole changes the role of a user within a project.
|
// ChangeUserRole changes the role of a user within a project.
|
||||||
func (d *Db) ChangeUserRole(username string, projectname string, role string) error {
|
func (d *Db) ChangeUserRole(username string, projectname string, role string) error {
|
||||||
// Execute the SQL query to change the user's role
|
// Execute the SQL query to change the user's role
|
||||||
|
@ -339,9 +350,14 @@ func (d *Db) SignWeeklyReport(reportId int, projectManagerId int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
managerQuery := `SELECT project_id FROM user_roles
|
||||||
|
WHERE user_id = ?
|
||||||
|
AND project_id = (SELECT project_id FROM weekly_reports WHERE report_id = ?)
|
||||||
|
AND p_role = 'project_manager'`
|
||||||
|
|
||||||
// Retrieve the project ID associated with the project manager
|
// Retrieve the project ID associated with the project manager
|
||||||
var managerProjectID int
|
var managerProjectID int
|
||||||
err = d.Get(&managerProjectID, "SELECT project_id FROM user_roles WHERE user_id = ? AND p_role = 'project_manager'", projectManagerId)
|
err = d.Get(&managerProjectID, managerQuery, projectManagerId, reportId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -463,8 +479,8 @@ func (d *Db) Migrate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWeeklyReportsUser retrieves weekly reports for a specific user and project.
|
// GetAllWeeklyReports retrieves weekly reports for a specific user and project.
|
||||||
func (d *Db) GetWeeklyReportsUser(username string, projectName string) ([]types.WeeklyReportList, error) {
|
func (d *Db) GetAllWeeklyReports(username string, projectName string) ([]types.WeeklyReportList, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT
|
SELECT
|
||||||
wr.week,
|
wr.week,
|
||||||
|
@ -601,3 +617,9 @@ func (d *Db) RemoveProject(projectname string) error {
|
||||||
_, err := d.Exec("DELETE FROM projects WHERE name = ?", projectname)
|
_, err := d.Exec("DELETE FROM projects WHERE name = ?", projectname)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Db) GetUserName(id int) (string, error) {
|
||||||
|
var username string
|
||||||
|
err := d.Get(&username, "SELECT username FROM users WHERE id = ?", id)
|
||||||
|
return username, err
|
||||||
|
}
|
||||||
|
|
|
@ -705,7 +705,7 @@ func TestGetWeeklyReportsUser(t *testing.T) {
|
||||||
t.Error("AddWeeklyReport failed:", err)
|
t.Error("AddWeeklyReport failed:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
reports, err := db.GetWeeklyReportsUser("testuser", "testproject")
|
reports, err := db.GetAllWeeklyReports("testuser", "testproject")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("GetWeeklyReportsUser failed:", err)
|
t.Error("GetWeeklyReportsUser failed:", err)
|
||||||
}
|
}
|
||||||
|
@ -964,4 +964,3 @@ func TestRemoveProject(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,12 @@ VALUES ("projecttest3","test project3", 1);
|
||||||
INSERT OR IGNORE INTO user_roles(user_id,project_id,p_role)
|
INSERT OR IGNORE INTO user_roles(user_id,project_id,p_role)
|
||||||
VALUES (1,1,"project_manager");
|
VALUES (1,1,"project_manager");
|
||||||
|
|
||||||
|
INSERT OR IGNORE INTO user_roles(user_id,project_id,p_role)
|
||||||
|
VALUES (1,2,"project_manager");
|
||||||
|
|
||||||
|
INSERT OR IGNORE INTO user_roles(user_id,project_id,p_role)
|
||||||
|
VALUES (1,3,"project_manager");
|
||||||
|
|
||||||
INSERT OR IGNORE INTO user_roles(user_id,project_id,p_role)
|
INSERT OR IGNORE INTO user_roles(user_id,project_id,p_role)
|
||||||
VALUES (2,1,"member");
|
VALUES (2,1,"member");
|
||||||
|
|
||||||
|
|
|
@ -10,42 +10,33 @@ import (
|
||||||
|
|
||||||
// AddUserToProjectHandler is a handler that adds a user to a project with a specified role
|
// AddUserToProjectHandler is a handler that adds a user to a project with a specified role
|
||||||
func AddUserToProjectHandler(c *fiber.Ctx) error {
|
func AddUserToProjectHandler(c *fiber.Ctx) error {
|
||||||
// Extract necessary parameters from the request
|
|
||||||
var requestData struct {
|
|
||||||
Username string `json:"username"`
|
|
||||||
ProjectName string `json:"projectName"`
|
|
||||||
Role string `json:"role"`
|
|
||||||
}
|
|
||||||
if err := c.BodyParser(&requestData); err != nil {
|
|
||||||
log.Info("Error parsing request body:", err)
|
|
||||||
return c.Status(400).SendString("Bad request")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the user adding another user to the project is a site admin
|
|
||||||
user := c.Locals("user").(*jwt.Token)
|
user := c.Locals("user").(*jwt.Token)
|
||||||
claims := user.Claims.(jwt.MapClaims)
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
adminUsername := claims["name"].(string)
|
pm_name := claims["name"].(string)
|
||||||
log.Info("Admin username from claims:", adminUsername)
|
|
||||||
|
|
||||||
isAdmin, err := db.GetDb(c).IsSiteAdmin(adminUsername)
|
project := c.Params("projectName")
|
||||||
|
username := c.Query("userName")
|
||||||
|
|
||||||
|
// Check if the user is a project manager
|
||||||
|
isPM, err := db.GetDb(c).IsProjectManager(pm_name, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Error checking admin status:", err)
|
log.Info("Error checking if user is project manager:", err)
|
||||||
return c.Status(500).SendString(err.Error())
|
return c.Status(500).SendString(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isAdmin {
|
if !isPM {
|
||||||
log.Info("User is not a site admin:", adminUsername)
|
log.Info("User: ", pm_name, " is not a project manager in project: ", project)
|
||||||
return c.Status(403).SendString("User is not a site admin")
|
return c.Status(403).SendString("User is not a project manager")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the user to the project with the specified role
|
// Add the user to the project with the specified role
|
||||||
err = db.GetDb(c).AddUserToProject(requestData.Username, requestData.ProjectName, requestData.Role)
|
err = db.GetDb(c).AddUserToProject(username, project, "member")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Error adding user to project:", err)
|
log.Info("Error adding user to project:", err)
|
||||||
return c.Status(500).SendString(err.Error())
|
return c.Status(500).SendString(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return success message
|
// Return success message
|
||||||
log.Info("User added to project successfully:", requestData.Username)
|
log.Info("User : ", username, " added to project: ", project)
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
51
backend/internal/handlers/projects/PromoteToPm.go
Normal file
51
backend/internal/handlers/projects/PromoteToPm.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package projects
|
||||||
|
|
||||||
|
import (
|
||||||
|
db "ttime/internal/database"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/gofiber/fiber/v2/log"
|
||||||
|
"github.com/golang-jwt/jwt/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// @Summary Promote to project manager
|
||||||
|
// @Description Promote a user to project manager
|
||||||
|
// @Tags Auth
|
||||||
|
// @Security JWT
|
||||||
|
// @Accept plain
|
||||||
|
// @Produce plain
|
||||||
|
// @Param projectName path string true "Project name"
|
||||||
|
// @Param userName query string true "User name"
|
||||||
|
// @Failure 500 {string} string "Internal server error"
|
||||||
|
// @Failure 403 {string} string "Forbidden"
|
||||||
|
// @Router /promote/{projectName} [put]
|
||||||
|
//
|
||||||
|
// Login logs in a user and returns a JWT token
|
||||||
|
// Promote to project manager
|
||||||
|
func PromoteToPm(c *fiber.Ctx) error {
|
||||||
|
user := c.Locals("user").(*jwt.Token)
|
||||||
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
|
pm_name := claims["name"].(string)
|
||||||
|
|
||||||
|
project := c.Params("projectName")
|
||||||
|
new_pm_name := c.Query("userName")
|
||||||
|
|
||||||
|
// Check if the user is a project manager
|
||||||
|
isPM, err := db.GetDb(c).IsProjectManager(pm_name, project)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Error checking if user is project manager:", err)
|
||||||
|
return c.Status(500).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isPM {
|
||||||
|
log.Info("User: ", pm_name, " is not a project manager in project: ", project)
|
||||||
|
return c.Status(403).SendString("User is not a project manager")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the user to the project with the specified role
|
||||||
|
err = db.GetDb(c).ChangeUserRole(new_pm_name, project, "project_manager")
|
||||||
|
|
||||||
|
// Return success message
|
||||||
|
log.Info("User : ", new_pm_name, " promoted to project manager in project: ", project)
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
40
backend/internal/handlers/projects/RemoveUserFromProject.go
Normal file
40
backend/internal/handlers/projects/RemoveUserFromProject.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package projects
|
||||||
|
|
||||||
|
import (
|
||||||
|
db "ttime/internal/database"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/gofiber/fiber/v2/log"
|
||||||
|
"github.com/golang-jwt/jwt/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RemoveUserFromProject(c *fiber.Ctx) error {
|
||||||
|
user := c.Locals("user").(*jwt.Token)
|
||||||
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
|
pm_name := claims["name"].(string)
|
||||||
|
|
||||||
|
project := c.Params("projectName")
|
||||||
|
username := c.Query("userName")
|
||||||
|
|
||||||
|
// Check if the user is a project manager
|
||||||
|
isPM, err := db.GetDb(c).IsProjectManager(pm_name, project)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Error checking if user is project manager:", err)
|
||||||
|
return c.Status(500).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isPM {
|
||||||
|
log.Info("User: ", pm_name, " is not a project manager in project: ", project)
|
||||||
|
return c.Status(403).SendString("User is not a project manager")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the user from the project
|
||||||
|
if err = db.GetDb(c).RemoveUserFromProject(username, project); err != nil {
|
||||||
|
log.Info("Error removing user from project:", err)
|
||||||
|
return c.Status(500).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return success message
|
||||||
|
log.Info("User : ", username, " removed from project: ", project)
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
56
backend/internal/handlers/reports/GetAllWeeklyReports.go
Normal file
56
backend/internal/handlers/reports/GetAllWeeklyReports.go
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package reports
|
||||||
|
|
||||||
|
import (
|
||||||
|
db "ttime/internal/database"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/gofiber/fiber/v2/log"
|
||||||
|
"github.com/golang-jwt/jwt/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetAllWeeklyReports retrieves all weekly reports for a user in a specific project
|
||||||
|
func GetAllWeeklyReports(c *fiber.Ctx) error {
|
||||||
|
// Extract the necessary parameters from the token
|
||||||
|
user := c.Locals("user").(*jwt.Token)
|
||||||
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
|
username := claims["name"].(string)
|
||||||
|
|
||||||
|
// Extract project name and week from query parameters
|
||||||
|
projectName := c.Params("projectName")
|
||||||
|
target_user := c.Query("targetUser") // The user whose reports are being requested
|
||||||
|
|
||||||
|
// If the target user is not empty, use it as the username
|
||||||
|
if target_user == "" {
|
||||||
|
target_user = username
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info(username, " trying to get all weekly reports for: ", target_user)
|
||||||
|
|
||||||
|
if projectName == "" {
|
||||||
|
log.Info("Missing project name")
|
||||||
|
return c.Status(400).SendString("Missing project name")
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the user is not a project manager, they can only view their own reports
|
||||||
|
pm, err := db.GetDb(c).IsProjectManager(username, projectName)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Error checking if user is project manager:", err)
|
||||||
|
return c.Status(500).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if pm == false && target_user != username {
|
||||||
|
log.Info("Unauthorized access")
|
||||||
|
return c.Status(403).SendString("Unauthorized access")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve weekly reports for the user in the project from the database
|
||||||
|
reports, err := db.GetDb(c).GetAllWeeklyReports(target_user, projectName)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error getting weekly reports for user:", target_user, "in project:", projectName, ":", err)
|
||||||
|
return c.Status(500).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Returning weekly report")
|
||||||
|
// Return the retrieved weekly report
|
||||||
|
return c.JSON(reports)
|
||||||
|
}
|
|
@ -16,11 +16,17 @@ func GetWeeklyReport(c *fiber.Ctx) error {
|
||||||
claims := user.Claims.(jwt.MapClaims)
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
username := claims["name"].(string)
|
username := claims["name"].(string)
|
||||||
|
|
||||||
log.Info("Getting weekly report for: ", username)
|
|
||||||
|
|
||||||
// Extract project name and week from query parameters
|
// Extract project name and week from query parameters
|
||||||
projectName := c.Query("projectName")
|
projectName := c.Query("projectName")
|
||||||
week := c.Query("week")
|
week := c.Query("week")
|
||||||
|
target_user := c.Query("targetUser") // The user whose report is being requested
|
||||||
|
|
||||||
|
// If the target user is not empty, use it as the username
|
||||||
|
if target_user == "" {
|
||||||
|
target_user = username
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info(username, " trying to get weekly report for: ", target_user)
|
||||||
|
|
||||||
if projectName == "" || week == "" {
|
if projectName == "" || week == "" {
|
||||||
log.Info("Missing project name or week number")
|
log.Info("Missing project name or week number")
|
||||||
|
@ -34,8 +40,20 @@ func GetWeeklyReport(c *fiber.Ctx) error {
|
||||||
return c.Status(400).SendString("Invalid week number")
|
return c.Status(400).SendString("Invalid week number")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the token user is not an admin, check if the target user is the same as the token user
|
||||||
|
pm, err := db.GetDb(c).IsProjectManager(username, projectName)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Error checking if user is project manager:", err)
|
||||||
|
return c.Status(500).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if pm == false && target_user != username {
|
||||||
|
log.Info("Unauthorized access")
|
||||||
|
return c.Status(403).SendString("Unauthorized access")
|
||||||
|
}
|
||||||
|
|
||||||
// Call the database function to get the weekly report
|
// Call the database function to get the weekly report
|
||||||
report, err := db.GetDb(c).GetWeeklyReport(username, projectName, weekInt)
|
report, err := db.GetDb(c).GetWeeklyReport(target_user, projectName, weekInt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Error getting weekly report from db:", err)
|
log.Info("Error getting weekly report from db:", err)
|
||||||
return c.Status(500).SendString(err.Error())
|
return c.Status(500).SendString(err.Error())
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package reports
|
|
||||||
|
|
||||||
import (
|
|
||||||
db "ttime/internal/database"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"github.com/gofiber/fiber/v2/log"
|
|
||||||
"github.com/golang-jwt/jwt/v5"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetWeeklyReportsUserHandler retrieves all weekly reports for a user in a specific project
|
|
||||||
func GetWeeklyReportsUserHandler(c *fiber.Ctx) error {
|
|
||||||
// Extract the necessary parameters from the token
|
|
||||||
user := c.Locals("user").(*jwt.Token)
|
|
||||||
claims := user.Claims.(jwt.MapClaims)
|
|
||||||
username := claims["name"].(string)
|
|
||||||
|
|
||||||
// Extract necessary (path) parameters from the request
|
|
||||||
projectName := c.Params("projectName")
|
|
||||||
|
|
||||||
// TODO: Here we need to check whether the user is a member of the project
|
|
||||||
// If not, we should return an error. On the other hand, if the user not a member,
|
|
||||||
// the returned list of reports will (should) allways be empty.
|
|
||||||
|
|
||||||
// Retrieve weekly reports for the user in the project from the database
|
|
||||||
reports, err := db.GetDb(c).GetWeeklyReportsUser(username, projectName)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Error getting weekly reports for user:", username, "in project:", projectName, ":", err)
|
|
||||||
return c.Status(500).SendString(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Returning weekly reports for user:", username, "in project:", projectName)
|
|
||||||
|
|
||||||
// Return the list of reports as JSON
|
|
||||||
return c.JSON(reports)
|
|
||||||
}
|
|
32
backend/internal/handlers/users/GetUserName.go
Normal file
32
backend/internal/handlers/users/GetUserName.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package users
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
db "ttime/internal/database"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Return the username of a user given their user id
|
||||||
|
func GetUserName(c *fiber.Ctx) error {
|
||||||
|
// Check the query params for userId
|
||||||
|
user_id_string := c.Query("userId")
|
||||||
|
if user_id_string == "" {
|
||||||
|
return c.Status(400).SendString("Missing user id")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to int
|
||||||
|
user_id, err := strconv.Atoi(user_id_string)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(400).SendString("Invalid user id")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the username from the database
|
||||||
|
username, err := db.GetDb(c).GetUserName(user_id)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(500).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the nuclear launch codes to north korea
|
||||||
|
return c.JSON(fiber.Map{"username": username})
|
||||||
|
}
|
|
@ -103,6 +103,7 @@ func main() {
|
||||||
// userGroup := api.Group("/user") // Not currently in use
|
// userGroup := api.Group("/user") // Not currently in use
|
||||||
api.Get("/users/all", users.ListAllUsers)
|
api.Get("/users/all", users.ListAllUsers)
|
||||||
api.Get("/project/getAllUsers", users.GetAllUsersProject)
|
api.Get("/project/getAllUsers", users.GetAllUsersProject)
|
||||||
|
api.Get("/username", users.GetUserName)
|
||||||
api.Post("/login", users.Login)
|
api.Post("/login", users.Login)
|
||||||
api.Post("/register", users.Register)
|
api.Post("/register", users.Register)
|
||||||
api.Post("/loginrenew", users.LoginRenew)
|
api.Post("/loginrenew", users.LoginRenew)
|
||||||
|
@ -119,6 +120,9 @@ func main() {
|
||||||
api.Get("/getUsersProject/:projectName", projects.ListAllUsersProject)
|
api.Get("/getUsersProject/:projectName", projects.ListAllUsersProject)
|
||||||
api.Post("/project", projects.CreateProject)
|
api.Post("/project", projects.CreateProject)
|
||||||
api.Post("/ProjectRoleChange", projects.ProjectRoleChange)
|
api.Post("/ProjectRoleChange", projects.ProjectRoleChange)
|
||||||
|
api.Put("/promoteToPm/:projectName", projects.PromoteToPm)
|
||||||
|
api.Put("/addUserToProject/:projectName", projects.AddUserToProjectHandler)
|
||||||
|
api.Delete("/removeUserFromProject/:projectName", projects.RemoveUserFromProject)
|
||||||
api.Delete("/removeProject/:projectName", projects.RemoveProject)
|
api.Delete("/removeProject/:projectName", projects.RemoveProject)
|
||||||
api.Delete("/project/:projectID", projects.DeleteProject)
|
api.Delete("/project/:projectID", projects.DeleteProject)
|
||||||
|
|
||||||
|
@ -126,10 +130,9 @@ func main() {
|
||||||
// reportGroup := api.Group("/report") // Not currently in use
|
// reportGroup := api.Group("/report") // Not currently in use
|
||||||
api.Get("/getWeeklyReport", reports.GetWeeklyReport)
|
api.Get("/getWeeklyReport", reports.GetWeeklyReport)
|
||||||
api.Get("/getUnsignedReports/:projectName", reports.GetUnsignedReports)
|
api.Get("/getUnsignedReports/:projectName", reports.GetUnsignedReports)
|
||||||
api.Get("/getWeeklyReportsUser/:projectName", reports.GetWeeklyReportsUserHandler)
|
api.Get("/getAllWeeklyReports/:projectName", reports.GetAllWeeklyReports)
|
||||||
api.Post("/submitWeeklyReport", reports.SubmitWeeklyReport)
|
api.Post("/submitWeeklyReport", reports.SubmitWeeklyReport)
|
||||||
api.Put("/signReport/:reportId", reports.SignReport)
|
api.Put("/signReport/:reportId", reports.SignReport)
|
||||||
api.Put("/addUserToProject", projects.AddUserToProjectHandler)
|
|
||||||
api.Put("/updateWeeklyReport", reports.UpdateWeeklyReport)
|
api.Put("/updateWeeklyReport", reports.UpdateWeeklyReport)
|
||||||
|
|
||||||
// Announce the port we are listening on and start the server
|
// Announce the port we are listening on and start the server
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { NewProjMember } from "../Components/AddMember";
|
import { AddMemberInfo } from "../Components/AddMember";
|
||||||
import { ProjectRoleChange } from "../Components/ChangeRole";
|
import { ProjectRoleChange } from "../Components/ChangeRole";
|
||||||
import { projectTimes } from "../Components/GetProjectTimes";
|
import { projectTimes } from "../Components/GetProjectTimes";
|
||||||
import { ProjectMember } from "../Components/GetUsersInProject";
|
import { ProjectMember } from "../Components/GetUsersInProject";
|
||||||
|
@ -99,16 +99,20 @@ interface API {
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<string>>;
|
): Promise<APIResponse<string>>;
|
||||||
|
|
||||||
/** Gets a weekly report for a specific user, project and week
|
/** Gets a weekly report for a specific user, project and week.
|
||||||
|
* Keep in mind that the user within the token needs to be PM
|
||||||
|
* of the project to get the report, unless the user is the target user.
|
||||||
* @param {string} projectName The name of the project.
|
* @param {string} projectName The name of the project.
|
||||||
* @param {string} week The week number.
|
* @param {string} week The week number.
|
||||||
* @param {string} token The authentication token.
|
* @param {string} token The authentication token.
|
||||||
|
* @param {string} targetUser The username of the target user. Defaults to token user.
|
||||||
* @returns {Promise<APIResponse<WeeklyReport>>} A promise resolving to an API response with the retrieved report.
|
* @returns {Promise<APIResponse<WeeklyReport>>} A promise resolving to an API response with the retrieved report.
|
||||||
*/
|
*/
|
||||||
getWeeklyReport(
|
getWeeklyReport(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
week: string,
|
week: string,
|
||||||
token: string,
|
token: string,
|
||||||
|
targetUser?: string,
|
||||||
): Promise<APIResponse<WeeklyReport>>;
|
): Promise<APIResponse<WeeklyReport>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,9 +122,10 @@ interface API {
|
||||||
* @param {string} token The token of the user
|
* @param {string} token The token of the user
|
||||||
* @returns {APIResponse<WeeklyReport[]>} A list of weekly reports
|
* @returns {APIResponse<WeeklyReport[]>} A list of weekly reports
|
||||||
*/
|
*/
|
||||||
getWeeklyReportsForUser(
|
getAllWeeklyReportsForUser(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
token: string,
|
||||||
|
targetUser?: string,
|
||||||
): Promise<APIResponse<WeeklyReport[]>>;
|
): Promise<APIResponse<WeeklyReport[]>>;
|
||||||
|
|
||||||
/** Gets all the projects of a user
|
/** Gets all the projects of a user
|
||||||
|
@ -192,7 +197,13 @@ interface API {
|
||||||
): Promise<APIResponse<void>>;
|
): Promise<APIResponse<void>>;
|
||||||
|
|
||||||
addUserToProject(
|
addUserToProject(
|
||||||
user: NewProjMember,
|
addMemberInfo: AddMemberInfo,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<void>>;
|
||||||
|
|
||||||
|
removeUserFromProject(
|
||||||
|
user: string,
|
||||||
|
project: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<void>>;
|
): Promise<APIResponse<void>>;
|
||||||
|
|
||||||
|
@ -209,6 +220,25 @@ interface API {
|
||||||
* @param {string} token The authentication token
|
* @param {string} token The authentication token
|
||||||
*/
|
*/
|
||||||
signReport(reportId: number, token: string): Promise<APIResponse<string>>;
|
signReport(reportId: number, token: string): Promise<APIResponse<string>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Promotes a user to project manager within a project.
|
||||||
|
*
|
||||||
|
* @param {string} userName The username of the user to promote
|
||||||
|
* @param {string} projectName The name of the project to promote the user in
|
||||||
|
* @returns {Promise<APIResponse<string>} A promise resolving to an API response.
|
||||||
|
*/
|
||||||
|
promoteToPm(
|
||||||
|
userName: string,
|
||||||
|
projectName: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<string>>;
|
||||||
|
/**
|
||||||
|
* Get the username from the id
|
||||||
|
* @param {number} id The id of the user
|
||||||
|
* @param {string} token Your token
|
||||||
|
*/
|
||||||
|
getUsername(id: number, token: string): Promise<APIResponse<string>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An instance of the API */
|
/** An instance of the API */
|
||||||
|
@ -318,18 +348,20 @@ export const api: API = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async addUserToProject(
|
async addUserToProject(
|
||||||
user: NewProjMember,
|
addMemberInfo: AddMemberInfo,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<void>> {
|
): Promise<APIResponse<void>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/addUserToProject", {
|
const response = await fetch(
|
||||||
|
`/api/addUserToProject/${addMemberInfo.projectName}/?userName=${addMemberInfo.userName}`,
|
||||||
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
Authorization: "Bearer " + token,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(user),
|
},
|
||||||
});
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return { success: false, message: "Failed to add member" };
|
return { success: false, message: "Failed to add member" };
|
||||||
|
@ -341,6 +373,31 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async removeUserFromProject(
|
||||||
|
user: string,
|
||||||
|
project: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<void>> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/removeUserFromProject/${project}?userName=${user}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!response.ok) {
|
||||||
|
return { success: false, message: "Failed to remove member" };
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return { success: false, message: "Failed to remove member" };
|
||||||
|
}
|
||||||
|
return { success: true, message: "Removed member" };
|
||||||
|
},
|
||||||
|
|
||||||
async renewToken(token: string): Promise<APIResponse<string>> {
|
async renewToken(token: string): Promise<APIResponse<string>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/loginrenew", {
|
const response = await fetch("/api/loginrenew", {
|
||||||
|
@ -516,10 +573,11 @@ export const api: API = {
|
||||||
projectName: string,
|
projectName: string,
|
||||||
week: string,
|
week: string,
|
||||||
token: string,
|
token: string,
|
||||||
|
targetUser?: string,
|
||||||
): Promise<APIResponse<WeeklyReport>> {
|
): Promise<APIResponse<WeeklyReport>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/getWeeklyReport?projectName=${projectName}&week=${week}`,
|
`/api/getWeeklyReport?projectName=${projectName}&week=${week}&targetUser=${targetUser ?? ""}`,
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -540,18 +598,22 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getWeeklyReportsForUser(
|
async getAllWeeklyReportsForUser(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
token: string,
|
||||||
|
targetUser?: string,
|
||||||
): Promise<APIResponse<WeeklyReport[]>> {
|
): Promise<APIResponse<WeeklyReport[]>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/getWeeklyReportsUser/${projectName}`, {
|
const response = await fetch(
|
||||||
|
`/api/getAllWeeklyReports/${projectName}?targetUser=${targetUser ?? ""}`,
|
||||||
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
Authorization: "Bearer " + token,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return {
|
return {
|
||||||
|
@ -783,4 +845,56 @@ export const api: API = {
|
||||||
return { success: false, message: "Failed to sign report" };
|
return { success: false, message: "Failed to sign report" };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async promoteToPm(
|
||||||
|
userName: string,
|
||||||
|
projectName: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<string>> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/promoteToPm/${projectName}?userName=${userName}`,
|
||||||
|
{
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!response.ok) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed to promote user to project manager",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed to promote user to project manager",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { success: true, message: "User promoted to project manager" };
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUsername(id: number, token: string): Promise<APIResponse<string>> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/username?userId=${id}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return { success: false, message: "Failed to get username" };
|
||||||
|
} else {
|
||||||
|
const data = (await response.json()) as string;
|
||||||
|
return { success: true, data };
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return { success: false, message: "Failed to get username" };
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,44 +1,35 @@
|
||||||
import { APIResponse, api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
|
|
||||||
export interface NewProjMember {
|
export interface AddMemberInfo {
|
||||||
username: string;
|
userName: string;
|
||||||
role: string;
|
projectName: string;
|
||||||
projectname: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to add a member to a project
|
* Tries to add a member to a project
|
||||||
* @param {Object} props - A NewProjMember
|
* @param {AddMemberInfo} props.membertoAdd - Contains user's name and project's name
|
||||||
* @returns {boolean} True if added, false if not
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
function AddMember(props: { memberToAdd: NewProjMember }): boolean {
|
async function AddMember(props: { memberToAdd: AddMemberInfo }): Promise<void> {
|
||||||
let added = false;
|
if (props.memberToAdd.userName === "") {
|
||||||
if (
|
alert("You must choose at least one user to add");
|
||||||
props.memberToAdd.username === "" ||
|
return;
|
||||||
props.memberToAdd.role === "" ||
|
|
||||||
props.memberToAdd.projectname === ""
|
|
||||||
) {
|
|
||||||
alert("All fields must be filled before adding");
|
|
||||||
return added;
|
|
||||||
}
|
}
|
||||||
api
|
try {
|
||||||
.addUserToProject(
|
const response = await api.addUserToProject(
|
||||||
props.memberToAdd,
|
props.memberToAdd,
|
||||||
localStorage.getItem("accessToken") ?? "",
|
localStorage.getItem("accessToken") ?? "",
|
||||||
)
|
);
|
||||||
.then((response: APIResponse<void>) => {
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
alert("Member added");
|
alert(`[${props.memberToAdd.userName}] added`);
|
||||||
added = true;
|
|
||||||
} else {
|
} else {
|
||||||
alert("Member not added");
|
alert(`[${props.memberToAdd.userName}] not added`);
|
||||||
console.error(response.message);
|
console.error(response.message);
|
||||||
}
|
}
|
||||||
})
|
} catch (error) {
|
||||||
.catch((error) => {
|
alert(`[${props.memberToAdd.userName}] not added`);
|
||||||
console.error("An error occurred during member add:", error);
|
console.error("An error occurred during member add:", error);
|
||||||
});
|
}
|
||||||
return added;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AddMember;
|
export default AddMember;
|
||||||
|
|
|
@ -1,37 +1,10 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { APIResponse, api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
import { NewProject } from "../Types/goTypes";
|
import { NewProject } from "../Types/goTypes";
|
||||||
import InputField from "./InputField";
|
import InputField from "./InputField";
|
||||||
import Logo from "../assets/Logo.svg";
|
import Logo from "../assets/Logo.svg";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to add a project to the system
|
|
||||||
* @param {Object} props - Project name and description
|
|
||||||
* @returns {boolean} True if created, false if not
|
|
||||||
*/
|
|
||||||
function CreateProject(props: { name: string; description: string }): void {
|
|
||||||
const project: NewProject = {
|
|
||||||
name: props.name,
|
|
||||||
description: props.description,
|
|
||||||
};
|
|
||||||
|
|
||||||
api
|
|
||||||
.createProject(project, localStorage.getItem("accessToken") ?? "")
|
|
||||||
.then((response: APIResponse<void>) => {
|
|
||||||
if (response.success) {
|
|
||||||
alert("Project added!");
|
|
||||||
} else {
|
|
||||||
alert("Project NOT added!");
|
|
||||||
console.error(response.message);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
alert("Project NOT added!");
|
|
||||||
console.error("An error occurred during creation:", error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides UI for adding a project to the system.
|
* Provides UI for adding a project to the system.
|
||||||
* @returns {JSX.Element} - Returns the component UI for adding a project
|
* @returns {JSX.Element} - Returns the component UI for adding a project
|
||||||
|
@ -40,6 +13,33 @@ function AddProject(): JSX.Element {
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [description, setDescription] = useState("");
|
const [description, setDescription] = useState("");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to add a project to the system
|
||||||
|
*/
|
||||||
|
const handleCreateProject = async (): Promise<void> => {
|
||||||
|
const project: NewProject = {
|
||||||
|
name: name.replace(/ /g, ""),
|
||||||
|
description: description.trim(),
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await api.createProject(
|
||||||
|
project,
|
||||||
|
localStorage.getItem("accessToken") ?? "",
|
||||||
|
);
|
||||||
|
if (response.success) {
|
||||||
|
alert(`${project.name} added!`);
|
||||||
|
setDescription("");
|
||||||
|
setName("");
|
||||||
|
} else {
|
||||||
|
alert("Project not added, name could be taken");
|
||||||
|
console.error(response.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
alert("Project not added");
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-fit w-screen items-center justify-center">
|
<div className="flex flex-col h-fit w-screen items-center justify-center">
|
||||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center h-fit w-fit rounded-3xl content-center pl-20 pr-20">
|
<div className="border-4 border-black bg-white flex flex-col items-center justify-center h-fit w-fit rounded-3xl content-center pl-20 pr-20">
|
||||||
|
@ -47,10 +47,7 @@ function AddProject(): JSX.Element {
|
||||||
className="bg-white rounded px-8 pt-6 pb-8 mb-4 items-center justify-center flex flex-col w-fit h-fit"
|
className="bg-white rounded px-8 pt-6 pb-8 mb-4 items-center justify-center flex flex-col w-fit h-fit"
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
CreateProject({
|
void handleCreateProject();
|
||||||
name: name,
|
|
||||||
description: description,
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
|
|
|
@ -1,71 +1,86 @@
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import GetAllUsers from "./GetAllUsers";
|
import AddMember, { AddMemberInfo } from "./AddMember";
|
||||||
import AddMember, { NewProjMember } from "./AddMember";
|
|
||||||
import BackButton from "./BackButton";
|
import BackButton from "./BackButton";
|
||||||
|
import GetUsersInProject, { ProjectMember } from "./GetUsersInProject";
|
||||||
|
import GetAllUsers from "./GetAllUsers";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides UI for adding a member to a project.
|
* Provides UI for adding a member to a project.
|
||||||
* @returns {JSX.Element} - Returns the component UI for adding a member
|
* @returns {JSX.Element} - Returns the component UI for adding a member
|
||||||
*/
|
*/
|
||||||
function AddUserToProject(props: { projectName: string }): JSX.Element {
|
function AddUserToProject(props: { projectName: string }): JSX.Element {
|
||||||
const [name, setName] = useState("");
|
const [names, setNames] = useState<string[]>([]);
|
||||||
const [users, setUsers] = useState<string[]>([]);
|
const [users, setUsers] = useState<string[]>([]);
|
||||||
const [role, setRole] = useState("");
|
const [usersProj, setUsersProj] = useState<ProjectMember[]>([]);
|
||||||
GetAllUsers({ setUsersProp: setUsers });
|
|
||||||
|
|
||||||
const handleClick = (): boolean => {
|
// Gets all users and project members for filtering
|
||||||
const newMember: NewProjMember = {
|
GetAllUsers({ setUsersProp: setUsers });
|
||||||
username: name,
|
GetUsersInProject({
|
||||||
projectname: props.projectName,
|
setUsersProp: setUsersProj,
|
||||||
role: role,
|
projectName: props.projectName,
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
* Filters the members from users so that users who are already
|
||||||
|
* members are not shown
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
setUsers((prevUsers) => {
|
||||||
|
const filteredUsers = prevUsers.filter(
|
||||||
|
(user) =>
|
||||||
|
!usersProj.some((projectUser) => projectUser.Username === user),
|
||||||
|
);
|
||||||
|
return filteredUsers;
|
||||||
|
});
|
||||||
|
}, [usersProj]);
|
||||||
|
|
||||||
|
// Attempts to add all of the selected users to the project
|
||||||
|
const handleAddClick = async (): Promise<void> => {
|
||||||
|
if (names.length === 0)
|
||||||
|
alert("You have to choose at least one user to add");
|
||||||
|
for (const name of names) {
|
||||||
|
const newMember: AddMemberInfo = {
|
||||||
|
userName: name,
|
||||||
|
projectName: props.projectName,
|
||||||
};
|
};
|
||||||
return AddMember({ memberToAdd: newMember });
|
await AddMember({ memberToAdd: newMember });
|
||||||
|
}
|
||||||
|
setNames([]);
|
||||||
|
location.reload();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Updates the names that have been selected
|
||||||
|
const handleUserClick = (user: string): void => {
|
||||||
|
setNames((prevNames): string[] => {
|
||||||
|
if (!prevNames.includes(user)) {
|
||||||
|
return [...prevNames, user];
|
||||||
|
}
|
||||||
|
return prevNames.filter((name) => name !== user);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center rounded-3xl content-center pl-20 pr-20 h-[75vh] w-[50vh]">
|
<div className="border-4 border-black bg-white flex flex-col items-center pt-10 rounded-3xl content-center pl-20 pr-20 h-[63vh] w-[50] overflow-auto">
|
||||||
<p className="pb-4 mb-2 text-center font-bold text-[18px]">
|
<h1 className="text-center font-bold text-[36px] pb-10">
|
||||||
User chosen: [{name}]
|
{props.projectName}
|
||||||
|
</h1>
|
||||||
|
<p className="p-1 text-center font-bold text-[26px]">
|
||||||
|
Choose users to add:
|
||||||
</p>
|
</p>
|
||||||
<p className="pb-4 mb-2 text-center font-bold text-[18px]">
|
<div className="border-2 border-black pl-2 pr-2 pb-2 rounded-xl text-center overflow-auto h-[26vh] w-[26vh]">
|
||||||
Role chosen: [{role}]
|
|
||||||
</p>
|
|
||||||
<p className="pb-4 mb-2 text-center font-bold text-[18px]">
|
|
||||||
Project chosen: [{props.projectName}]
|
|
||||||
</p>
|
|
||||||
<p className="p-1">Choose role:</p>
|
|
||||||
<div className="border-2 border-black p-2 rounded-xl text-center h-[10h] w-[16] overflow-auto">
|
|
||||||
<ul className="text-center items-center font-medium space-y-2">
|
|
||||||
<li
|
|
||||||
className="h-[10] w-[14] items-start px-2 py-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
|
||||||
onClick={() => {
|
|
||||||
setRole("member");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{"Member"}
|
|
||||||
</li>
|
|
||||||
<li
|
|
||||||
className="h-[10] w-[14] items-start px-2 py-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
|
||||||
onClick={() => {
|
|
||||||
setRole("project_manager");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{"Project manager"}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<p className="p-1">Choose user:</p>
|
|
||||||
<div className="border-2 border-black p-2 rounded-xl text-center overflow-scroll h-[26vh] w-[26vh]">
|
|
||||||
<ul className="text-center font-medium space-y-2">
|
<ul className="text-center font-medium space-y-2">
|
||||||
<div></div>
|
<div></div>
|
||||||
{users.map((user) => (
|
{users.map((user) => (
|
||||||
<li
|
<li
|
||||||
className="items-start p-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
className={
|
||||||
|
names.includes(user)
|
||||||
|
? "items-start p-1 border-2 border-transparent rounded-full bg-orange-500 hover:bg-orange-600 text-white hover:cursor-pointer ring-2 ring-black"
|
||||||
|
: "items-start p-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-400 hover:text-slate-100 hover:cursor-pointer"
|
||||||
|
}
|
||||||
key={user}
|
key={user}
|
||||||
value={user}
|
value={user}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setName(user);
|
handleUserClick(user);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span>{user}</span>
|
<span>{user}</span>
|
||||||
|
@ -73,13 +88,16 @@ function AddUserToProject(props: { projectName: string }): JSX.Element {
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex space-x-5 items-center justify-between">
|
<p className="pt-10 pb-5 underline text-center font-bold text-[18px]">
|
||||||
|
Number of users to be added: {names.length}
|
||||||
|
</p>
|
||||||
|
<div className="space-x-10 items-center">
|
||||||
<Button
|
<Button
|
||||||
text="Add"
|
text="Add"
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
handleClick();
|
void handleAddClick();
|
||||||
}}
|
}}
|
||||||
type="submit"
|
type="button"
|
||||||
/>
|
/>
|
||||||
<BackButton />
|
<BackButton />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,7 +17,7 @@ function AllTimeReportsInProject(): JSX.Element {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getWeeklyReports = async (): Promise<void> => {
|
const getWeeklyReports = async (): Promise<void> => {
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const response = await api.getWeeklyReportsForUser(
|
const response = await api.getAllWeeklyReportsForUser(
|
||||||
projectName ?? "",
|
projectName ?? "",
|
||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,10 +17,10 @@ function AllTimeReportsInProject(): JSX.Element {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getWeeklyReports = async (): Promise<void> => {
|
const getWeeklyReports = async (): Promise<void> => {
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const response = await api.getWeeklyReportsForDifferentUser(
|
const response = await api.getAllWeeklyReportsForUser(
|
||||||
projectName ?? "",
|
projectName ?? "",
|
||||||
username ?? "",
|
|
||||||
token,
|
token,
|
||||||
|
username ?? "",
|
||||||
);
|
);
|
||||||
console.log(response);
|
console.log(response);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
@ -31,7 +31,7 @@ function AllTimeReportsInProject(): JSX.Element {
|
||||||
};
|
};
|
||||||
|
|
||||||
void getWeeklyReports();
|
void getWeeklyReports();
|
||||||
}, []);
|
}, [projectName, username]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { useState } from "react";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import ChangeRole, { ProjectRoleChange } from "./ChangeRole";
|
import ChangeRole, { ProjectRoleChange } from "./ChangeRole";
|
||||||
|
|
||||||
export default function ChangeRoles(props: {
|
export default function ChangeRoleView(props: {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
username: string;
|
username: string;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
|
|
|
@ -2,8 +2,11 @@ import { APIResponse, api } from "../API/API";
|
||||||
import { StrNameChange } from "../Types/goTypes";
|
import { StrNameChange } from "../Types/goTypes";
|
||||||
|
|
||||||
function ChangeUsername(props: { nameChange: StrNameChange }): void {
|
function ChangeUsername(props: { nameChange: StrNameChange }): void {
|
||||||
if (props.nameChange.newName === "") {
|
if (
|
||||||
alert("You have to select a new name");
|
props.nameChange.newName === "" ||
|
||||||
|
props.nameChange.newName === props.nameChange.prevName
|
||||||
|
) {
|
||||||
|
alert("You have to give a new name\n\nName not changed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
api
|
api
|
||||||
|
@ -13,7 +16,7 @@ function ChangeUsername(props: { nameChange: StrNameChange }): void {
|
||||||
alert("Name changed successfully");
|
alert("Name changed successfully");
|
||||||
location.reload();
|
location.reload();
|
||||||
} else {
|
} else {
|
||||||
alert("Name not changed");
|
alert("Name not changed, name could be taken");
|
||||||
console.error(response.message);
|
console.error(response.message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,17 +3,14 @@ import { Link, useParams } from "react-router-dom";
|
||||||
import { api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
import { WeeklyReport } from "../Types/goTypes";
|
import { WeeklyReport } from "../Types/goTypes";
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders a component that displays the projects a user is a part of and links to the projects start-page.
|
|
||||||
* @returns The JSX element representing the component.
|
|
||||||
*/
|
|
||||||
function DisplayUserProject(): JSX.Element {
|
function DisplayUserProject(): JSX.Element {
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
const [unsignedReports, setUnsignedReports] = useState<WeeklyReport[]>([]);
|
const [unsignedReports, setUnsignedReports] = useState<WeeklyReport[]>([]);
|
||||||
//const navigate = useNavigate();
|
const [usernames, setUsernames] = useState<string[]>([]);
|
||||||
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getUnsignedReports = async (): Promise<void> => {
|
const getUnsignedReports = async (): Promise<void> => {
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
|
||||||
const response = await api.getUnsignedReportsInProject(
|
const response = await api.getUnsignedReportsInProject(
|
||||||
projectName ?? "",
|
projectName ?? "",
|
||||||
token,
|
token,
|
||||||
|
@ -21,13 +18,21 @@ function DisplayUserProject(): JSX.Element {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setUnsignedReports(response.data ?? []);
|
setUnsignedReports(response.data ?? []);
|
||||||
|
const usernamesPromises = (response.data ?? []).map((report) =>
|
||||||
|
api.getUsername(report.userId, token),
|
||||||
|
);
|
||||||
|
const usernamesResponses = await Promise.all(usernamesPromises);
|
||||||
|
const usernames = usernamesResponses.map(
|
||||||
|
(res) => (res.data as { username?: string }).username ?? "",
|
||||||
|
);
|
||||||
|
setUsernames(usernames);
|
||||||
} else {
|
} else {
|
||||||
console.error(response.message);
|
console.error(response.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void getUnsignedReports();
|
void getUnsignedReports();
|
||||||
}, [projectName]); // Include 'projectName' in the dependency array
|
}, [projectName, token]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -39,8 +44,8 @@ function DisplayUserProject(): JSX.Element {
|
||||||
<h1 key={index} className="border-b-2 border-black w-full">
|
<h1 key={index} className="border-b-2 border-black w-full">
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<span className="ml-6 mr-2 font-bold">UserID:</span>
|
<span className="ml-6 mr-2 font-bold">Username:</span>
|
||||||
<h1>{unsignedReport.userId}</h1>
|
<h1>{usernames[index]}</h1>{" "}
|
||||||
<span className="ml-6 mr-2 font-bold">Week:</span>
|
<span className="ml-6 mr-2 font-bold">Week:</span>
|
||||||
<h1>{unsignedReport.week}</h1>
|
<h1>{unsignedReport.week}</h1>
|
||||||
<span className="ml-6 mr-2 font-bold">Total Time:</span>
|
<span className="ml-6 mr-2 font-bold">Total Time:</span>
|
||||||
|
@ -58,7 +63,7 @@ function DisplayUserProject(): JSX.Element {
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<div className="ml-auto flex space-x-4">
|
<div className="ml-auto flex space-x-4">
|
||||||
<Link
|
<Link
|
||||||
to={`/PMViewUnsignedReport/${projectName}/${unsignedReport.userId}/${unsignedReport.week}`}
|
to={`/PMViewUnsignedReport/${projectName}/${usernames[index]}/${unsignedReport.week}`}
|
||||||
>
|
>
|
||||||
<h1 className="underline cursor-pointer font-bold">
|
<h1 className="underline cursor-pointer font-bold">
|
||||||
View Report
|
View Report
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//info: Header component to display the header of the page including the logo and user information where thr user can logout
|
//info: Header component to display the header of the page including the logo and user information where thr user can logout
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import backgroundImage from "../assets/1.jpg";
|
import backgroundImage from "../assets/1.jpg";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,23 +9,33 @@ import backgroundImage from "../assets/1.jpg";
|
||||||
*/
|
*/
|
||||||
function Header(): JSX.Element {
|
function Header(): JSX.Element {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const username = localStorage.getItem("username");
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleLogout = (): void => {
|
const handleLogout = (): void => {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleNavigation = (): void => {
|
||||||
|
if (username === "admin") {
|
||||||
|
navigate("/admin");
|
||||||
|
} else {
|
||||||
|
navigate("/yourProjects");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header
|
<header
|
||||||
className="fixed top-0 left-0 right-0 border-[1.75px] border-black text-black p-3 pl-5 flex items-center justify-between bg-cover"
|
className="fixed top-0 left-0 right-0 border-[1.75px] border-black text-black p-3 pl-5 flex items-center justify-between bg-cover"
|
||||||
style={{ backgroundImage: `url(${backgroundImage})` }}
|
style={{ backgroundImage: `url(${backgroundImage})` }}
|
||||||
>
|
>
|
||||||
<Link to="/your-projects">
|
<div onClick={handleNavigation}>
|
||||||
<img
|
<img
|
||||||
src="/src/assets/Logo.svg"
|
src="/src/assets/Logo.svg"
|
||||||
alt="TTIME Logo"
|
alt="TTIME Logo"
|
||||||
className="w-11 h-14 cursor-pointer"
|
className="w-11 h-14 cursor-pointer"
|
||||||
/>
|
/>
|
||||||
</Link>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className="relative"
|
className="relative"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import DeleteUser from "./DeleteUser";
|
|
||||||
import UserProjectListAdmin from "./UserProjectListAdmin";
|
import UserProjectListAdmin from "./UserProjectListAdmin";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import ChangeRoleView from "./ChangeRoleView";
|
import ChangeRoleView from "./ChangeRoleView";
|
||||||
|
import RemoveUserFromProj from "./RemoveUserFromProj";
|
||||||
|
|
||||||
function MemberInfoModal(props: {
|
function MemberInfoModal(props: {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
|
@ -20,7 +20,7 @@ function MemberInfoModal(props: {
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
className="fixed inset-10 bg-opacity-30 backdrop-blur-sm
|
||||||
flex justify-center items-center"
|
flex justify-center items-center"
|
||||||
>
|
>
|
||||||
<div className="border-4 border-black bg-white rounded-lg text-center flex flex-col">
|
<div className="border-4 border-black bg-white rounded-lg text-center flex flex-col">
|
||||||
|
@ -42,13 +42,16 @@ function MemberInfoModal(props: {
|
||||||
<UserProjectListAdmin username={props.username} />
|
<UserProjectListAdmin username={props.username} />
|
||||||
<div className="items-center space-x-6">
|
<div className="items-center space-x-6">
|
||||||
<Button
|
<Button
|
||||||
text={"Delete"}
|
text={"Remove"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
if (
|
if (
|
||||||
window.confirm("Are you sure you want to delete this user?")
|
window.confirm(
|
||||||
|
"Are you sure you want to remove this user from the project?",
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
DeleteUser({
|
RemoveUserFromProj({
|
||||||
usernameToDelete: props.username,
|
userToRemove: props.username,
|
||||||
|
projectName: props.projectName,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -62,7 +62,7 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
const success = await handleNewWeeklyReport();
|
const success = await handleNewWeeklyReport();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
alert(
|
alert(
|
||||||
"A Time Report for this week already exists, please go to the edit page to edit it or change week number.",
|
"Error occurred! Your connection to the server might be lost or a time report for this week already exists, please check your connection or go to the edit page to edit your report or change week number.",
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ export default function OtherUsersTR(): JSX.Element {
|
||||||
projectName ?? "",
|
projectName ?? "",
|
||||||
fetchedWeek?.toString() ?? "0",
|
fetchedWeek?.toString() ?? "0",
|
||||||
token,
|
token,
|
||||||
|
username ?? "",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
@ -86,6 +87,7 @@ export default function OtherUsersTR(): JSX.Element {
|
||||||
min="0"
|
min="0"
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
className="border-2 border-black rounded-md text-center w-1/2"
|
||||||
value={developmentTime === 0 ? "" : developmentTime}
|
value={developmentTime === 0 ? "" : developmentTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -97,6 +99,7 @@ export default function OtherUsersTR(): JSX.Element {
|
||||||
min="0"
|
min="0"
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
className="border-2 border-black rounded-md text-center w-1/2"
|
||||||
value={meetingTime === 0 ? "" : meetingTime}
|
value={meetingTime === 0 ? "" : meetingTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -108,6 +111,7 @@ export default function OtherUsersTR(): JSX.Element {
|
||||||
min="0"
|
min="0"
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
className="border-2 border-black rounded-md text-center w-1/2"
|
||||||
value={adminTime === 0 ? "" : adminTime}
|
value={adminTime === 0 ? "" : adminTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -119,6 +123,7 @@ export default function OtherUsersTR(): JSX.Element {
|
||||||
min="0"
|
min="0"
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
className="border-2 border-black rounded-md text-center w-1/2"
|
||||||
value={ownWorkTime === 0 ? "" : ownWorkTime}
|
value={ownWorkTime === 0 ? "" : ownWorkTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -130,6 +135,7 @@ export default function OtherUsersTR(): JSX.Element {
|
||||||
min="0"
|
min="0"
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
className="border-2 border-black rounded-md text-center w-1/2"
|
||||||
value={studyTime === 0 ? "" : studyTime}
|
value={studyTime === 0 ? "" : studyTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -141,6 +147,7 @@ export default function OtherUsersTR(): JSX.Element {
|
||||||
min="0"
|
min="0"
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
className="border-2 border-black rounded-md text-center w-1/2"
|
||||||
value={testingTime === 0 ? "" : testingTime}
|
value={testingTime === 0 ? "" : testingTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -38,7 +38,12 @@ function ProjectInfoModal(props: {
|
||||||
</div>
|
</div>
|
||||||
<div className="border-2 border-black rounded-lg h-[8vh] text-left divide-y-2 flex flex-col overflow-auto mx-10">
|
<div className="border-2 border-black rounded-lg h-[8vh] text-left divide-y-2 flex flex-col overflow-auto mx-10">
|
||||||
<p className="p-2">Number of members: {users.length}</p>
|
<p className="p-2">Number of members: {users.length}</p>
|
||||||
<p className="p-2">Total time reported: {totalTime.current}</p>
|
<p className="p-2">
|
||||||
|
Total time reported:{" "}
|
||||||
|
{Math.floor(totalTime.current / 60 / 24) + " d "}
|
||||||
|
{Math.floor((totalTime.current / 60) % 24) + " h "}
|
||||||
|
{(totalTime.current % 60) + " m "}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="h-[6vh] p-7 text-center">
|
<div className="h-[6vh] p-7 text-center">
|
||||||
<h2 className="text-[20px] font-bold">Project members:</h2>
|
<h2 className="text-[20px] font-bold">Project members:</h2>
|
||||||
|
|
|
@ -15,17 +15,21 @@ export default function Register(): JSX.Element {
|
||||||
const [errMessage, setErrMessage] = useState<string>();
|
const [errMessage, setErrMessage] = useState<string>();
|
||||||
|
|
||||||
const handleRegister = async (): Promise<void> => {
|
const handleRegister = async (): Promise<void> => {
|
||||||
|
if (username === "" || password === "") {
|
||||||
|
alert("Must provide username and password");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const newUser: NewUser = {
|
const newUser: NewUser = {
|
||||||
username: username ?? "",
|
username: username?.replace(/ /g, "") ?? "",
|
||||||
password: password ?? "",
|
password: password ?? "",
|
||||||
};
|
};
|
||||||
const response = await api.registerUser(newUser);
|
const response = await api.registerUser(newUser);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
alert("User added!");
|
alert(`${newUser.username} added!`);
|
||||||
setPassword("");
|
setPassword("");
|
||||||
setUsername("");
|
setUsername("");
|
||||||
} else {
|
} else {
|
||||||
alert("User not added");
|
alert("User not added, name could be taken");
|
||||||
setErrMessage(response.message ?? "Unknown error");
|
setErrMessage(response.message ?? "Unknown error");
|
||||||
console.error(errMessage);
|
console.error(errMessage);
|
||||||
}
|
}
|
||||||
|
|
41
frontend/src/Components/RemoveUserFromProj.tsx
Normal file
41
frontend/src/Components/RemoveUserFromProj.tsx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import { api, APIResponse } from "../API/API";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a user from a project
|
||||||
|
* @param {string} props.usernameToDelete - The username of user to remove
|
||||||
|
* @param {string} props.projectName - Project to remove user from
|
||||||
|
* @returns {void}
|
||||||
|
* @example
|
||||||
|
* const exampleUsername = "user";
|
||||||
|
* const exampleProjectName "project";
|
||||||
|
* RemoveUserFromProj({ userToRemove: exampleUsername, projectName: exampleProjectName });
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default function RemoveUserFromProj(props: {
|
||||||
|
userToRemove: string;
|
||||||
|
projectName: string;
|
||||||
|
}): void {
|
||||||
|
if (props.userToRemove === localStorage.getItem("username")) {
|
||||||
|
alert("Cannot remove yourself");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api
|
||||||
|
.removeUserFromProject(
|
||||||
|
props.userToRemove,
|
||||||
|
props.projectName,
|
||||||
|
localStorage.getItem("accessToken") ?? "",
|
||||||
|
)
|
||||||
|
.then((response: APIResponse<void>) => {
|
||||||
|
if (response.success) {
|
||||||
|
alert(`${props.userToRemove} has been removed!`);
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert(`${props.userToRemove} has not been removed due to an error`);
|
||||||
|
console.error(response.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
alert(`${props.userToRemove} has not been removed due to an error`);
|
||||||
|
console.error("An error occurred during deletion:", error);
|
||||||
|
});
|
||||||
|
}
|
|
@ -8,12 +8,12 @@ import { projectTimes } from "./GetProjectTimes";
|
||||||
* @returns JSX.Element
|
* @returns JSX.Element
|
||||||
*/
|
*/
|
||||||
export default function TimePerRole(): JSX.Element {
|
export default function TimePerRole(): JSX.Element {
|
||||||
const [development, setDevelopment] = useState<number>();
|
const [development, setDevelopment] = useState<number>(0);
|
||||||
const [meeting, setMeeting] = useState<number>();
|
const [meeting, setMeeting] = useState<number>(0);
|
||||||
const [admin, setAdmin] = useState<number>();
|
const [admin, setAdmin] = useState<number>(0);
|
||||||
const [own_work, setOwnWork] = useState<number>();
|
const [own_work, setOwnWork] = useState<number>(0);
|
||||||
const [study, setStudy] = useState<number>();
|
const [study, setStudy] = useState<number>(0);
|
||||||
const [testing, setTesting] = useState<number>();
|
const [testing, setTesting] = useState<number>(0);
|
||||||
|
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
|
|
|
@ -28,7 +28,7 @@ function UserInfoModal(props: {
|
||||||
const handleClickChangeName = (): void => {
|
const handleClickChangeName = (): void => {
|
||||||
const nameChange: StrNameChange = {
|
const nameChange: StrNameChange = {
|
||||||
prevName: props.username,
|
prevName: props.username,
|
||||||
newName: newUsername,
|
newName: newUsername.replace(/ /g, ""),
|
||||||
};
|
};
|
||||||
ChangeUsername({ nameChange: nameChange });
|
ChangeUsername({ nameChange: nameChange });
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,8 +31,9 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
projectName ?? "",
|
projectName ?? "",
|
||||||
fetchedWeek?.toString() ?? "0",
|
fetchedWeek?.toString() ?? "0",
|
||||||
token,
|
token,
|
||||||
|
username ?? "",
|
||||||
);
|
);
|
||||||
|
console.log(response);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
const report: WeeklyReport = response.data ?? {
|
const report: WeeklyReport = response.data ?? {
|
||||||
reportId: 0,
|
reportId: 0,
|
||||||
|
@ -62,25 +63,33 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
void fetchUsersWeeklyReport();
|
void fetchUsersWeeklyReport();
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSignWeeklyReport = async (): Promise<void> => {
|
const handleSignWeeklyReport = async (): Promise<boolean> => {
|
||||||
await api.signReport(reportId, token);
|
const response = await api.signReport(reportId, token);
|
||||||
|
if (response.success) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="text-[30px] font-bold">
|
<h1 className="text-[30px] font-bold"> {username}'s Report</h1>
|
||||||
{" "}
|
|
||||||
UserId: {username}'s Report
|
|
||||||
</h1>
|
|
||||||
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
||||||
<form
|
<form
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void handleSignWeeklyReport();
|
void (async (): Promise<void> => {
|
||||||
|
const success = await handleSignWeeklyReport();
|
||||||
|
if (!success) {
|
||||||
|
alert("Failed to sign report!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
alert("Report successfully signed!");
|
alert("Report successfully signed!");
|
||||||
navigate(-1);
|
navigate(-1);
|
||||||
|
})();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="flex flex-col items-center">
|
<div className="flex flex-col items-center">
|
||||||
|
|
151
testing/helpers.py
Normal file
151
testing/helpers.py
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
import requests
|
||||||
|
import string
|
||||||
|
import random
|
||||||
|
import json
|
||||||
|
|
||||||
|
# Helper function for the TTime API testing suite
|
||||||
|
|
||||||
|
# For style guide, see:
|
||||||
|
# https://peps.python.org/pep-0008/#function-and-variable-names
|
||||||
|
# https://google.github.io/styleguide/pyguide.html#316-naming
|
||||||
|
|
||||||
|
##################
|
||||||
|
## Static Paths ##
|
||||||
|
##################
|
||||||
|
|
||||||
|
base_url = "http://localhost:8080"
|
||||||
|
|
||||||
|
registerPath = base_url + "/api/register"
|
||||||
|
loginPath = base_url + "/api/login"
|
||||||
|
addProjectPath = base_url + "/api/project"
|
||||||
|
submitReportPath = base_url + "/api/submitWeeklyReport"
|
||||||
|
getWeeklyReportPath = base_url + "/api/getWeeklyReport"
|
||||||
|
getProjectPath = base_url + "/api/project"
|
||||||
|
signReportPath = base_url + "/api/signReport"
|
||||||
|
addUserToProjectPath = base_url + "/api/addUserToProject"
|
||||||
|
promoteToAdminPath = base_url + "/api/promoteToAdmin"
|
||||||
|
getUserProjectsPath = base_url + "/api/getUserProjects"
|
||||||
|
getAllWeeklyReportsPath = base_url + "/api/getAllWeeklyReports"
|
||||||
|
checkIfProjectManagerPath = base_url + "/api/checkIfProjectManager"
|
||||||
|
ProjectRoleChangePath = base_url + "/api/ProjectRoleChange"
|
||||||
|
getUsersProjectPath = base_url + "/api/getUsersProject"
|
||||||
|
getUnsignedReportsPath = base_url + "/api/getUnsignedReports"
|
||||||
|
getChangeUserNamePath = base_url + "/api/changeUserName"
|
||||||
|
getUpdateWeeklyReportPath = base_url + "/api/updateWeeklyReport"
|
||||||
|
removeProjectPath = base_url + "/api/removeProject"
|
||||||
|
promoteToPmPath = base_url + "/api/promoteToPm"
|
||||||
|
|
||||||
|
debug_output = True
|
||||||
|
|
||||||
|
|
||||||
|
def gprint(*args, **kwargs):
|
||||||
|
print("\033[92m", *args, "\033[00m", **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def dprint(*args, **kwargs):
|
||||||
|
if debug_output:
|
||||||
|
print(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def randomString(len=10):
|
||||||
|
"""Generate a random string of fixed length"""
|
||||||
|
letters = string.ascii_lowercase
|
||||||
|
return "".join(random.choice(letters) for i in range(len))
|
||||||
|
|
||||||
|
|
||||||
|
############ ############ ############ ############ ############
|
||||||
|
|
||||||
|
|
||||||
|
# Posts the username and password to the register endpoint
|
||||||
|
def register(username: string, password: string):
|
||||||
|
dprint("Registering with username: ", username, " and password: ", password)
|
||||||
|
response = requests.post(
|
||||||
|
registerPath, json={"username": username, "password": password}
|
||||||
|
)
|
||||||
|
dprint(response.text)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
# Posts the username and password to the login endpoint
|
||||||
|
def login(username: string, password: string):
|
||||||
|
dprint("Logging in with username: ", username, " and password: ", password)
|
||||||
|
response = requests.post(
|
||||||
|
loginPath, json={"username": username, "password": password}
|
||||||
|
)
|
||||||
|
dprint(response.text)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
# Register a user and return the token
|
||||||
|
def register_and_login(username: string, password: string) -> string:
|
||||||
|
register(username, password)
|
||||||
|
response = login(username, password)
|
||||||
|
return response.json()["token"]
|
||||||
|
|
||||||
|
|
||||||
|
def create_project(
|
||||||
|
token: string, project_name: string, description: string = "Test description"
|
||||||
|
):
|
||||||
|
dprint("Creating project with name: ", project_name)
|
||||||
|
response = requests.post(
|
||||||
|
addProjectPath,
|
||||||
|
headers={"Authorization": "Bearer " + token},
|
||||||
|
json={"name": project_name, "description": description},
|
||||||
|
)
|
||||||
|
dprint(response.text)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
# Add a user to a project, requires the user withing the token to be a project manager of said project
|
||||||
|
def addToProject(token: string, username: string, project_name: string):
|
||||||
|
dprint("Adding user with username: ", username, " to project: ", project_name)
|
||||||
|
response = requests.put(
|
||||||
|
addUserToProjectPath + "/" + project_name,
|
||||||
|
headers={"Authorization": "Bearer " + token},
|
||||||
|
params={"userName": username},
|
||||||
|
)
|
||||||
|
dprint(response.text)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def promoteToManager(token: string, username: string, project_name: string):
|
||||||
|
dprint(
|
||||||
|
"Promoting user with username: ",
|
||||||
|
username,
|
||||||
|
" to project manager of project: ",
|
||||||
|
project_name,
|
||||||
|
)
|
||||||
|
response = requests.put(
|
||||||
|
promoteToPmPath + "/" + project_name,
|
||||||
|
headers={"Authorization": "Bearer " + token},
|
||||||
|
params={"userName": username},
|
||||||
|
)
|
||||||
|
dprint(response.text)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def submitReport(token: string, report):
|
||||||
|
dprint("Submitting report: ", report)
|
||||||
|
response = requests.post(
|
||||||
|
submitReportPath,
|
||||||
|
json=report,
|
||||||
|
headers={"Authorization": "Bearer " + token},
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def getReport(token: string, username: string, projectName: string):
|
||||||
|
# Retrieve the report ID
|
||||||
|
response = requests.get(
|
||||||
|
getWeeklyReportPath,
|
||||||
|
headers={"Authorization": "Bearer " + token},
|
||||||
|
params={"username": username, "projectName": projectName, "week": 1},
|
||||||
|
)
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
def signReport(project_manager_token: string, report_id: int):
|
||||||
|
return requests.put(
|
||||||
|
signReportPath + "/" + str(report_id),
|
||||||
|
headers={"Authorization": "Bearer " + project_manager_token},
|
||||||
|
)
|
|
@ -1,50 +1,14 @@
|
||||||
import requests
|
import requests
|
||||||
import string
|
|
||||||
import random
|
|
||||||
|
|
||||||
debug_output = True
|
# This modules contains helper functions for the tests
|
||||||
|
from helpers import *
|
||||||
def gprint(*args, **kwargs):
|
|
||||||
print("\033[92m", *args, "\033[00m", **kwargs)
|
|
||||||
|
|
||||||
print("Running Tests...")
|
print("Running Tests...")
|
||||||
|
|
||||||
def dprint(*args, **kwargs):
|
|
||||||
if debug_output:
|
|
||||||
print(*args, **kwargs)
|
|
||||||
|
|
||||||
def randomString(len=10):
|
|
||||||
"""Generate a random string of fixed length"""
|
|
||||||
letters = string.ascii_lowercase
|
|
||||||
return "".join(random.choice(letters) for i in range(len))
|
|
||||||
|
|
||||||
|
|
||||||
# Defined once per test run
|
# Defined once per test run
|
||||||
username = "user_" + randomString()
|
username = "user_" + randomString()
|
||||||
projectName = "project_" + randomString()
|
projectName = "project_" + randomString()
|
||||||
|
|
||||||
# The base URL of the API
|
|
||||||
base_url = "http://localhost:8080"
|
|
||||||
|
|
||||||
# Endpoint to test
|
|
||||||
registerPath = base_url + "/api/register"
|
|
||||||
loginPath = base_url + "/api/login"
|
|
||||||
addProjectPath = base_url + "/api/project"
|
|
||||||
submitReportPath = base_url + "/api/submitWeeklyReport"
|
|
||||||
getWeeklyReportPath = base_url + "/api/getWeeklyReport"
|
|
||||||
getProjectPath = base_url + "/api/project"
|
|
||||||
signReportPath = base_url + "/api/signReport"
|
|
||||||
addUserToProjectPath = base_url + "/api/addUserToProject"
|
|
||||||
promoteToAdminPath = base_url + "/api/promoteToAdmin"
|
|
||||||
getUserProjectsPath = base_url + "/api/getUserProjects"
|
|
||||||
getWeeklyReportsUserPath = base_url + "/api/getWeeklyReportsUser"
|
|
||||||
checkIfProjectManagerPath = base_url + "/api/checkIfProjectManager"
|
|
||||||
ProjectRoleChangePath = base_url + "/api/ProjectRoleChange"
|
|
||||||
getUsersProjectPath = base_url + "/api/getUsersProject"
|
|
||||||
getUnsignedReportsPath = base_url + "/api/getUnsignedReports"
|
|
||||||
getChangeUserNamePath = base_url + "/api/changeUserName"
|
|
||||||
getUpdateWeeklyReportPath = base_url + "/api/updateWeeklyReport"
|
|
||||||
removeProjectPath = base_url + "/api/removeProject"
|
|
||||||
|
|
||||||
# ta bort auth i handlern för att få testet att gå igenom
|
# ta bort auth i handlern för att få testet att gå igenom
|
||||||
def test_ProjectRoleChange():
|
def test_ProjectRoleChange():
|
||||||
|
@ -53,9 +17,7 @@ def test_ProjectRoleChange():
|
||||||
localProjectName = randomString()
|
localProjectName = randomString()
|
||||||
register(localUsername, "username_password")
|
register(localUsername, "username_password")
|
||||||
|
|
||||||
token = login(localUsername, "username_password").json()[
|
token = login(localUsername, "username_password").json()["token"]
|
||||||
"token"
|
|
||||||
]
|
|
||||||
|
|
||||||
# Just checking since this test is built somewhat differently than the others
|
# Just checking since this test is built somewhat differently than the others
|
||||||
assert token != None, "Login failed"
|
assert token != None, "Login failed"
|
||||||
|
@ -83,13 +45,14 @@ def test_ProjectRoleChange():
|
||||||
|
|
||||||
|
|
||||||
def test_get_user_projects():
|
def test_get_user_projects():
|
||||||
|
username = "user2"
|
||||||
|
password = "123"
|
||||||
|
|
||||||
dprint("Testing get user projects")
|
dprint("Testing get user projects")
|
||||||
loginResponse = login("user2", "123")
|
loginResponse = login(username, password)
|
||||||
# Check if the user is added to the project
|
# Check if the user is added to the project
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
getUserProjectsPath,
|
getUserProjectsPath + "/" + username,
|
||||||
json={"username": "user2"},
|
|
||||||
headers={"Authorization": "Bearer " + loginResponse.json()["token"]},
|
headers={"Authorization": "Bearer " + loginResponse.json()["token"]},
|
||||||
)
|
)
|
||||||
dprint(response.text)
|
dprint(response.text)
|
||||||
|
@ -98,26 +61,6 @@ def test_get_user_projects():
|
||||||
gprint("test_get_user_projects successful")
|
gprint("test_get_user_projects successful")
|
||||||
|
|
||||||
|
|
||||||
# Posts the username and password to the register endpoint
|
|
||||||
def register(username: string, password: string):
|
|
||||||
dprint("Registering with username: ", username, " and password: ", password)
|
|
||||||
response = requests.post(
|
|
||||||
registerPath, json={"username": username, "password": password}
|
|
||||||
)
|
|
||||||
dprint(response.text)
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
# Posts the username and password to the login endpoint
|
|
||||||
def login(username: string, password: string):
|
|
||||||
dprint("Logging in with username: ", username, " and password: ", password)
|
|
||||||
response = requests.post(
|
|
||||||
loginPath, json={"username": username, "password": password}
|
|
||||||
)
|
|
||||||
dprint(response.text)
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
# Test function to login
|
# Test function to login
|
||||||
def test_login():
|
def test_login():
|
||||||
response = login(username, "always_same")
|
response = login(username, "always_same")
|
||||||
|
@ -133,6 +76,7 @@ def test_create_user():
|
||||||
assert response.status_code == 200, "Registration failed"
|
assert response.status_code == 200, "Registration failed"
|
||||||
gprint("test_create_user 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():
|
||||||
loginResponse = login(username, "always_same")
|
loginResponse = login(username, "always_same")
|
||||||
|
@ -146,6 +90,7 @@ def test_add_project():
|
||||||
assert response.status_code == 200, "Add project failed"
|
assert response.status_code == 200, "Add project failed"
|
||||||
gprint("test_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():
|
||||||
token = login(username, "always_same").json()["token"]
|
token = login(username, "always_same").json()["token"]
|
||||||
|
@ -167,6 +112,7 @@ def test_submit_report():
|
||||||
assert response.status_code == 200, "Submit report failed"
|
assert response.status_code == 200, "Submit report failed"
|
||||||
gprint("test_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():
|
||||||
token = login(username, "always_same").json()["token"]
|
token = login(username, "always_same").json()["token"]
|
||||||
|
@ -194,91 +140,58 @@ def test_get_project():
|
||||||
|
|
||||||
# Test function to add a user to a project
|
# Test function to add a user to a project
|
||||||
def test_add_user_to_project():
|
def test_add_user_to_project():
|
||||||
# Log in as a site admin
|
# User to create
|
||||||
admin_username = randomString()
|
pm_user = "user" + randomString()
|
||||||
admin_password = "admin_password"
|
pm_passwd = "password"
|
||||||
dprint(
|
|
||||||
"Registering with username: ", admin_username, " and password: ", admin_password
|
|
||||||
)
|
|
||||||
response = requests.post(
|
|
||||||
registerPath, json={"username": admin_username, "password": admin_password}
|
|
||||||
)
|
|
||||||
dprint(response.text)
|
|
||||||
|
|
||||||
admin_token = login(admin_username, admin_password).json()["token"]
|
# User to add
|
||||||
response = requests.post(
|
member_user = "member" + randomString()
|
||||||
promoteToAdminPath,
|
member_passwd = "password"
|
||||||
json={"username": admin_username},
|
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
|
||||||
)
|
|
||||||
dprint(response.text)
|
|
||||||
assert response.status_code == 200, "Promote to site admin failed"
|
|
||||||
dprint("Admin promoted to site admin successfully")
|
|
||||||
|
|
||||||
# Create a new user to add to the project
|
# Name of the project to be created
|
||||||
new_user = randomString()
|
project_name = "project" + randomString()
|
||||||
register(new_user, "new_user_password")
|
|
||||||
|
|
||||||
# Add the new user to the project as a member
|
pm_token = register_and_login(pm_user, pm_passwd)
|
||||||
response = requests.put(
|
register(member_user, member_passwd)
|
||||||
addUserToProjectPath,
|
|
||||||
json={"projectName": projectName, "username": new_user, "role": "member"},
|
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
|
||||||
)
|
|
||||||
|
|
||||||
dprint(response.text)
|
response = create_project(pm_token, project_name)
|
||||||
|
assert response.status_code == 200, "Create project failed"
|
||||||
|
|
||||||
|
# Promote the user to project manager
|
||||||
|
response = addToProject(pm_token, member_user, project_name)
|
||||||
assert response.status_code == 200, "Add user to project failed"
|
assert response.status_code == 200, "Add user to project failed"
|
||||||
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():
|
||||||
# Create a project manager user
|
# Pm user
|
||||||
project_manager = randomString()
|
pm_username = "pm" + randomString()
|
||||||
register(project_manager, "project_manager_password")
|
pm_password = "admin_password2"
|
||||||
|
|
||||||
# Register an admin
|
# User to add
|
||||||
admin_username = randomString()
|
member_user = "member" + randomString()
|
||||||
admin_password = "admin_password2"
|
member_passwd = "password"
|
||||||
dprint(
|
|
||||||
"Registering with username: ", admin_username, " and password: ", admin_password
|
|
||||||
)
|
|
||||||
response = requests.post(
|
|
||||||
registerPath, json={"username": admin_username, "password": admin_password}
|
|
||||||
)
|
|
||||||
dprint(response.text)
|
|
||||||
|
|
||||||
# Log in as the admin
|
# Name of the project to be created
|
||||||
admin_token = login(admin_username, admin_password).json()["token"]
|
project_name = "project" + randomString()
|
||||||
response = requests.post(
|
|
||||||
promoteToAdminPath,
|
|
||||||
json={"username": admin_username},
|
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
|
||||||
)
|
|
||||||
|
|
||||||
response = requests.put(
|
# Register and get the tokens for both users
|
||||||
addUserToProjectPath,
|
pm_token = register_and_login(pm_username, pm_password)
|
||||||
json={
|
member_token = register_and_login(member_user, member_passwd)
|
||||||
"projectName": projectName,
|
|
||||||
"username": project_manager,
|
|
||||||
"role": "project_manager",
|
|
||||||
},
|
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200, "Add project manager to project failed"
|
|
||||||
dprint("Project manager added to project successfully")
|
|
||||||
|
|
||||||
# Log in as the project manager
|
# Create the project
|
||||||
project_manager_token = login(project_manager, "project_manager_password").json()[
|
response = create_project(pm_token, project_name)
|
||||||
"token"
|
assert response.status_code == 200, "Create project failed"
|
||||||
]
|
|
||||||
|
# Add the user to the project
|
||||||
|
response = addToProject(pm_token, member_user, project_name)
|
||||||
|
|
||||||
# Submit a report for the project
|
# Submit a report for the project
|
||||||
token = login(username, "always_same").json()["token"]
|
response = submitReport(
|
||||||
response = requests.post(
|
member_token,
|
||||||
submitReportPath,
|
{
|
||||||
json={
|
"projectName": project_name,
|
||||||
"projectName": projectName,
|
"week": 1,
|
||||||
"week": 2,
|
|
||||||
"developmentTime": 10,
|
"developmentTime": 10,
|
||||||
"meetingTime": 5,
|
"meetingTime": 5,
|
||||||
"adminTime": 5,
|
"adminTime": 5,
|
||||||
|
@ -286,46 +199,33 @@ def test_sign_report():
|
||||||
"studyTime": 10,
|
"studyTime": 10,
|
||||||
"testingTime": 10,
|
"testingTime": 10,
|
||||||
},
|
},
|
||||||
headers={"Authorization": "Bearer " + token},
|
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, "Submit report failed"
|
assert response.status_code == 200, "Submit report failed"
|
||||||
dprint("Submit report successful")
|
|
||||||
|
|
||||||
# Retrieve the report ID
|
# Retrieve the report ID
|
||||||
response = requests.get(
|
report_id = getReport(member_token, member_user, project_name)["reportId"]
|
||||||
getWeeklyReportPath,
|
|
||||||
headers={"Authorization": "Bearer " + token},
|
|
||||||
params={"username": username, "projectName": projectName, "week": 1},
|
|
||||||
)
|
|
||||||
dprint(response.text)
|
|
||||||
report_id = response.json()["reportId"]
|
|
||||||
|
|
||||||
# Sign the report as the project manager
|
# Sign the report as the project manager
|
||||||
response = requests.put(
|
response = signReport(pm_token, report_id)
|
||||||
signReportPath + "/" + str(report_id),
|
|
||||||
headers={"Authorization": "Bearer " + project_manager_token},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200, "Sign report failed"
|
assert response.status_code == 200, "Sign report failed"
|
||||||
dprint("Sign report successful")
|
dprint("Sign report successful")
|
||||||
|
|
||||||
# Retrieve the report ID again for confirmation
|
# Retrieve the report ID again for confirmation
|
||||||
response = requests.get(
|
report_id = getReport(member_token, member_user, project_name)["reportId"]
|
||||||
getWeeklyReportPath,
|
assert report_id != None, "Get report failed"
|
||||||
headers={"Authorization": "Bearer " + token},
|
|
||||||
params={"username": username, "projectName": projectName, "week": 1},
|
|
||||||
)
|
|
||||||
dprint(response.text)
|
|
||||||
gprint("test_sign_report successful")
|
gprint("test_sign_report successful")
|
||||||
|
|
||||||
|
|
||||||
# Test function to get weekly reports for a user in a project
|
# Test function to get weekly reports for a user in a project
|
||||||
def test_get_weekly_reports_user():
|
def test_get_all_weekly_reports():
|
||||||
# Log in as the user
|
# Log in as the user
|
||||||
token = login(username, "always_same").json()["token"]
|
token = login(username, "always_same").json()["token"]
|
||||||
|
|
||||||
# Get weekly reports for the user in the project
|
# Get weekly reports for the user in the project
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
getWeeklyReportsUserPath + "/" + projectName,
|
getAllWeeklyReportsPath + "/" + projectName,
|
||||||
headers={"Authorization": "Bearer " + token},
|
headers={"Authorization": "Bearer " + token},
|
||||||
|
params={"targetUser": username},
|
||||||
)
|
)
|
||||||
|
|
||||||
dprint(response.text)
|
dprint(response.text)
|
||||||
|
@ -333,7 +233,6 @@ def test_get_weekly_reports_user():
|
||||||
gprint("test_get_weekly_reports_user successful")
|
gprint("test_get_weekly_reports_user successful")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Test function to check if a user is a project manager
|
# Test function to check if a user is a project manager
|
||||||
def test_check_if_project_manager():
|
def test_check_if_project_manager():
|
||||||
# Log in as the user
|
# Log in as the user
|
||||||
|
@ -349,6 +248,7 @@ def test_check_if_project_manager():
|
||||||
assert response.status_code == 200, "Check if project manager failed"
|
assert response.status_code == 200, "Check if project manager failed"
|
||||||
gprint("test_check_if_project_manager successful")
|
gprint("test_check_if_project_manager successful")
|
||||||
|
|
||||||
|
|
||||||
def test_ensure_manager_of_created_project():
|
def test_ensure_manager_of_created_project():
|
||||||
# Create a new user to add to the project
|
# Create a new user to add to the project
|
||||||
newUser = "karen_" + randomString()
|
newUser = "karen_" + randomString()
|
||||||
|
@ -372,6 +272,7 @@ def test_ensure_manager_of_created_project():
|
||||||
assert response.json()["isProjectManager"] == True, "User is not project manager"
|
assert response.json()["isProjectManager"] == True, "User is not project manager"
|
||||||
gprint("test_ensure_admin_of_created_project successful")
|
gprint("test_ensure_admin_of_created_project successful")
|
||||||
|
|
||||||
|
|
||||||
def test_change_user_name():
|
def test_change_user_name():
|
||||||
# Register a new user
|
# Register a new user
|
||||||
new_user = randomString()
|
new_user = randomString()
|
||||||
|
@ -409,6 +310,7 @@ def test_change_user_name():
|
||||||
assert response.status_code == 200, "Change user name failed"
|
assert response.status_code == 200, "Change user name failed"
|
||||||
gprint("test_change_user_name successful")
|
gprint("test_change_user_name successful")
|
||||||
|
|
||||||
|
|
||||||
def test_list_all_users_project():
|
def test_list_all_users_project():
|
||||||
# Log in as a user who is a member of the project
|
# Log in as a user who is a member of the project
|
||||||
admin_username = randomString()
|
admin_username = randomString()
|
||||||
|
@ -437,6 +339,7 @@ def test_list_all_users_project():
|
||||||
assert response.status_code == 200, "List all users project failed"
|
assert response.status_code == 200, "List all users project failed"
|
||||||
gprint("test_list_all_users_project sucessful")
|
gprint("test_list_all_users_project sucessful")
|
||||||
|
|
||||||
|
|
||||||
def test_update_weekly_report():
|
def test_update_weekly_report():
|
||||||
# Log in as the user
|
# Log in as the user
|
||||||
token = login(username, "always_same").json()["token"]
|
token = login(username, "always_same").json()["token"]
|
||||||
|
@ -502,6 +405,7 @@ def test_remove_project():
|
||||||
assert response.status_code == 200, "Remove project failed"
|
assert response.status_code == 200, "Remove project failed"
|
||||||
gprint("test_remove_project successful")
|
gprint("test_remove_project successful")
|
||||||
|
|
||||||
|
|
||||||
def test_get_unsigned_reports():
|
def test_get_unsigned_reports():
|
||||||
# Log in as the user
|
# Log in as the user
|
||||||
token = login("user2", "123").json()["token"]
|
token = login("user2", "123").json()["token"]
|
||||||
|
@ -515,7 +419,85 @@ def test_get_unsigned_reports():
|
||||||
gprint("test_get_unsigned_reports successful")
|
gprint("test_get_unsigned_reports successful")
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_other_users_report_as_pm():
|
||||||
|
# Create user
|
||||||
|
user = randomString()
|
||||||
|
register(user, "password")
|
||||||
|
|
||||||
|
# Create project
|
||||||
|
project = randomString()
|
||||||
|
pm_token = login(user, "password").json()["token"]
|
||||||
|
response = requests.post(
|
||||||
|
addProjectPath,
|
||||||
|
json={"name": project, "description": "This is a project"},
|
||||||
|
headers={"Authorization": "Bearer " + pm_token},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200, "Add project failed"
|
||||||
|
|
||||||
|
# Create other user
|
||||||
|
other_user = randomString()
|
||||||
|
register(other_user, "password")
|
||||||
|
user_token = login(other_user, "password").json()["token"]
|
||||||
|
|
||||||
|
# Add other user to project
|
||||||
|
response = requests.put(
|
||||||
|
addUserToProjectPath + "/" + project,
|
||||||
|
headers={"Authorization": "Bearer " + pm_token}, # note pm_token
|
||||||
|
params={"userName": other_user},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200, "Add user to project failed"
|
||||||
|
|
||||||
|
# Submit report as other user
|
||||||
|
response = requests.post(
|
||||||
|
submitReportPath,
|
||||||
|
json={
|
||||||
|
"projectName": project,
|
||||||
|
"week": 1,
|
||||||
|
"developmentTime": 10,
|
||||||
|
"meetingTime": 5,
|
||||||
|
"adminTime": 5,
|
||||||
|
"ownWorkTime": 10,
|
||||||
|
"studyTime": 10,
|
||||||
|
"testingTime": 10,
|
||||||
|
},
|
||||||
|
headers={"Authorization": "Bearer " + user_token},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200, "Submit report failed"
|
||||||
|
|
||||||
|
# Get report as project manager
|
||||||
|
response = requests.get(
|
||||||
|
getWeeklyReportPath,
|
||||||
|
headers={"Authorization": "Bearer " + pm_token},
|
||||||
|
params={"targetUser": other_user, "projectName": project, "week": 1},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200, "Get weekly report failed"
|
||||||
|
|
||||||
|
|
||||||
|
def test_promote_to_manager():
|
||||||
|
# User to create
|
||||||
|
pm_user = "user" + randomString()
|
||||||
|
pm_passwd = "password"
|
||||||
|
|
||||||
|
# User to promote
|
||||||
|
member_user = "member" + randomString()
|
||||||
|
member_passwd = "password"
|
||||||
|
|
||||||
|
# Name of the project to be created
|
||||||
|
project_name = "project" + randomString()
|
||||||
|
|
||||||
|
pm_token = register_and_login(pm_user, pm_passwd)
|
||||||
|
member_token = register_and_login(member_user, member_passwd)
|
||||||
|
|
||||||
|
response = create_project(pm_token, project_name)
|
||||||
|
assert response.status_code == 200, "Create project failed"
|
||||||
|
|
||||||
|
# Promote the user to project manager
|
||||||
|
response = promoteToManager(pm_token, member_user, project_name)
|
||||||
|
assert response.status_code == 200, "Promote to manager failed"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
test_promote_to_manager()
|
||||||
test_remove_project()
|
test_remove_project()
|
||||||
test_get_user_projects()
|
test_get_user_projects()
|
||||||
test_create_user()
|
test_create_user()
|
||||||
|
@ -526,7 +508,7 @@ if __name__ == "__main__":
|
||||||
test_get_project()
|
test_get_project()
|
||||||
test_sign_report()
|
test_sign_report()
|
||||||
test_add_user_to_project()
|
test_add_user_to_project()
|
||||||
test_get_weekly_reports_user()
|
test_get_all_weekly_reports()
|
||||||
test_check_if_project_manager()
|
test_check_if_project_manager()
|
||||||
test_ProjectRoleChange()
|
test_ProjectRoleChange()
|
||||||
test_ensure_manager_of_created_project()
|
test_ensure_manager_of_created_project()
|
||||||
|
@ -534,4 +516,4 @@ if __name__ == "__main__":
|
||||||
test_list_all_users_project()
|
test_list_all_users_project()
|
||||||
test_change_user_name()
|
test_change_user_name()
|
||||||
test_update_weekly_report()
|
test_update_weekly_report()
|
||||||
|
test_get_other_users_report_as_pm()
|
Loading…
Reference in a new issue