Merge branch 'dev' into gruppDM
This commit is contained in:
commit
1fd167d412
2 changed files with 13 additions and 5 deletions
|
@ -16,6 +16,7 @@ func GetStatistics(c *fiber.Ctx) error {
|
||||||
|
|
||||||
// Extract project name from query parameters
|
// Extract project name from query parameters
|
||||||
projectName := c.Query("projectName")
|
projectName := c.Query("projectName")
|
||||||
|
userNameParam := c.Query("userName")
|
||||||
|
|
||||||
log.Info(username, " trying to get statistics for project: ", projectName)
|
log.Info(username, " trying to get statistics for project: ", projectName)
|
||||||
|
|
||||||
|
@ -24,18 +25,24 @@ func GetStatistics(c *fiber.Ctx) error {
|
||||||
return c.Status(400).SendString("Missing project name")
|
return c.Status(400).SendString("Missing project name")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user is not a project manager, they can't view statistics
|
// Check if the user is a project manager
|
||||||
pm, err := db.GetDb(c).IsProjectManager(username, projectName)
|
pm, err := db.GetDb(c).IsProjectManager(username, projectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Error checking if user is project manager:", 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 !pm {
|
if userNameParam == "" {
|
||||||
log.Info("Unauthorized access")
|
userNameParam = username
|
||||||
|
}
|
||||||
|
|
||||||
|
if !pm || userNameParam != username {
|
||||||
|
log.Info("Unauthorized access for user:", username, "trying to access project:", projectName, "statistics for user:", userNameParam)
|
||||||
return c.Status(403).SendString("Unauthorized access")
|
return c.Status(403).SendString("Unauthorized access")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
username = userNameParam
|
||||||
|
|
||||||
// Retrieve statistics for the project from the database
|
// Retrieve statistics for the project from the database
|
||||||
statistics, err := db.GetDb(c).ReportStatistics(username, projectName)
|
statistics, err := db.GetDb(c).ReportStatistics(username, projectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -269,6 +269,7 @@ interface API {
|
||||||
getStatistics(
|
getStatistics(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
token: string,
|
||||||
|
userName?: string,
|
||||||
): Promise<APIResponse<Statistics>>;
|
): Promise<APIResponse<Statistics>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -980,11 +981,11 @@ export const api: API = {
|
||||||
},
|
},
|
||||||
async getStatistics(
|
async getStatistics(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
userName?: string,
|
||||||
): Promise<APIResponse<Statistics>> {
|
): Promise<APIResponse<Statistics>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/getStatistics/?projectName=${projectName}`,
|
`/api/getStatistics/?projectName=${projectName}?userName=${userName ?? ""}`,
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
Loading…
Reference in a new issue