Compare commits
No commits in common. "fe6942aa8145d08304f28a920ac8f5b998001aef" and "0c2617d0cb9dd03a73005bb6347d16ac7fd3ddc1" have entirely different histories.
fe6942aa81
...
0c2617d0cb
9 changed files with 20 additions and 257 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -36,7 +36,6 @@ dist/
|
||||||
.vscode/
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.go.work.sum
|
|
||||||
|
|
||||||
# Ignore configuration files
|
# Ignore configuration files
|
||||||
.env
|
.env
|
||||||
|
|
|
@ -32,7 +32,6 @@ type Database interface {
|
||||||
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)
|
||||||
SignWeeklyReport(reportId int, projectManagerId int) error
|
SignWeeklyReport(reportId int, projectManagerId int) error
|
||||||
IsSiteAdmin(username string) (bool, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This struct is a wrapper type that holds the database connection
|
// This struct is a wrapper type that holds the database connection
|
||||||
|
@ -317,26 +316,6 @@ func (d *Db) SignWeeklyReport(reportId int, projectManagerId int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSiteAdmin checks if a given username is a site admin
|
|
||||||
func (d *Db) IsSiteAdmin(username string) (bool, error) {
|
|
||||||
// Define the SQL query to check if the user is a site admin
|
|
||||||
query := `
|
|
||||||
SELECT COUNT(*) FROM site_admin
|
|
||||||
JOIN users ON site_admin.admin_id = users.id
|
|
||||||
WHERE users.username = ?
|
|
||||||
`
|
|
||||||
|
|
||||||
// Execute the query
|
|
||||||
var count int
|
|
||||||
err := d.Get(&count, query, username)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If count is greater than 0, the user is a site admin
|
|
||||||
return count > 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reads a directory of migration files and applies them to the database.
|
// Reads a directory of migration files and applies them to the database.
|
||||||
// This will eventually be used on an embedded directory
|
// This will eventually be used on an embedded directory
|
||||||
func (d *Db) Migrate() error {
|
func (d *Db) Migrate() error {
|
||||||
|
|
|
@ -18,8 +18,6 @@ type GlobalState interface {
|
||||||
GetWeeklyReport(c *fiber.Ctx) error
|
GetWeeklyReport(c *fiber.Ctx) error
|
||||||
SignReport(c *fiber.Ctx) error
|
SignReport(c *fiber.Ctx) error
|
||||||
GetProject(c *fiber.Ctx) error
|
GetProject(c *fiber.Ctx) error
|
||||||
AddUserToProjectHandler(c *fiber.Ctx) error
|
|
||||||
PromoteToAdmin(c *fiber.Ctx) error
|
|
||||||
// GetProject(c *fiber.Ctx) error // To get a specific project
|
// GetProject(c *fiber.Ctx) error // To get a specific project
|
||||||
// UpdateProject(c *fiber.Ctx) error // To update a project
|
// UpdateProject(c *fiber.Ctx) error // To update a project
|
||||||
// DeleteProject(c *fiber.Ctx) error // To delete a project
|
// DeleteProject(c *fiber.Ctx) error // To delete a project
|
||||||
|
|
|
@ -101,45 +101,3 @@ func (gs *GState) ListAllUsersProject(c *fiber.Ctx) error {
|
||||||
// Return the list of users as JSON
|
// Return the list of users as JSON
|
||||||
return c.JSON(users)
|
return c.JSON(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserToProjectHandler is a handler that adds a user to a project with a specified role
|
|
||||||
func (gs *GState) 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 {
|
|
||||||
println("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)
|
|
||||||
claims := user.Claims.(jwt.MapClaims)
|
|
||||||
adminUsername := claims["name"].(string)
|
|
||||||
println("Admin username from claims:", adminUsername)
|
|
||||||
|
|
||||||
isAdmin, err := gs.Db.IsSiteAdmin(adminUsername)
|
|
||||||
if err != nil {
|
|
||||||
println("Error checking admin status:", err)
|
|
||||||
return c.Status(500).SendString(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isAdmin {
|
|
||||||
println("User is not a site admin:", adminUsername)
|
|
||||||
return c.Status(403).SendString("User is not a site admin")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the user to the project with the specified role
|
|
||||||
err = gs.Db.AddUserToProject(requestData.Username, requestData.ProjectName, requestData.Role)
|
|
||||||
if err != nil {
|
|
||||||
println("Error adding user to project:", err)
|
|
||||||
return c.Status(500).SendString(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return success message
|
|
||||||
println("User added to project successfully:", requestData.Username)
|
|
||||||
return c.SendStatus(fiber.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
|
@ -64,42 +64,30 @@ func (gs *GState) GetWeeklyReport(c *fiber.Ctx) error {
|
||||||
return c.JSON(report)
|
return c.JSON(report)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReportId struct {
|
|
||||||
ReportId int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gs *GState) SignReport(c *fiber.Ctx) error {
|
func (gs *GState) SignReport(c *fiber.Ctx) error {
|
||||||
println("Signing report...")
|
|
||||||
// Extract the necessary parameters from the token
|
// Extract the necessary parameters from the token
|
||||||
user := c.Locals("user").(*jwt.Token)
|
user := c.Locals("user").(*jwt.Token)
|
||||||
claims := user.Claims.(jwt.MapClaims)
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
projectManagerUsername := claims["name"].(string)
|
managerUsername := claims["name"].(string)
|
||||||
|
|
||||||
// Extract report ID from the request query parameters
|
// Extract the report ID and project manager ID from request parameters
|
||||||
// reportID := c.Query("reportId")
|
reportID, err := strconv.Atoi(c.Params("reportId"))
|
||||||
rid := new(ReportId)
|
if err != nil {
|
||||||
if err := c.BodyParser(rid); err != nil {
|
return c.Status(400).SendString("Invalid report ID")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
println("Signing report for: ", rid.ReportId)
|
|
||||||
// reportIDInt, err := strconv.Atoi(rid.ReportId)
|
|
||||||
// println("Signing report for: ", rid.ReportId)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.Status(400).SendString("Invalid report ID")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Get the project manager's ID
|
// Call the database function to get the project manager ID
|
||||||
projectManagerID, err := gs.Db.GetUserId(projectManagerUsername)
|
managerID, err := gs.Db.GetUserId(managerUsername)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(500).SendString("Failed to get project manager ID")
|
return c.Status(500).SendString("Failed to get project manager ID")
|
||||||
}
|
}
|
||||||
println("blabla", projectManagerID)
|
|
||||||
|
|
||||||
// Call the database function to sign the weekly report
|
// Call the database function to sign the weekly report
|
||||||
err = gs.Db.SignWeeklyReport(rid.ReportId, projectManagerID)
|
err = gs.Db.SignWeeklyReport(reportID, managerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(500).SendString(err.Error())
|
return c.Status(500).SendString("Failed to sign the weekly report: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return success response
|
||||||
return c.Status(200).SendString("Weekly report signed successfully")
|
return c.Status(200).SendString("Weekly report signed successfully")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
"ttime/internal/types"
|
"ttime/internal/types"
|
||||||
|
|
||||||
|
@ -123,25 +122,3 @@ func (gs *GState) ListAllUsers(c *fiber.Ctx) error {
|
||||||
// Return the list of users as JSON
|
// Return the list of users as JSON
|
||||||
return c.JSON(users)
|
return c.JSON(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gs *GState) PromoteToAdmin(c *fiber.Ctx) error {
|
|
||||||
// Extract the username from the request body
|
|
||||||
var newUser types.NewUser
|
|
||||||
if err := c.BodyParser(&newUser); err != nil {
|
|
||||||
return c.Status(400).SendString("Bad request")
|
|
||||||
}
|
|
||||||
username := newUser.Username
|
|
||||||
|
|
||||||
println("Promoting user to admin:", username) // Debug print
|
|
||||||
|
|
||||||
// Promote the user to a site admin in the database
|
|
||||||
if err := gs.Db.PromoteToAdmin(username); err != nil {
|
|
||||||
fmt.Println("Error promoting user to admin:", err) // Debug print
|
|
||||||
return c.Status(500).SendString(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
println("User promoted to admin successfully:", username) // Debug print
|
|
||||||
|
|
||||||
// Return a success message
|
|
||||||
return c.SendStatus(fiber.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
|
@ -80,9 +80,6 @@ func main() {
|
||||||
server.Post("/api/project", gs.CreateProject)
|
server.Post("/api/project", gs.CreateProject)
|
||||||
server.Get("/api/project/:projectId", gs.GetProject)
|
server.Get("/api/project/:projectId", gs.GetProject)
|
||||||
server.Get("/api/getWeeklyReport", gs.GetWeeklyReport)
|
server.Get("/api/getWeeklyReport", gs.GetWeeklyReport)
|
||||||
server.Post("/api/signReport", gs.SignReport)
|
|
||||||
server.Put("/api/addUserToProject", gs.AddUserToProjectHandler)
|
|
||||||
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
|
||||||
|
|
||||||
// Announce the port we are listening on and start the server
|
// Announce the port we are listening on and start the server
|
||||||
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
||||||
|
|
23
go.work.sum
23
go.work.sum
|
@ -1,28 +1,15 @@
|
||||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
|
||||||
github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
|
||||||
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
||||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
|
||||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||||
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
|
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||||
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
|
||||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||||
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
|
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
|
||||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
|
||||||
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
|
||||||
modernc.org/cc/v3 v3.41.0/go.mod h1:Ni4zjJYJ04CDOhG7dn640WGfwBzfE0ecX8TyMB0Fv0Y=
|
|
||||||
modernc.org/ccgo/v3 v3.16.15/go.mod h1:yT7B+/E2m43tmMOT51GMoM98/MtHIcQQSleGnddkUNI=
|
|
||||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
|
||||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
|
||||||
|
|
128
testing.py
128
testing.py
|
@ -22,13 +22,7 @@ loginPath = base_url + "/api/login"
|
||||||
addProjectPath = base_url + "/api/project"
|
addProjectPath = base_url + "/api/project"
|
||||||
submitReportPath = base_url + "/api/submitReport"
|
submitReportPath = base_url + "/api/submitReport"
|
||||||
getWeeklyReportPath = base_url + "/api/getWeeklyReport"
|
getWeeklyReportPath = base_url + "/api/getWeeklyReport"
|
||||||
<<<<<<< HEAD
|
|
||||||
getProjectPath = base_url + "/api/project"
|
getProjectPath = base_url + "/api/project"
|
||||||
=======
|
|
||||||
signReportPath = base_url + "/api/signReport"
|
|
||||||
addUserToProjectPath = base_url + "/api/addUserToProject"
|
|
||||||
promoteToAdminPath = base_url + "/api/promoteToAdmin"
|
|
||||||
>>>>>>> 9ad89d60636ac6091d71b0bf307982becc9b89fe
|
|
||||||
|
|
||||||
|
|
||||||
# Posts the username and password to the register endpoint
|
# Posts the username and password to the register endpoint
|
||||||
|
@ -50,20 +44,20 @@ def login(username: string, password: string):
|
||||||
print(response.text)
|
print(response.text)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# Test function to login
|
|
||||||
def test_login():
|
def test_login():
|
||||||
response = login(username, "always_same")
|
response = login(username, "always_same")
|
||||||
assert response.status_code == 200, "Login failed"
|
assert response.status_code == 200, "Login failed"
|
||||||
print("Login successful")
|
print("Login successful")
|
||||||
return response.json()["token"]
|
return response.json()["token"]
|
||||||
|
|
||||||
# Test function to create a new user
|
|
||||||
def test_create_user():
|
def test_create_user():
|
||||||
response = register(username, "always_same")
|
response = register(username, "always_same")
|
||||||
assert response.status_code == 200, "Registration failed"
|
assert response.status_code == 200, "Registration failed"
|
||||||
print("Registration successful")
|
print("Registration successful")
|
||||||
|
|
||||||
# Test function to add a project
|
|
||||||
def test_add_project():
|
def test_add_project():
|
||||||
loginResponse = login(username, "always_same")
|
loginResponse = login(username, "always_same")
|
||||||
token = loginResponse.json()["token"]
|
token = loginResponse.json()["token"]
|
||||||
|
@ -76,7 +70,7 @@ def test_add_project():
|
||||||
assert response.status_code == 200, "Add project failed"
|
assert response.status_code == 200, "Add project failed"
|
||||||
print("Add project successful")
|
print("Add project successful")
|
||||||
|
|
||||||
# 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"]
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
|
@ -97,7 +91,6 @@ def test_submit_report():
|
||||||
assert response.status_code == 200, "Submit report failed"
|
assert response.status_code == 200, "Submit report failed"
|
||||||
print("Submit report successful")
|
print("Submit report successful")
|
||||||
|
|
||||||
# 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"]
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
|
@ -118,123 +111,10 @@ def test_get_project():
|
||||||
print(response.text)
|
print(response.text)
|
||||||
assert response.status_code == 200, "Get project failed"
|
assert response.status_code == 200, "Get project failed"
|
||||||
|
|
||||||
# Test function to add a user to a project
|
|
||||||
def test_add_user_to_project():
|
|
||||||
# Log in as a site admin
|
|
||||||
admin_username = randomString()
|
|
||||||
admin_password = "admin_password"
|
|
||||||
print("Registering with username: ", admin_username, " and password: ", admin_password)
|
|
||||||
response = requests.post(
|
|
||||||
registerPath, json={"username": admin_username, "password": admin_password}
|
|
||||||
)
|
|
||||||
print(response.text)
|
|
||||||
|
|
||||||
admin_token = login(admin_username, admin_password).json()["token"]
|
|
||||||
response = requests.post(promoteToAdminPath, json={"username": admin_username}, headers={"Authorization": "Bearer " + admin_token})
|
|
||||||
print(response.text)
|
|
||||||
assert response.status_code == 200, "Promote to site admin failed"
|
|
||||||
print("Admin promoted to site admin successfully")
|
|
||||||
|
|
||||||
# Create a new user to add to the project
|
|
||||||
new_user = randomString()
|
|
||||||
register(new_user, "new_user_password")
|
|
||||||
|
|
||||||
# Add the new user to the project as a member
|
|
||||||
response = requests.put(
|
|
||||||
addUserToProjectPath,
|
|
||||||
json={"projectName": projectName, "username": new_user, "role": "member"},
|
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
|
||||||
)
|
|
||||||
|
|
||||||
print(response.text)
|
|
||||||
assert response.status_code == 200, "Add user to project failed"
|
|
||||||
print("Add user to project successful")
|
|
||||||
|
|
||||||
# Test function to sign a report
|
|
||||||
def test_sign_report():
|
|
||||||
# Create a project manager user
|
|
||||||
project_manager = randomString()
|
|
||||||
register(project_manager, "project_manager_password")
|
|
||||||
|
|
||||||
# Register an admin
|
|
||||||
admin_username = randomString()
|
|
||||||
admin_password = "admin_password2"
|
|
||||||
print("Registering with username: ", admin_username, " and password: ", admin_password)
|
|
||||||
response = requests.post(
|
|
||||||
registerPath, json={"username": admin_username, "password": admin_password}
|
|
||||||
)
|
|
||||||
print(response.text)
|
|
||||||
|
|
||||||
# Log in as the admin
|
|
||||||
admin_token = login(admin_username, admin_password).json()["token"]
|
|
||||||
response = requests.post(promoteToAdminPath, json={"username": admin_username}, headers={"Authorization": "Bearer " + admin_token})
|
|
||||||
|
|
||||||
response = requests.put(
|
|
||||||
addUserToProjectPath,
|
|
||||||
json={"projectName": projectName, "username": project_manager, "role": "project_manager"},
|
|
||||||
headers={"Authorization": "Bearer " + admin_token},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200, "Add project manager to project failed"
|
|
||||||
print("Project manager added to project successfully")
|
|
||||||
|
|
||||||
# Log in as the project manager
|
|
||||||
project_manager_token = login(project_manager, "project_manager_password").json()["token"]
|
|
||||||
|
|
||||||
# Submit a report for the project
|
|
||||||
token = login(username, "always_same").json()["token"]
|
|
||||||
response = requests.post(
|
|
||||||
submitReportPath,
|
|
||||||
json={
|
|
||||||
"projectName": projectName,
|
|
||||||
"week": 1,
|
|
||||||
"developmentTime": 10,
|
|
||||||
"meetingTime": 5,
|
|
||||||
"adminTime": 5,
|
|
||||||
"ownWorkTime": 10,
|
|
||||||
"studyTime": 10,
|
|
||||||
"testingTime": 10,
|
|
||||||
},
|
|
||||||
headers={"Authorization": "Bearer " + token},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200, "Submit report failed"
|
|
||||||
print("Submit report successful")
|
|
||||||
|
|
||||||
# Retrieve the report ID
|
|
||||||
response = requests.get(
|
|
||||||
getWeeklyReportPath,
|
|
||||||
headers={"Authorization": "Bearer " + token},
|
|
||||||
params={"username": username, "projectName": projectName , "week": 1}
|
|
||||||
)
|
|
||||||
print(response.text)
|
|
||||||
report_id = response.json()["reportId"]
|
|
||||||
|
|
||||||
# Sign the report as the project manager
|
|
||||||
response = requests.post(
|
|
||||||
signReportPath,
|
|
||||||
json={"reportId": report_id},
|
|
||||||
headers={"Authorization": "Bearer " + project_manager_token},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200, "Sign report failed"
|
|
||||||
print("Sign report successful")
|
|
||||||
|
|
||||||
# Retrieve the report ID again for confirmation
|
|
||||||
response = requests.get(
|
|
||||||
getWeeklyReportPath,
|
|
||||||
headers={"Authorization": "Bearer " + token},
|
|
||||||
params={"username": username, "projectName": projectName , "week": 1}
|
|
||||||
)
|
|
||||||
print(response.text)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_create_user()
|
test_create_user()
|
||||||
test_login()
|
test_login()
|
||||||
test_add_project()
|
test_add_project()
|
||||||
test_submit_report()
|
test_submit_report()
|
||||||
test_get_weekly_report()
|
test_get_weekly_report()
|
||||||
<<<<<<< HEAD
|
|
||||||
test_get_project()
|
test_get_project()
|
||||||
=======
|
|
||||||
test_sign_report()
|
|
||||||
test_add_user_to_project()
|
|
||||||
>>>>>>> 9ad89d60636ac6091d71b0bf307982becc9b89fe
|
|
||||||
|
|
Loading…
Reference in a new issue