Merge branch 'dev' into gruppDM
This commit is contained in:
commit
1631c8b6b0
14 changed files with 1209 additions and 923 deletions
|
@ -47,7 +47,7 @@ itest:
|
|||
make build
|
||||
./bin/$(PROC_NAME) >/dev/null 2>&1 &
|
||||
sleep 1 # Adjust if needed
|
||||
python ../testing.py
|
||||
python ../testing/testing.py || pkill $(PROC_NAME)
|
||||
pkill $(PROC_NAME)
|
||||
|
||||
# Get dependencies target
|
||||
|
|
|
@ -13,10 +13,10 @@ require (
|
|||
require (
|
||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.20.3 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.5 // indirect
|
||||
github.com/go-openapi/spec v0.20.15 // indirect
|
||||
github.com/go-openapi/swag v0.22.10 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||
github.com/go-openapi/spec v0.21.0 // indirect
|
||||
github.com/go-openapi/swag v0.23.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
|
@ -25,10 +25,10 @@ require (
|
|||
github.com/swaggo/files/v2 v2.0.0 // indirect
|
||||
golang.org/x/tools v0.19.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
|
||||
modernc.org/libc v1.41.0 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // indirect
|
||||
modernc.org/libc v1.49.1 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.7.2 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
modernc.org/strutil v1.2.0 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
)
|
||||
|
@ -42,7 +42,7 @@ require (
|
|||
// These are all for fiber
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
github.com/gofiber/fiber/v2 v2.52.2
|
||||
github.com/gofiber/fiber/v2 v2.52.4
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.17.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
|
@ -52,5 +52,5 @@ require (
|
|||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.52.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
)
|
||||
|
|
|
@ -10,20 +10,20 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/go-openapi/jsonpointer v0.20.3 h1:jykzYWS/kyGtsHfRt6aV8JTB9pcQAXPIA7qlZ5aRlyk=
|
||||
github.com/go-openapi/jsonpointer v0.20.3/go.mod h1:c7l0rjoouAuIxCm8v/JWKRgMjDG/+/7UBWsXMrv6PsM=
|
||||
github.com/go-openapi/jsonreference v0.20.5 h1:hutI+cQI+HbSQaIGSfsBsYI0pHk+CATf8Fk5gCSj0yI=
|
||||
github.com/go-openapi/jsonreference v0.20.5/go.mod h1:thAqAp31UABtI+FQGKAQfmv7DbFpKNUlva2UPCxKu2Y=
|
||||
github.com/go-openapi/spec v0.20.15 h1:8bDcVxF607pTh9NpPwgsH4J5Uhh5mV5XoWnkurdiY+U=
|
||||
github.com/go-openapi/spec v0.20.15/go.mod h1:o0upgqg5uYFG7O5mADrDVmSG3Wa6y6OLhwiCqQ+sTv4=
|
||||
github.com/go-openapi/swag v0.22.10 h1:4y86NVn7Z2yYd6pfS4Z+Nyh3aAUL3Nul+LMbhFKy0gA=
|
||||
github.com/go-openapi/swag v0.22.10/go.mod h1:Cnn8BYtRlx6BNE3DPN86f/xkapGIcLWzh3CLEb4C1jI=
|
||||
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
||||
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
||||
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
||||
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
|
||||
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
|
||||
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
|
||||
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
|
||||
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/gofiber/contrib/jwt v1.0.8 h1:/GeOsm/Mr1OGr0GTy+RIVSz5VgNNyP3ZgK4wdqxF/WY=
|
||||
github.com/gofiber/contrib/jwt v1.0.8/go.mod h1:gWWBtBiLmKXRN7xy6a96QO0KGvPEyxdh8x496Ujtg84=
|
||||
github.com/gofiber/fiber/v2 v2.52.2 h1:b0rYH6b06Df+4NyrbdptQL8ifuxw/Tf2DgfkZkDaxEo=
|
||||
github.com/gofiber/fiber/v2 v2.52.2/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
|
||||
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||
github.com/gofiber/swagger v1.0.0 h1:BzUzDS9ZT6fDUa692kxmfOjc1DZiloLiPK/W5z1H1tc=
|
||||
github.com/gofiber/swagger v1.0.0/go.mod h1:QrYNF1Yrc7ggGK6ATsJ6yfH/8Zi5bu9lA7wB8TmCecg=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||
|
@ -85,8 +85,8 @@ golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
|
|||
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
|
||||
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
@ -94,16 +94,26 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
|
|||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/cc/v4 v4.20.0 h1:45Or8mQfbUqJOG9WaxvlFYOAQO0lQ5RvqBcFCXngjxk=
|
||||
modernc.org/cc/v4 v4.20.0/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
|
||||
modernc.org/ccgo/v4 v4.15.0 h1:uwfCZOkKhaNNotgYW7kxkJwrkQC1HfGitt/7ousudJE=
|
||||
modernc.org/ccgo/v4 v4.15.0/go.mod h1:XVITcYGiI+O97UNDLMsnZ9ZjJOhC+ACX+TfxpsWWyRc=
|
||||
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
|
||||
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/libc v1.41.0 h1:g9YAc6BkKlgORsUWj+JwqoB1wU3o4DE3bM3yvA3k+Gk=
|
||||
modernc.org/libc v1.41.0/go.mod h1:w0eszPsiXoOnoMJgrXjglgLuDy/bt5RR4y3QzUUeodY=
|
||||
modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw=
|
||||
modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU=
|
||||
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b h1:BnN1t+pb1cy61zbvSUV7SeI0PwosMhlAEi/vBY4qxp8=
|
||||
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/libc v1.49.1 h1:r4UaWllkYXRPA7Mq/KzmassZBvNJiH9egF4O/KV/gdE=
|
||||
modernc.org/libc v1.49.1/go.mod h1:Hx2rWfza47GSzCluTU7Vf0Qx3z9rWCVORL6RNgq+Xog=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
|
||||
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
|
||||
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
|
||||
modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU=
|
||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
|
||||
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
|
||||
modernc.org/sqlite v1.29.5 h1:8l/SQKAjDtZFo9lkJLdk8g9JEOeYRG4/ghStDCCTiTE=
|
||||
modernc.org/sqlite v1.29.5/go.mod h1:S02dvcmm7TnTRvGhv8IGYyLnIt7AS2KPaB1F/71p75U=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
|
|
|
@ -45,6 +45,7 @@ type Database interface {
|
|||
UpdateWeeklyReport(projectName string, userName string, week int, developmentTime int, meetingTime int, adminTime int, ownWorkTime int, studyTime int, testingTime int) error
|
||||
RemoveProject(projectname string) error
|
||||
GetUserName(id int) (string, error)
|
||||
UnsignWeeklyReport(reportId int, projectManagerId int) error
|
||||
}
|
||||
|
||||
// This struct is a wrapper type that holds the database connection
|
||||
|
@ -372,6 +373,36 @@ func (d *Db) SignWeeklyReport(reportId int, projectManagerId int) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (d *Db) UnsignWeeklyReport(reportId int, projectManagerId int) error {
|
||||
// Retrieve the project ID associated with the report
|
||||
var reportProjectID int
|
||||
err := d.Get(&reportProjectID, "SELECT project_id FROM weekly_reports WHERE report_id = ?", reportId)
|
||||
if err != nil {
|
||||
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
|
||||
var managerProjectID int
|
||||
err = d.Get(&managerProjectID, managerQuery, projectManagerId, reportId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if the project manager is in the same project as the report
|
||||
if reportProjectID != managerProjectID {
|
||||
return errors.New("project manager doesn't have permission to unsign the report")
|
||||
}
|
||||
|
||||
// Update the signed_by field of the specified report
|
||||
_, err = d.Exec("UPDATE weekly_reports SET signed_by = NULL WHERE report_id = ?;", projectManagerId, reportId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *Db) GetUnsignedWeeklyReports(projectName string) ([]types.WeeklyReport, error) {
|
||||
// Define the SQL query to fetch unsigned reports for a given user
|
||||
query := `
|
||||
|
|
|
@ -583,6 +583,94 @@ func TestSignWeeklyReport(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestUnsignWeeklyReport(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
// Add project manager
|
||||
err = db.AddUser("projectManager", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
// Add a regular user
|
||||
err = db.AddUser("testuser", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
// Add project
|
||||
err = db.AddProject("testproject", "description", "projectManager")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
|
||||
// Add both regular users as members to the project
|
||||
err = db.AddUserToProject("testuser", "testproject", "member")
|
||||
if err != nil {
|
||||
t.Error("AddUserToProject failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddUserToProject("projectManager", "testproject", "project_manager")
|
||||
if err != nil {
|
||||
t.Error("AddUserToProject failed:", err)
|
||||
}
|
||||
|
||||
// Add a weekly report for one of the regular users
|
||||
err = db.AddWeeklyReport("testproject", "testuser", 1, 1, 1, 1, 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Error("AddWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Retrieve the added report
|
||||
report, err := db.GetWeeklyReport("testuser", "testproject", 1)
|
||||
if err != nil {
|
||||
t.Error("GetWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Print project manager's ID
|
||||
projectManagerID, err := db.GetUserId("projectManager")
|
||||
if err != nil {
|
||||
t.Error("GetUserId failed:", err)
|
||||
}
|
||||
|
||||
// Sign the report with the project manager
|
||||
err = db.SignWeeklyReport(report.ReportId, projectManagerID)
|
||||
if err != nil {
|
||||
t.Error("SignWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Retrieve the report again to check if it's signed
|
||||
signedReport, err := db.GetWeeklyReport("testuser", "testproject", 1)
|
||||
if err != nil {
|
||||
t.Error("GetWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Ensure the report is signed by the project manager
|
||||
if *signedReport.SignedBy != projectManagerID {
|
||||
t.Errorf("Expected SignedBy to be %d, got %d", projectManagerID, *signedReport.SignedBy)
|
||||
}
|
||||
|
||||
// Unsign the report
|
||||
err = db.UnsignWeeklyReport(report.ReportId, projectManagerID)
|
||||
if err != nil {
|
||||
t.Error("UnsignWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Retrieve the report again to check if it's unsigned
|
||||
unsignedReport, err := db.GetWeeklyReport("testuser", "testproject", 1)
|
||||
if err != nil {
|
||||
t.Error("GetWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Ensure the report is unsigned
|
||||
if unsignedReport.SignedBy != nil {
|
||||
t.Error("Expected SignedBy to be nil, got", unsignedReport.SignedBy)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSignWeeklyReportByAnotherProjectManager tests the scenario where a project manager attempts to sign a weekly report for a user who is not assigned to their project
|
||||
func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) {
|
||||
db, err := setupState()
|
||||
|
|
|
@ -44,6 +44,10 @@ func PromoteToPm(c *fiber.Ctx) error {
|
|||
|
||||
// Add the user to the project with the specified role
|
||||
err = db.GetDb(c).ChangeUserRole(new_pm_name, project, "project_manager")
|
||||
if err != nil {
|
||||
log.Info("Error promoting user to project manager:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return success message
|
||||
log.Info("User : ", new_pm_name, " promoted to project manager in project: ", project)
|
||||
|
|
|
@ -38,7 +38,7 @@ func GetAllWeeklyReports(c *fiber.Ctx) error {
|
|||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
if pm == false && target_user != username {
|
||||
if !(pm || target_user == username) {
|
||||
log.Info("Unauthorized access")
|
||||
return c.Status(403).SendString("Unauthorized access")
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func GetWeeklyReport(c *fiber.Ctx) error {
|
|||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
if pm == false && target_user != username {
|
||||
if !(pm || target_user == username) {
|
||||
log.Info("Unauthorized access")
|
||||
return c.Status(403).SendString("Unauthorized access")
|
||||
}
|
||||
|
|
41
backend/internal/handlers/reports/UnsignReport.go
Normal file
41
backend/internal/handlers/reports/UnsignReport.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package reports
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func UnsignReport(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
projectManagerUsername := claims["name"].(string)
|
||||
|
||||
// Extract report ID from the path
|
||||
reportId, err := strconv.Atoi(c.Params("reportId"))
|
||||
if err != nil {
|
||||
log.Info("Invalid report ID")
|
||||
return c.Status(400).SendString("Invalid report ID")
|
||||
}
|
||||
|
||||
// Get the project manager's ID
|
||||
projectManagerID, err := db.GetDb(c).GetUserId(projectManagerUsername)
|
||||
if err != nil {
|
||||
log.Info("Failed to get project manager ID for user: ", projectManagerUsername)
|
||||
return c.Status(500).SendString("Failed to get project manager ID")
|
||||
}
|
||||
|
||||
// Call the database function to sign the weekly report
|
||||
err = db.GetDb(c).UnsignWeeklyReport(reportId, projectManagerID)
|
||||
if err != nil {
|
||||
log.Info("Error Unsigning weekly report:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Project manager ID: ", projectManagerID, " signed report ID: ", reportId)
|
||||
return c.Status(200).SendString("Weekly report unsigned successfully")
|
||||
}
|
|
@ -126,6 +126,7 @@ func main() {
|
|||
api.Delete("/removeProject/:projectName", projects.RemoveProject)
|
||||
api.Delete("/project/:projectID", projects.DeleteProject)
|
||||
|
||||
|
||||
// All report related routes
|
||||
// reportGroup := api.Group("/report") // Not currently in use
|
||||
api.Get("/getWeeklyReport", reports.GetWeeklyReport)
|
||||
|
@ -134,6 +135,7 @@ func main() {
|
|||
api.Post("/submitWeeklyReport", reports.SubmitWeeklyReport)
|
||||
api.Put("/signReport/:reportId", reports.SignReport)
|
||||
api.Put("/updateWeeklyReport", reports.UpdateWeeklyReport)
|
||||
api.Put("/unsignReport/:reportId", reports.UnsignReport)
|
||||
|
||||
// Announce the port we are listening on and start the server
|
||||
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
||||
|
|
1792
frontend/package-lock.json
generated
1792
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -221,6 +221,15 @@ interface API {
|
|||
*/
|
||||
signReport(reportId: number, token: string): Promise<APIResponse<string>>;
|
||||
|
||||
/**
|
||||
* Unsigns a report. Keep in mind that the user which the token belongs to must be
|
||||
* the project manager of the project the report belongs to.
|
||||
*
|
||||
* @param {number} reportId The id of the report to sign
|
||||
* @param {string} token The authentication token
|
||||
*/
|
||||
unsignReport(reportId: number, token: string): Promise<APIResponse<string>>;
|
||||
|
||||
/**
|
||||
* Promotes a user to project manager within a project.
|
||||
*
|
||||
|
@ -846,6 +855,29 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async unsignReport(
|
||||
reportId: number,
|
||||
token: string,
|
||||
): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch(`/api/unsignReport/${reportId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to unsign report" };
|
||||
} else {
|
||||
return { success: true, message: "Report unsigned" };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to unsign report" };
|
||||
}
|
||||
},
|
||||
|
||||
async promoteToPm(
|
||||
userName: string,
|
||||
projectName: string,
|
||||
|
|
|
@ -34,8 +34,9 @@ getChangeUserNamePath = base_url + "/api/changeUserName"
|
|||
getUpdateWeeklyReportPath = base_url + "/api/updateWeeklyReport"
|
||||
removeProjectPath = base_url + "/api/removeProject"
|
||||
promoteToPmPath = base_url + "/api/promoteToPm"
|
||||
unsignReportPath = base_url + "/api/unsignReport"
|
||||
|
||||
debug_output = True
|
||||
debug_output = False
|
||||
|
||||
|
||||
def gprint(*args, **kwargs):
|
||||
|
@ -149,3 +150,9 @@ def signReport(project_manager_token: string, report_id: int):
|
|||
signReportPath + "/" + str(report_id),
|
||||
headers={"Authorization": "Bearer " + project_manager_token},
|
||||
)
|
||||
|
||||
def unsignReport(project_manager_token: string, report_id: int):
|
||||
return requests.put(
|
||||
unsignReportPath + "/" + str(report_id),
|
||||
headers={"Authorization": "Bearer " + project_manager_token},
|
||||
)
|
||||
|
|
|
@ -215,6 +215,68 @@ def test_sign_report():
|
|||
assert report_id != None, "Get report failed"
|
||||
gprint("test_sign_report successful")
|
||||
|
||||
# Test function to unsign a report
|
||||
def test_unsign_report():
|
||||
# Pm user
|
||||
pm_username = "pm" + randomString()
|
||||
pm_password = "admin_password2"
|
||||
|
||||
# User to add
|
||||
member_user = "member" + randomString()
|
||||
member_passwd = "password"
|
||||
|
||||
# Name of the project to be created
|
||||
project_name = "project" + randomString()
|
||||
|
||||
# Register and get the tokens for both users
|
||||
pm_token = register_and_login(pm_username, pm_password)
|
||||
member_token = register_and_login(member_user, member_passwd)
|
||||
|
||||
# Create the project
|
||||
response = create_project(pm_token, project_name)
|
||||
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
|
||||
response = submitReport(
|
||||
member_token,
|
||||
{
|
||||
"projectName": project_name,
|
||||
"week": 1,
|
||||
"developmentTime": 10,
|
||||
"meetingTime": 5,
|
||||
"adminTime": 5,
|
||||
"ownWorkTime": 10,
|
||||
"studyTime": 10,
|
||||
"testingTime": 10,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200, "Submit report failed"
|
||||
|
||||
# Retrieve the report ID
|
||||
report_id = getReport(member_token, member_user, project_name)["reportId"]
|
||||
|
||||
# Sign the report as the project manager
|
||||
response = signReport(pm_token, report_id)
|
||||
assert response.status_code == 200, "Sign report failed"
|
||||
dprint("Sign report successful")
|
||||
|
||||
# Retrieve the report ID again for confirmation
|
||||
report_id = getReport(member_token, member_user, project_name)["reportId"]
|
||||
assert report_id != None, "Get report failed"
|
||||
|
||||
# Unsign the report as the project manager
|
||||
response = unsignReport(pm_token, report_id)
|
||||
assert response.status_code == 200, "Unsign report failed"
|
||||
dprint("Unsign report successful")
|
||||
|
||||
# Retrieve the report ID again for confirmation
|
||||
report_id = getReport(member_token, member_user, project_name)["reportId"]
|
||||
assert report_id != None, "Get report failed"
|
||||
gprint("test_unsign_report successful")
|
||||
|
||||
|
||||
# Test function to get weekly reports for a user in a project
|
||||
def test_get_all_weekly_reports():
|
||||
|
@ -497,6 +559,7 @@ def test_promote_to_manager():
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_unsign_report()
|
||||
test_promote_to_manager()
|
||||
test_remove_project()
|
||||
test_get_user_projects()
|
||||
|
|
Loading…
Reference in a new issue