Changeset 0.25.4 (#164)
This commit is contained in:
@@ -449,16 +449,20 @@ func (h *ProjectHandler) loadAndAuthorize(c *gin.Context) (*models.Project, bool
|
||||
}
|
||||
|
||||
userID := getUserID(c)
|
||||
teamIDs, _ := h.stores.Teams.GetUserTeamIDs(c.Request.Context(), userID)
|
||||
|
||||
ok, err := h.stores.Projects.UserCanAccess(c.Request.Context(), userID, projectID, teamIDs)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "access check failed"})
|
||||
return nil, false
|
||||
}
|
||||
if !ok {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "project not found"})
|
||||
return nil, false
|
||||
// Admins can access all projects
|
||||
if c.GetString("role") != "admin" {
|
||||
teamIDs, _ := h.stores.Teams.GetUserTeamIDs(c.Request.Context(), userID)
|
||||
|
||||
ok, err := h.stores.Projects.UserCanAccess(c.Request.Context(), userID, projectID, teamIDs)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "access check failed"})
|
||||
return nil, false
|
||||
}
|
||||
if !ok {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "project not found"})
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
project, err := h.stores.Projects.GetByID(c.Request.Context(), projectID)
|
||||
|
||||
Reference in New Issue
Block a user