diff --git a/graph/dgraph_resolver.go b/graph/dgraph_resolver.go index a3debd1..45ba42b 100644 --- a/graph/dgraph_resolver.go +++ b/graph/dgraph_resolver.go @@ -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 diff --git a/graph/tension_resolver.go b/graph/tension_resolver.go index d96af49..fe9aa22 100644 --- a/graph/tension_resolver.go +++ b/graph/tension_resolver.go @@ -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 } @@ -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) @@ -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.")) @@ -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 diff --git a/web/auth/validation.go b/web/auth/validation.go index 4597ac9..8e0420b 100644 --- a/web/auth/validation.go +++ b/web/auth/validation.go @@ -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) @@ -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