diff --git a/system/rest.yaml b/system/rest.yaml index 57b0fc730..a07378760 100644 --- a/system/rest.yaml +++ b/system/rest.yaml @@ -209,15 +209,6 @@ endpoints: method: GET title: Current compose settings path: "/current" -- title: Subscription - path: "/subscription" - entrypoint: subscription - apis: - - name: current - method: GET - title: Returns current subscription status - path: "/" - parameters: {} - title: Roles description: An organisation may have many roles. Roles may have many channels available. Access to channels may be shared between roles. diff --git a/system/rest/handlers/subscription.go b/system/rest/handlers/subscription.go deleted file mode 100644 index 605aa1ce0..000000000 --- a/system/rest/handlers/subscription.go +++ /dev/null @@ -1,57 +0,0 @@ -package handlers - -// This file is auto-generated. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// Definitions file that controls how this file is generated: -// - -import ( - "context" - "github.com/cortezaproject/corteza-server/pkg/api" - "github.com/cortezaproject/corteza-server/system/rest/request" - "github.com/go-chi/chi" - "net/http" -) - -type ( - // Internal API interface - SubscriptionAPI interface { - Current(context.Context, *request.SubscriptionCurrent) (interface{}, error) - } - - // HTTP API interface - Subscription struct { - Current func(http.ResponseWriter, *http.Request) - } -) - -func NewSubscription(h SubscriptionAPI) *Subscription { - return &Subscription{ - Current: func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - params := request.NewSubscriptionCurrent() - if err := params.Fill(r); err != nil { - api.Send(w, r, err) - return - } - - value, err := h.Current(r.Context(), params) - if err != nil { - api.Send(w, r, err) - return - } - - api.Send(w, r, value) - }, - } -} - -func (h Subscription) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { - r.Group(func(r chi.Router) { - r.Use(middlewares...) - r.Get("/subscription/", h.Current) - }) -} diff --git a/system/rest/request/subscription.go b/system/rest/request/subscription.go deleted file mode 100644 index 6299d97ca..000000000 --- a/system/rest/request/subscription.go +++ /dev/null @@ -1,60 +0,0 @@ -package request - -// This file is auto-generated. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// Definitions file that controls how this file is generated: -// - -import ( - "encoding/json" - "fmt" - "github.com/cortezaproject/corteza-server/pkg/payload" - "github.com/go-chi/chi" - "io" - "mime/multipart" - "net/http" - "strings" -) - -// dummy vars to prevent -// unused imports complain -var ( - _ = chi.URLParam - _ = multipart.ErrMessageTooLarge - _ = payload.ParseUint64s -) - -type ( - // Internal API interface - SubscriptionCurrent struct { - } -) - -// NewSubscriptionCurrent request -func NewSubscriptionCurrent() *SubscriptionCurrent { - return &SubscriptionCurrent{} -} - -// Auditable returns all auditable/loggable parameters -func (r SubscriptionCurrent) Auditable() map[string]interface{} { - return map[string]interface{}{} -} - -// Fill processes request and fills internal variables -func (r *SubscriptionCurrent) Fill(req *http.Request) (err error) { - if strings.ToLower(req.Header.Get("content-type")) == "application/json" { - err = json.NewDecoder(req.Body).Decode(r) - - switch { - case err == io.EOF: - err = nil - case err != nil: - return fmt.Errorf("error parsing http request body: %w", err) - } - } - - return err -} diff --git a/system/rest/router.go b/system/rest/router.go index 367183022..13403c419 100644 --- a/system/rest/router.go +++ b/system/rest/router.go @@ -27,7 +27,6 @@ func MountRoutes(r chi.Router) { handlers.NewAuthClient(AuthClient{}.New()).MountRoutes(r) handlers.NewAutomation(Automation{}.New()).MountRoutes(r) - handlers.NewSubscription(Subscription{}.New()).MountRoutes(r) handlers.NewUser(User{}.New()).MountRoutes(r) handlers.NewRole(Role{}.New()).MountRoutes(r) handlers.NewPermissions(Permissions{}.New()).MountRoutes(r) diff --git a/system/rest/subscription.go b/system/rest/subscription.go deleted file mode 100644 index 87e1348e7..000000000 --- a/system/rest/subscription.go +++ /dev/null @@ -1,45 +0,0 @@ -package rest - -import ( - "context" - "github.com/cortezaproject/corteza-server/pkg/api" - "github.com/cortezaproject/corteza-server/system/rest/request" -) - -type Subscription struct{} - -func (Subscription) New() *Subscription { - return &Subscription{} -} - -func (ctrl *Subscription) Current(ctx context.Context, r *request.SubscriptionCurrent) (interface{}, error) { - return api.OK(), nil - //if service.CurrentSubscription == nil { - // // Nothing to do here - //} - // - //// Returning function that gets called with writter & request - //// - //// This is the only way to get to the request URL we need to do a domain check - //// for the permit - //return func(w http.ResponseWriter, r *http.Request) { - // var ( - // domain = r.Host - // pos = strings.IndexByte(domain, ':') - // - // // Anyone that has access permissions is considered admin - // isAdmin = service.DefaultAccessControl.CanAccess(ctx) - // ) - // - // if pos > -1 { - // // Strip port - // domain = domain[:pos] - // } - // - // if err := service.CurrentSubscription.Validate(domain, isAdmin); err != nil { - // api.Send(w, r, err) - // } else { - // api.Send(w, r, api.OK()) - // } - //}, nil -} diff --git a/system/service/auth.go b/system/service/auth.go index 4d14fdc6d..ef1dc58f7 100644 --- a/system/service/auth.go +++ b/system/service/auth.go @@ -26,7 +26,6 @@ type ( ac authAccessController eventbus eventDispatcher - subscription authSubscriptionChecker store store.Storer settings *types.AppSettings notifications AuthNotificationService @@ -37,10 +36,6 @@ type ( authAccessController interface { CanImpersonateUser(context.Context, *types.User) bool } - - authSubscriptionChecker interface { - CanRegister(uint) error - } ) const ( @@ -67,7 +62,6 @@ func Auth() *auth { return &auth{ eventbus: eventbus.Service(), ac: DefaultAccessControl, - subscription: CurrentSubscription, settings: CurrentSettings, notifications: DefaultAuthNotification, @@ -190,9 +184,6 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User, // Find user via his email if u, err = store.LookupUserByEmail(ctx, svc.store, profile.Email); errors.IsNotFound(err) { // @todo check if it is ok to auto-create a user here - if err = svc.CanRegister(ctx); err != nil { - return AuthErrSubscription(aam).Wrap(err) - } // In case we do not have this email, create a new user u = &types.User{ @@ -351,10 +342,6 @@ func (svc auth) InternalSignUp(ctx context.Context, input *types.User, password // // return nil,nil - if err = svc.CanRegister(ctx); err != nil { - return err - } - var nUser = &types.User{ ID: nextID(), CreatedAt: *now(), @@ -818,23 +805,6 @@ func (svc auth) SendPasswordResetToken(ctx context.Context, email string) (err e return svc.recordAction(ctx, aam, AuthActionSendPasswordResetToken, err) } -// CanRegister verifies if user can register -func (svc auth) CanRegister(ctx context.Context) error { - if svc.subscription != nil { - c, err := store.CountUsers(ctx, svc.store, types.UserFilter{}) - if err != nil { - return fmt.Errorf("can not check if user can register: %w", err) - } - - // When we have an active subscription, we need to check - // if users can register or did this deployment hit - // it's user-limit - return svc.subscription.CanRegister(c) - } - - return nil -} - func (svc auth) sendPasswordResetToken(ctx context.Context, u *types.User) (err error) { var ( notificationLang = "en" diff --git a/system/service/auth_actions.gen.go b/system/service/auth_actions.gen.go index ff07aa481..3d18704f0 100644 --- a/system/service/auth_actions.gen.go +++ b/system/service/auth_actions.gen.go @@ -571,36 +571,6 @@ func AuthErrGeneric(mm ...*authActionProps) *errors.Error { return e } -// AuthErrSubscription returns "system:auth.subscription" as *errors.Error -// -// -// This function is auto-generated. -// -func AuthErrSubscription(mm ...*authActionProps) *errors.Error { - var p = &authActionProps{} - if len(mm) > 0 { - p = mm[0] - } - - var e = errors.New( - errors.KindInternal, - - p.Format("subscription error", nil), - - errors.Meta("type", "subscription"), - errors.Meta("resource", "system:auth"), - - errors.Meta(authPropsMetaKey{}, p), - - errors.StackSkip(1), - ) - - if len(mm) > 0 { - } - - return e -} - // AuthErrInvalidCredentials returns "system:auth.invalidCredentials" as *errors.Error // // diff --git a/system/service/auth_actions.yaml b/system/service/auth_actions.yaml index e70717768..712a34f5b 100644 --- a/system/service/auth_actions.yaml +++ b/system/service/auth_actions.yaml @@ -69,10 +69,6 @@ actions: log: "impersonating {user}" errors: - - error: subscription - message: "subscription error" - severity: warning - - error: invalidCredentials message: "invalid username and password combination" log: "{email} failed to authenticate with {credentials.kind}" diff --git a/system/service/service.go b/system/service/service.go index 6abd7c3df..687c643c7 100644 --- a/system/service/service.go +++ b/system/service/service.go @@ -35,12 +35,6 @@ type ( Auth options.AuthOpt } - permitChecker interface { - Validate(string, bool) error - CanCreateUser(uint) error - CanRegister(uint) error - } - eventDispatcher interface { WaitFor(ctx context.Context, ev eventbus.Event) (err error) Dispatch(ctx context.Context, ev eventbus.Event) @@ -57,17 +51,6 @@ var ( DefaultLogger *zap.Logger - // CurrentSubscription holds current subscription info, - // and functions for domain validation, user limit checks and - // warning texts - // - // By default, Corteza (community edition) has this set to nil - // and with that all checks & validations are skipped - // - // Other flavours or distributions can set this to - // something that suits their needs. - CurrentSubscription permitChecker - // DefaultSettings controls system's settings DefaultSettings *settings diff --git a/system/service/user.go b/system/service/user.go index 50f12e706..bd430d643 100644 --- a/system/service/user.go +++ b/system/service/user.go @@ -31,8 +31,7 @@ type ( settings *types.AppSettings - auth userAuth - subscription userSubscriptionChecker + auth userAuth ac userAccessController eventbus eventDispatcher @@ -45,10 +44,6 @@ type ( SetPasswordCredentials(context.Context, uint64, string) error } - userSubscriptionChecker interface { - CanCreateUser(uint) error - } - userAccessController interface { CanCreateUser(context.Context) bool CanReadUser(context.Context, *types.User) bool @@ -99,8 +94,6 @@ func User(ctx context.Context) UserService { store: DefaultStore, actionlog: DefaultActionlog, - - subscription: CurrentSubscription, }) } @@ -360,21 +353,6 @@ func (svc user) Create(ctx context.Context, new *types.User) (u *types.User, err return UserErrInvalidEmail() } - if svc.subscription != nil { - var c uint - if c, err = store.CountUsers(ctx, svc.store, types.UserFilter{}); err != nil { - return err - } - - // When we have an active subscription, we need to check - // if users can be create or did this deployment hit - // it's user-limit - err = svc.subscription.CanCreateUser(c) - if err != nil { - return err - } - } - if err = svc.eventbus.WaitFor(ctx, event.UserBeforeCreate(new, u)); err != nil { return }