Skip to content

The only tool you need to know what is happening and how to fix it.

fix: cycles resolved, all compiles, moved dependencies around

dduxce5ffd54d6f4
diff --git a/backend/app/controllers/auth.controller.go b/backend/app/controllers/auth.controller.go
index 6785af31..e36a8c8a 100644
--- a/backend/app/controllers/auth.controller.go
+++ b/backend/app/controllers/auth.controller.go
@@ -3,6 +3,7 @@ package controllers
import (
"github.com/tracewayapp/traceway/backend/app/cache"
"github.com/tracewayapp/traceway/backend/app/config"
+ "github.com/tracewayapp/traceway/backend/app/db"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/repositories"
@@ -19,7 +20,7 @@ var PostRegistrationHooks []func(tx *sql.Tx, org *models.Organization, user *mod
type authController struct{}
func (a authController) HasOrganizations(c *gin.Context) {
- tx := middleware.GetTx(c)
+ tx := db.GetTx(c)
hasOrganizations, err := repositories.OrganizationRepository.HasOrganizations(tx)
if err != nil {
@@ -42,7 +43,7 @@ func (a authController) Login(c *gin.Context) {
return
}
- tx := middleware.GetTx(c)
+ tx := db.GetTx(c)
user, err := repositories.UserRepository.FindByEmail(tx, request.Email)
if err != nil {
@@ -104,7 +105,7 @@ func (a authController) Register(c *gin.Context) {
}
}
- tx := middleware.GetTx(c)
+ tx := db.GetTx(c)
// if we're not in the cloud mode only a single organization is allowed
if config.Config.CloudMode != "true" {
@@ -213,7 +214,7 @@ func (a authController) Register(c *gin.Context) {
}
func (a authController) LoginBundle(c *gin.Context) {
- tx := middleware.GetTx(c)
+ tx := db.GetTx(c)
userId := middleware.GetUserId(c)
if userId == 0 {
diff --git a/backend/app/controllers/invitation.controller.go b/backend/app/controllers/invitation.controller.go
index 88e9e0c4..6b99c34b 100644
--- a/backend/app/controllers/invitation.controller.go
+++ b/backend/app/controllers/invitation.controller.go
@@ -21,7 +21,7 @@ const maxMembersPerOrg = 10
const invitationExpiryDays = 7
func (c *invitationController) InviteUser(ctx *gin.Context) {
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
organizationId := middleware.GetOrganizationId(ctx)
userId := middleware.GetUserId(ctx)
@@ -109,7 +109,7 @@ func (c *invitationController) ListInvitations(ctx *gin.Context) {
}
func (c *invitationController) RevokeInvitation(ctx *gin.Context) {
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
organizationId := middleware.GetOrganizationId(ctx)
invitationId, err := strconv.Atoi(ctx.Param("id"))
@@ -213,7 +213,7 @@ func (c *invitationController) GetInvitationInfo(ctx *gin.Context) {
}
func (c *invitationController) AcceptInvitation(ctx *gin.Context) {
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
token := ctx.Param("token")
var request models.AcceptInvitationRequest
@@ -300,7 +300,7 @@ func (c *invitationController) AcceptInvitation(ctx *gin.Context) {
}
func (c *invitationController) AcceptExistingUser(ctx *gin.Context) {
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
token := ctx.Param("token")
userId := middleware.GetUserId(ctx)
userEmail := middleware.GetUserEmail(ctx)
diff --git a/backend/app/controllers/member.controller.go b/backend/app/controllers/member.controller.go
index 3c8201e9..e0de87f9 100644
--- a/backend/app/controllers/member.controller.go
+++ b/backend/app/controllers/member.controller.go
@@ -1,6 +1,7 @@
package controllers
import (
+ "github.com/tracewayapp/traceway/backend/app/db"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/repositories"
@@ -14,7 +15,7 @@ import (
type memberController struct{}
func (c *memberController) UpdateRole(ctx *gin.Context) {
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
organizationId := middleware.GetOrganizationId(ctx)
currentUserId := middleware.GetUserId(ctx)
currentUserRole := middleware.GetUserOrgRole(ctx)
@@ -66,7 +67,7 @@ func (c *memberController) UpdateRole(ctx *gin.Context) {
}
func (c *memberController) RemoveMember(ctx *gin.Context) {
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
organizationId := middleware.GetOrganizationId(ctx)
currentUserId := middleware.GetUserId(ctx)
diff --git a/backend/app/controllers/notification_channel.controller.go b/backend/app/controllers/notification_channel.controller.go
index a4321abc..38678686 100644
--- a/backend/app/controllers/notification_channel.controller.go
+++ b/backend/app/controllers/notification_channel.controller.go
@@ -26,7 +26,7 @@ func (ctrl *notificationChannelController) List(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
channels, err := repositories.NotificationChannelRepository.FindByProject(tx, projectId)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to list notification channels: %w", err))
@@ -89,7 +89,7 @@ func (ctrl *notificationChannelController) Create(ctx *gin.Context) {
createdBy = &userId
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
now := time.Now().UTC()
channel := &models.NotificationChannel{
ProjectId: projectId,
@@ -156,7 +156,7 @@ func (ctrl *notificationChannelController) Update(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.NotificationChannelRepository.FindById(tx, id)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to find notification channel: %w", err))
@@ -194,7 +194,7 @@ func (ctrl *notificationChannelController) Delete(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.NotificationChannelRepository.FindById(tx, id)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to delete notification channel: %w", err))
diff --git a/backend/app/controllers/notification_rule.controller.go b/backend/app/controllers/notification_rule.controller.go
index b2dadf5e..10ecef6c 100644
--- a/backend/app/controllers/notification_rule.controller.go
+++ b/backend/app/controllers/notification_rule.controller.go
@@ -8,6 +8,7 @@ import (
"time"
"github.com/gin-gonic/gin"
+ "github.com/tracewayapp/traceway/backend/app/db"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/repositories"
@@ -43,7 +44,7 @@ func (ctrl *notificationRuleController) List(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
rules, err := repositories.NotificationRuleRepository.FindByProjectWithChannel(tx, projectId)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to list notification rules: %w", err))
@@ -103,7 +104,7 @@ func (ctrl *notificationRuleController) Create(ctx *gin.Context) {
req.CooldownMinutes = 15
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
channel, err := repositories.NotificationChannelRepository.FindById(tx, req.ChannelId)
if err != nil {
@@ -188,7 +189,7 @@ func (ctrl *notificationRuleController) Update(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.NotificationRuleRepository.FindById(tx, id)
if err != nil {
@@ -245,7 +246,7 @@ func (ctrl *notificationRuleController) Delete(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.NotificationRuleRepository.FindById(tx, id)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to delete notification rule: %w", err))
@@ -278,7 +279,7 @@ func (ctrl *notificationRuleController) Toggle(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.NotificationRuleRepository.FindById(tx, id)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to find notification rule: %w", err))
@@ -323,7 +324,7 @@ func (ctrl *notificationRuleController) Snooze(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.NotificationRuleRepository.FindById(tx, id)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to find notification rule: %w", err))
diff --git a/backend/app/controllers/oauth.controller.go b/backend/app/controllers/oauth.controller.go
index 09fdebf4..e1af91cb 100644
--- a/backend/app/controllers/oauth.controller.go
+++ b/backend/app/controllers/oauth.controller.go
@@ -11,6 +11,7 @@ import (
"github.com/tracewayapp/traceway/backend/app/cache"
"github.com/tracewayapp/traceway/backend/app/config"
+ "github.com/tracewayapp/traceway/backend/app/db"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/repositories"
@@ -90,7 +91,7 @@ func (a oauthController) Callback(c *gin.Context) {
return
}
- tx := middleware.GetTx(c)
+ tx := db.GetTx(c)
var mappedRole string
if provider == "oidc" && services.OAuthService.OIDCRoleClaimEnabled() {
@@ -148,7 +149,7 @@ func (a oauthController) Callback(c *gin.Context) {
}
func (a oauthController) findOrCreateUser(c *gin.Context, provider string, gothUser goth.User) (*models.User, error) {
- tracewayTx := middleware.GetTx(c)
+ tracewayTx := db.GetTx(c)
user, err := repositories.UserRepository.FindByOAuth(tracewayTx, provider, gothUser.UserID)
if err != nil {
@@ -221,7 +222,7 @@ func (a oauthController) FinishSetup(c *gin.Context) {
return
}
- tx := middleware.GetTx(c)
+ tx := db.GetTx(c)
user, err := repositories.UserRepository.FindById(tx, userId)
if err != nil {
diff --git a/backend/app/controllers/organization.controller.go b/backend/app/controllers/organization.controller.go
index 07c3d598..caa729a6 100644
--- a/backend/app/controllers/organization.controller.go
+++ b/backend/app/controllers/organization.controller.go
@@ -87,7 +87,7 @@ type UpdateSettingsRequest struct {
func (c *organizationController) UpdateSettings(ctx *gin.Context) {
organizationId := middleware.GetOrganizationId(ctx)
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
var req UpdateSettingsRequest
if err := ctx.ShouldBindJSON(&req); err != nil {
diff --git a/backend/app/controllers/password_reset.controller.go b/backend/app/controllers/password_reset.controller.go
index 09f9a90c..31ac8177 100644
--- a/backend/app/controllers/password_reset.controller.go
+++ b/backend/app/controllers/password_reset.controller.go
@@ -1,9 +1,8 @@
package controllers
import (
- "github.com/tracewayapp/traceway/backend/app/middleware"
- "github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/db"
+ "github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/repositories"
"github.com/tracewayapp/traceway/backend/app/services"
"database/sql"
@@ -21,7 +20,7 @@ const resetTokenExpiry = 1 * time.Hour
const resetRateLimitPeriod = 1 * time.Hour
func (c *passwordResetController) ForgotPassword(ctx *gin.Context) {
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
var request models.ForgotPasswordRequest
if err := ctx.ShouldBindJSON(&request); err != nil {
@@ -88,7 +87,7 @@ func (c *passwordResetController) ValidateToken(ctx *gin.Context) {
}
func (c *passwordResetController) ResetPassword(ctx *gin.Context) {
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
token := ctx.Param("token")
var request models.ResetPasswordRequest
diff --git a/backend/app/controllers/widget.controller.go b/backend/app/controllers/widget.controller.go
index 0e810e79..74554086 100644
--- a/backend/app/controllers/widget.controller.go
+++ b/backend/app/controllers/widget.controller.go
@@ -8,6 +8,7 @@ import (
"strings"
"time"
+ "github.com/tracewayapp/traceway/backend/app/db"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/repositories"
@@ -58,7 +59,7 @@ func (c *widgetController) Add(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
group, err := repositories.WidgetGroupRepository.FindById(tx, groupId)
if err != nil {
@@ -135,7 +136,7 @@ func (c *widgetController) Update(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
group, err := repositories.WidgetGroupRepository.FindById(tx, groupId)
if err != nil {
@@ -203,7 +204,7 @@ func (c *widgetController) Move(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
group, err := repositories.WidgetGroupRepository.FindById(tx, groupId)
if err != nil {
@@ -284,7 +285,7 @@ func (c *widgetController) Delete(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
group, err := repositories.WidgetGroupRepository.FindById(tx, groupId)
if err != nil {
@@ -335,7 +336,7 @@ func (c *widgetController) ToggleStar(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
group, err := repositories.WidgetGroupRepository.FindById(tx, groupId)
if err != nil {
@@ -375,7 +376,7 @@ func (c *widgetController) ListStarred(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
widgets, err := repositories.WidgetGroupRepository.FindStarredWidgetsByProject(tx, projectId)
if err != nil {
diff --git a/backend/app/controllers/widget_group.controller.go b/backend/app/controllers/widget_group.controller.go
index 0051ff62..e1549f31 100644
--- a/backend/app/controllers/widget_group.controller.go
+++ b/backend/app/controllers/widget_group.controller.go
@@ -8,6 +8,7 @@ import (
"strings"
"time"
+ "github.com/tracewayapp/traceway/backend/app/db"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/repositories"
@@ -26,7 +27,7 @@ func (c *widgetGroupController) List(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
list, err := repositories.WidgetGroupRepository.FindByProject(tx, projectId)
if err != nil {
@@ -59,7 +60,7 @@ func (c *widgetGroupController) PopulateDefaults(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.WidgetGroupRepository.FindByProject(tx, projectId)
if err != nil {
@@ -113,7 +114,7 @@ func (c *widgetGroupController) Create(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.WidgetGroupRepository.FindByProject(tx, projectId)
if err != nil {
@@ -166,7 +167,7 @@ func (c *widgetGroupController) GetWithWidgets(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
group, err := repositories.WidgetGroupRepository.FindById(tx, id)
if err != nil {
@@ -225,7 +226,7 @@ func (c *widgetGroupController) Update(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.WidgetGroupRepository.FindById(tx, id)
if err != nil {
@@ -275,7 +276,7 @@ func (c *widgetGroupController) Delete(ctx *gin.Context) {
return
}
- tx := middleware.GetTx(ctx)
+ tx := db.GetTx(ctx)
existing, err := repositories.WidgetGroupRepository.FindById(tx, id)
if err != nil {
diff --git a/backend/app/db/db.go b/backend/app/db/db.go
index d333bdb7..71e3a249 100644
--- a/backend/app/db/db.go
+++ b/backend/app/db/db.go
@@ -63,6 +63,14 @@ func GetDB() *sql.DB {
return DB
}
+const TransactionContextKey = "dbTx"
+func GetTx(ctx context.Context) *sql.Tx {
+ if tx, ok := ctx.Value(TransactionContextKey).(*sql.Tx); ok {
+ return tx
+ }
+ return nil
+}
+
type ctxKey struct{}
func ContextWithTx(ctx context.Context, tx *sql.Tx) context.Context {
diff --git a/backend/app/middleware/transactional.middleware.go b/backend/app/middleware/transactional.middleware.go
index 7c7a923d..ec307c6d 100644
--- a/backend/app/middleware/transactional.middleware.go
+++ b/backend/app/middleware/transactional.middleware.go
@@ -1,16 +1,14 @@
package middleware
import (
- "github.com/tracewayapp/traceway/backend/app/db"
"context"
- "database/sql"
"net/http"
+ "github.com/tracewayapp/traceway/backend/app/db"
+
"github.com/gin-gonic/gin"
)
-const TransactionContextKey = "dbTx"
-
func Transactional(c *gin.Context) {
txHandle, err := db.DB.Begin()
@@ -27,9 +25,9 @@ func Transactional(c *gin.Context) {
}
}()
- c.Set(TransactionContextKey, txHandle)
+ c.Set(db.TransactionContextKey, txHandle)
- c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), TransactionContextKey, txHandle))
+ c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), db.TransactionContextKey, txHandle))
c.Next()
@@ -42,10 +40,3 @@ func Transactional(c *gin.Context) {
txHandle.Rollback()
}
}
-
-func GetTx(c *gin.Context) *sql.Tx {
- if id, exists := c.Get(TransactionContextKey); exists {
- return id.(*sql.Tx)
- }
- return nil
-}