Skip to content

Commit

Permalink
hotfix: fix test orga limit + fix cut_history regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrckd committed Apr 14, 2023
1 parent b83480d commit 2e80c67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions graph/dgraph_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ func DgraphQueryResolverRaw(ctx context.Context, db *db.Dgraph, data interface{}
queryType, typeName, queryName, err := queryTypeFromGraphqlContext(ctx)
if err != nil { return tools.LogErr("DgraphQueryResolver", err) }

// Return error if jwt token error (particurly when has expired)
// Return error if jwt token error (particularly when has expired)
if queryType == "add" || queryType == "update" || queryType == "delete" {
_, _, err := auth.GetUserContext(ctx)
if err != nil { return tools.LogErr("Access denied", err) }
}

// Remove some input
rawQuery := gc.RawQuery
variables := gc.Variables
// Remove some input
if ctx.Value("cut_history") != nil {
// Go along PushHistory...
// improve that hack with gqlgen #1144 issue
Expand Down
19 changes: 12 additions & 7 deletions graph/tension_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ func addTensionHook(ctx context.Context, obj interface{}, next graphql.Resolver)
// In order to notify user on the given event, we need to know their ids to pass and link them
// to the notification (UserEvent edge) function. To do so we first cut the history from the original
// input, and push then the history (see the PushHistory function).
ctx = context.WithValue(ctx, "cut_history", true)
ctx = context.WithValue(ctx, "cut_history", true) // Used by DgraphQueryResolverRaw
history := input.History
input.History = nil
// Execute query
data, err := next(ctx)
if err != nil { return data, err }
Expand All @@ -112,7 +114,7 @@ func addTensionHook(ctx context.Context, obj interface{}, next graphql.Resolver)
id := tension.ID

// Validate and process Blob Event
ok, _, err := TensionEventHook(uctx, id, input.History, nil)
ok, _, err := TensionEventHook(uctx, id, history, nil)
if !ok || err != nil {
// Delete the tension just added
e := db.GetDB().DeepDelete("tension", id)
Expand All @@ -122,7 +124,7 @@ func addTensionHook(ctx context.Context, obj interface{}, next graphql.Resolver)
return data, err
}
if ok {
PublishTensionEvent(model.EventNotif{Uctx: uctx, Tid: id, History: input.History})
PublishTensionEvent(model.EventNotif{Uctx: uctx, Tid: id, History: history})
return data, err
}
return nil, LogErr("Access denied", fmt.Errorf("Contact a coordinator to access this ressource."))
Expand Down Expand Up @@ -152,17 +154,20 @@ func updateTensionHook(ctx context.Context, obj interface{}, next graphql.Resolv
ok, contract, err = TensionEventHook(uctx, ids[0], input.Set.History, blob)
if err != nil { return nil, err }
if ok {
// History and notification Logics
// --
// History and notification Logics --
// In order to notify user on the given event, we need to know
// their ids to pass and link them to the user's notifications (UserEvent edge).
// To do so we first cut the history from the original input,
// and push then the history (see the [[PushHistory]] function).
ctx = context.WithValue(ctx, "cut_history", true)
ctx = context.WithValue(ctx, "cut_history", true) // Used by DgraphQueryResolverRaw
history := input.Set.History
now := Now()
input.Set.History = nil
input.Set.UpdatedAt = &now
// Execute query
data, err := next(ctx)
if err != nil { return data, err }
PublishTensionEvent(model.EventNotif{Uctx: uctx, Tid: ids[0], History: input.Set.History})
PublishTensionEvent(model.EventNotif{Uctx: uctx, Tid: ids[0], History: history})
return data, err
} else if contract != nil {
var t model.UpdateTensionPayload
Expand Down
7 changes: 3 additions & 4 deletions web/auth/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ func CanNewOrga(uctx model.UserCtx, form model.OrgaForm) (bool, error) {

switch uctx.Rights.Type {
case model.UserTypeRegular:
if n_orgs >= MAX_ORGA_REG {
return ok, fmt.Errorf("Number of organisation are limited to %d, please contact us to create more.", uctx.Rights.MaxPublicOrga)
if n_orgs >= MAX_ORGA_REG && MAX_ORGA_REG >= 0 {
return ok, fmt.Errorf("Number of organisation are limited to %d, please contact us to create more.", MAX_ORGA_REG)
} else if *form.Visibility == model.NodeVisibilityPublic &&
n_public >= uctx.Rights.MaxPublicOrga && uctx.Rights.MaxPublicOrga >= 0 {
return ok, fmt.Errorf("Number of public organisation are limited to %d, please contact us to create more.", uctx.Rights.MaxPublicOrga)
Expand All @@ -333,13 +333,12 @@ func CanNewOrga(uctx model.UserCtx, form model.OrgaForm) (bool, error) {

case model.UserTypePro:
if n_orgs >= MAX_ORGA_PRO && MAX_ORGA_PRO >= 0 {
return ok, fmt.Errorf("You own too many organisation, please contact us to create more.")
return ok, fmt.Errorf("Number of organisation are limited to %d, please contact us to create more.", MAX_ORGA_PRO)
}


case model.UserTypeRoot:
// pass

}

ok = true
Expand Down

0 comments on commit 2e80c67

Please sign in to comment.