Use store pkg functions instead of struct methods

Mainly for consistenct
This commit is contained in:
Denis Arh
2020-09-08 20:06:03 +02:00
parent 68deb606a0
commit 11b7803305
12 changed files with 120 additions and 120 deletions
+7 -7
View File
@@ -95,7 +95,7 @@ func (svc chart) FindByID(namespaceID, chartID uint64) (c *types.Chart, err erro
}
aProps.chart.ID = chartID
return svc.store.LookupComposeChartByID(svc.ctx, chartID)
return store.LookupComposeChartByID(svc.ctx, svc.store, chartID)
})
}
@@ -106,7 +106,7 @@ func (svc chart) FindByHandle(namespaceID uint64, h string) (c *types.Chart, err
}
aProps.chart.Handle = h
return svc.store.LookupComposeChartByNamespaceIDHandle(svc.ctx, namespaceID, h)
return store.LookupComposeChartByNamespaceIDHandle(svc.ctx, svc.store, namespaceID, h)
})
}
@@ -141,7 +141,7 @@ func (svc chart) Create(new *types.Chart) (*types.Chart, error) {
return err
}
return svc.store.CreateComposeChart(svc.ctx, new)
return store.CreateComposeChart(svc.ctx, svc.store, new)
}()
return new, svc.recordAction(svc.ctx, aProps, ChartActionCreate, err)
@@ -198,7 +198,7 @@ func (svc chart) updater(namespaceID, chartID uint64, action func(...*chartActio
)
err = store.Tx(svc.ctx, svc.store, func(ctx context.Context, s store.Storable) (err error) {
ns, c, err = loadChart(svc.ctx, s, namespaceID, chartID)
ns, c, err = loadChart(ctx, s, namespaceID, chartID)
if err != nil {
return
}
@@ -206,13 +206,13 @@ func (svc chart) updater(namespaceID, chartID uint64, action func(...*chartActio
aProps.setNamespace(ns)
aProps.setChanged(c)
if changed, err = fn(svc.ctx, ns, c); err != nil {
if changed, err = fn(ctx, ns, c); err != nil {
return err
} else if !changed {
return
}
return svc.store.UpdateComposeChart(svc.ctx, c)
return store.UpdateComposeChart(ctx, s, c)
})
return c, svc.recordAction(svc.ctx, aProps, action, err)
@@ -220,7 +220,7 @@ func (svc chart) updater(namespaceID, chartID uint64, action func(...*chartActio
func (svc chart) uniqueCheck(c *types.Chart) (err error) {
if c.Handle != "" {
if e, _ := svc.store.LookupComposeChartByNamespaceIDHandle(svc.ctx, c.NamespaceID, c.Handle); e != nil && e.ID != c.ID {
if e, _ := store.LookupComposeChartByNamespaceIDHandle(svc.ctx, svc.store, c.NamespaceID, c.Handle); e != nil && e.ID != c.ID {
return ChartErrHandleNotUnique()
}
}
+1 -1
View File
@@ -267,7 +267,7 @@ func (svc module) updater(namespaceID, moduleID uint64, action func(...*moduleAc
}
if moduleChanged {
if err = svc.store.UpdateComposeModule(svc.ctx, m); err != nil {
if err = store.UpdateComposeModule(svc.ctx, svc.store, m); err != nil {
return err
}
}
+1 -1
View File
@@ -221,7 +221,7 @@ func (svc namespace) updater(namespaceID uint64, action func(...*namespaceAction
}
if changed {
if err = svc.store.UpdateComposeNamespace(svc.ctx, ns); err != nil {
if err = store.UpdateComposeNamespace(svc.ctx, svc.store, ns); err != nil {
return err
}
}
+1 -1
View File
@@ -321,7 +321,7 @@ func (svc page) updater(namespaceID, pageID uint64, action func(...*pageActionPr
}
if changed {
if err = svc.store.UpdateComposePage(svc.ctx, p); err != nil {
if err = store.UpdateComposePage(svc.ctx, svc.store, p); err != nil {
return err
}
}
+9 -9
View File
@@ -41,7 +41,7 @@ func (svc *application) LookupByID(ctx context.Context, ID uint64) (app *types.A
return ApplicationErrInvalidID()
}
if app, err = svc.store.LookupApplicationByID(ctx, ID); err != nil {
if app, err = store.LookupApplicationByID(ctx, svc.store, ID); err != nil {
return ApplicationErrInvalidID().Wrap(err)
}
@@ -83,7 +83,7 @@ func (svc *application) Search(ctx context.Context, af types.ApplicationFilter)
}
}
aa, f, err = svc.store.SearchApplications(ctx, af)
aa, f, err = store.SearchApplications(ctx, svc.store, af)
return err
}()
@@ -112,7 +112,7 @@ func (svc *application) Create(ctx context.Context, new *types.Application) (app
new.Unify = &types.ApplicationUnify{}
}
if err = svc.store.CreateApplication(ctx, new); err != nil {
if err = store.CreateApplication(ctx, svc.store, new); err != nil {
return
}
@@ -135,7 +135,7 @@ func (svc *application) Update(ctx context.Context, upd *types.Application) (app
return ApplicationErrInvalidID()
}
if app, err = svc.store.LookupApplicationByID(ctx, upd.ID); err != nil {
if app, err = store.LookupApplicationByID(ctx, svc.store, upd.ID); err != nil {
return
}
@@ -158,7 +158,7 @@ func (svc *application) Update(ctx context.Context, upd *types.Application) (app
app.Unify = upd.Unify
}
if err = svc.store.UpdateApplication(ctx, app); err != nil {
if err = store.UpdateApplication(ctx, svc.store, app); err != nil {
return err
}
@@ -180,7 +180,7 @@ func (svc *application) Delete(ctx context.Context, ID uint64) (err error) {
return ApplicationErrInvalidID()
}
if app, err = svc.store.LookupApplicationByID(ctx, ID); err != nil {
if app, err = store.LookupApplicationByID(ctx, svc.store, ID); err != nil {
return
}
@@ -195,7 +195,7 @@ func (svc *application) Delete(ctx context.Context, ID uint64) (err error) {
}
app.DeletedAt = nowPtr()
if err = svc.store.UpdateApplication(ctx, app); err != nil {
if err = store.UpdateApplication(ctx, svc.store, app); err != nil {
return
}
@@ -217,7 +217,7 @@ func (svc *application) Undelete(ctx context.Context, ID uint64) (err error) {
return ApplicationErrInvalidID()
}
if app, err = svc.store.LookupApplicationByID(ctx, ID); err != nil {
if app, err = store.LookupApplicationByID(ctx, svc.store, ID); err != nil {
return
}
@@ -233,7 +233,7 @@ func (svc *application) Undelete(ctx context.Context, ID uint64) (err error) {
// }
app.DeletedAt = nil
if err = svc.store.UpdateApplication(ctx, app); err != nil {
if err = store.UpdateApplication(ctx, svc.store, app); err != nil {
return
}
+10 -10
View File
@@ -6,8 +6,8 @@ import (
"github.com/cortezaproject/corteza-server/pkg/actionlog"
intAuth "github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/pkg/store"
ngStore "github.com/cortezaproject/corteza-server/store"
files "github.com/cortezaproject/corteza-server/pkg/store"
"github.com/cortezaproject/corteza-server/store"
"github.com/cortezaproject/corteza-server/system/types"
"github.com/disintegration/imaging"
"github.com/edwvee/exiffix"
@@ -29,9 +29,9 @@ type (
attachment struct {
ctx context.Context
actionlog actionlog.Recorder
files store.Store
files files.Store
ac attachmentAccessController
store ngStore.Storable
store store.Storable
}
attachmentAccessController interface {
@@ -50,7 +50,7 @@ type (
}
)
func Attachment(store store.Store) AttachmentService {
func Attachment(store files.Store) AttachmentService {
return (&attachment{
files: store,
actionlog: DefaultActionlog,
@@ -82,7 +82,7 @@ func (svc attachment) FindByID(ID uint64) (att *types.Attachment, err error) {
return AttachmentErrInvalidID()
}
if att, err = svc.store.LookupAttachmentByID(svc.ctx, ID); err != nil {
if att, err = store.LookupAttachmentByID(svc.ctx, svc.store, ID); err != nil {
return err
}
@@ -104,14 +104,14 @@ func (svc attachment) DeleteByID(ID uint64) (err error) {
return AttachmentErrInvalidID()
}
if att, err = svc.store.LookupAttachmentByID(svc.ctx, ID); err != nil {
if att, err = store.LookupAttachmentByID(svc.ctx, svc.store, ID); err != nil {
return err
}
att.DeletedAt = nowPtr()
aaProps.setAttachment(att)
return svc.store.UpdateAttachment(svc.ctx, att)
return store.UpdateAttachment(svc.ctx, svc.store, att)
}()
return svc.recordAction(svc.ctx, aaProps, AttachmentActionDelete, err)
@@ -123,7 +123,7 @@ func (svc attachment) Find(filter types.AttachmentFilter) (aa types.AttachmentSe
)
err = func() (err error) {
aa, f, err = svc.store.SearchAttachments(svc.ctx, filter)
aa, f, err = store.SearchAttachments(svc.ctx, svc.store, filter)
return err
}()
@@ -213,7 +213,7 @@ func (svc attachment) create(name string, size int64, fh io.ReadSeeker, att *typ
return AttachmentErrFailedToProcessImage(aaProps).Wrap(err)
}
if err = svc.store.CreateAttachment(svc.ctx, att); err != nil {
if err = store.CreateAttachment(svc.ctx, svc.store, att); err != nil {
return
}
+32 -32
View File
@@ -120,7 +120,7 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
}
f := types.CredentialsFilter{Kind: profile.Provider, Credentials: profile.UserID}
if cc, _, err := svc.store.SearchCredentials(ctx, f); err == nil {
if cc, _, err := store.SearchCredentials(ctx, svc.store, f); err == nil {
// Credentials found, load user
for _, c := range cc {
if !c.Valid() {
@@ -130,11 +130,11 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
// Add credentials ID for audit log
aam.setCredentials(c)
if u, err = svc.store.LookupUserByID(ctx, c.OwnerID); err != nil {
if u, err = store.LookupUserByID(ctx, svc.store, c.OwnerID); err != nil {
if errors.Is(err, store.ErrNotFound) {
// Orphaned credentials (no owner)
// try to auto-fix this by removing credentials and recreating user
if err = svc.store.DeleteCredentialsByID(ctx, c.ID); err != nil {
if err = store.DeleteCredentialsByID(ctx, svc.store, c.ID); err != nil {
return err
} else {
goto findByEmail
@@ -155,7 +155,7 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
if u.Valid() {
// Valid user, Bingo!
c.LastUsedAt = nowPtr()
if err = svc.store.UpdateCredentials(ctx, c); err != nil {
if err = store.UpdateCredentials(ctx, svc.store, c); err != nil {
return err
}
@@ -189,7 +189,7 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
setUser(nil)
// Find user via his email
if u, err = svc.store.LookupUserByEmail(ctx, profile.Email); errors.Is(err, store.ErrNotFound) {
if u, err = store.LookupUserByEmail(ctx, svc.store, profile.Email); errors.Is(err, store.ErrNotFound) {
// @todo check if it is ok to auto-create a user here
if err = svc.CanRegister(ctx); err != nil {
return AuthErrSubscription(aam).Wrap(err)
@@ -216,7 +216,7 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
u.ID = id.Next()
u.CreatedAt = now()
if err = svc.store.CreateUser(ctx, u); err != nil {
if err = store.CreateUser(ctx, svc.store, u); err != nil {
return err
}
@@ -263,7 +263,7 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
LastUsedAt: nowPtr(),
}
if err = svc.store.CreateCredentials(ctx, c); err != nil {
if err = store.CreateCredentials(ctx, svc.store, c); err != nil {
return err
}
@@ -316,13 +316,13 @@ func (svc auth) InternalSignUp(ctx context.Context, input *types.User, password
}
var eUser *types.User
eUser, err = svc.store.LookupUserByEmail(ctx, input.Email)
eUser, err = store.LookupUserByEmail(ctx, svc.store, input.Email)
if err == nil && eUser.Valid() {
var (
cc types.CredentialsSet
f = types.CredentialsFilter{OwnerID: eUser.ID, Kind: credentialsTypePassword}
)
cc, _, err = svc.store.SearchCredentials(ctx, f)
cc, _, err = store.SearchCredentials(ctx, svc.store, f)
if err != nil {
return err
}
@@ -335,7 +335,7 @@ func (svc auth) InternalSignUp(ctx context.Context, input *types.User, password
c.UpdatedAt = nowPtr()
aam.setCredentials(c)
if err = svc.store.UpdateCredentials(ctx, c); err != nil {
if err = store.UpdateCredentials(ctx, svc.store, c); err != nil {
return err
}
}
@@ -396,7 +396,7 @@ func (svc auth) InternalSignUp(ctx context.Context, input *types.User, password
}
// Whitelisted user data to copy
err = svc.store.CreateUser(ctx, nUser)
err = store.CreateUser(ctx, svc.store, nUser)
if err != nil {
return err
@@ -462,7 +462,7 @@ func (svc auth) InternalLogin(ctx context.Context, email string, password string
cc types.CredentialsSet
)
u, err = svc.store.LookupUserByEmail(ctx, email)
u, err = store.LookupUserByEmail(ctx, svc.store, email)
if errors.Is(err, store.ErrNotFound) {
return AuthErrFailedForUnknownUser()
}
@@ -474,7 +474,7 @@ func (svc auth) InternalLogin(ctx context.Context, email string, password string
// Update audit meta with found user
ctx = internalAuth.SetIdentityToContext(ctx, u)
cc, _, err = svc.store.SearchCredentials(ctx, types.CredentialsFilter{OwnerID: u.ID, Kind: credentialsTypePassword})
cc, _, err = store.SearchCredentials(ctx, svc.store, types.CredentialsFilter{OwnerID: u.ID, Kind: credentialsTypePassword})
if err != nil {
return err
}
@@ -487,7 +487,7 @@ func (svc auth) InternalLogin(ctx context.Context, email string, password string
c.LastUsedAt = nowPtr()
aam.setCredentials(c)
if err = svc.store.UpdateCredentials(ctx, c); err != nil {
if err = store.UpdateCredentials(ctx, svc.store, c); err != nil {
return err
}
}
@@ -542,7 +542,7 @@ func (svc auth) SetPassword(ctx context.Context, userID uint64, password string)
return AuthErrPasswordNotSecure(aam)
}
u, err = svc.store.LookupUserByID(ctx, userID)
u, err = store.LookupUserByID(ctx, svc.store, userID)
if errors.Is(err, store.ErrNotFound) {
return AuthErrPasswordChangeFailedForUnknownUser(aam)
}
@@ -566,7 +566,7 @@ func (svc auth) Impersonate(ctx context.Context, userID uint64) (u *types.User,
)
err = func() error {
if u, err = svc.store.LookupUserByID(ctx, userID); err != nil {
if u, err = store.LookupUserByID(ctx, svc.store, userID); err != nil {
return err
}
@@ -605,12 +605,12 @@ func (svc auth) ChangePassword(ctx context.Context, userID uint64, oldPassword,
return AuthErrPasswordNotSecure(aam)
}
u, err = svc.store.LookupUserByID(ctx, userID)
u, err = store.LookupUserByID(ctx, svc.store, userID)
if errors.Is(err, store.ErrNotFound) {
return AuthErrPasswordChangeFailedForUnknownUser(aam)
}
cc, _, err = svc.store.SearchCredentials(ctx, types.CredentialsFilter{Kind: credentialsTypePassword, OwnerID: userID})
cc, _, err = store.SearchCredentials(ctx, svc.store, types.CredentialsFilter{Kind: credentialsTypePassword, OwnerID: userID})
if err != nil {
return err
}
@@ -658,7 +658,7 @@ func (svc auth) SetPasswordCredentials(ctx context.Context, userID uint64, passw
return
}
if cc, _, err = svc.store.SearchCredentials(ctx, f); err != nil {
if cc, _, err = store.SearchCredentials(ctx, svc.store, f); err != nil {
return nil
}
@@ -669,7 +669,7 @@ func (svc auth) SetPasswordCredentials(ctx context.Context, userID uint64, passw
})
// Do a partial update and soft-delete all
if err = svc.store.UpdateCredentials(ctx, cc...); err != nil {
if err = store.UpdateCredentials(ctx, svc.store, cc...); err != nil {
return
}
@@ -682,7 +682,7 @@ func (svc auth) SetPasswordCredentials(ctx context.Context, userID uint64, passw
Credentials: string(hash),
}
return svc.store.CreateCredentials(ctx, c)
return store.CreateCredentials(ctx, svc.store, c)
}
// IssueAuthRequestToken returns token that can be used for authentication
@@ -748,7 +748,7 @@ func (svc auth) loadFromTokenAndConfirmEmail(ctx context.Context, token, tokenTy
u.EmailConfirmed = true
u.UpdatedAt = nowPtr()
if err = svc.store.UpdateUser(ctx, u); err != nil {
if err = store.UpdateUser(ctx, svc.store, u); err != nil {
return err
}
@@ -806,7 +806,7 @@ func (svc auth) SendEmailAddressConfirmationToken(ctx context.Context, email str
return AuthErrPasswordResetDisabledByConfig(aam)
}
u, err := svc.store.LookupUserByEmail(ctx, email)
u, err := store.LookupUserByEmail(ctx, svc.store, email)
if err != nil {
return AuthErrInvalidToken(aam)
}
@@ -855,7 +855,7 @@ func (svc auth) SendPasswordResetToken(ctx context.Context, email string) (err e
return AuthErrPasswordResetDisabledByConfig(aam)
}
if u, err = svc.store.LookupUserByEmail(ctx, email); err != nil {
if u, err = store.LookupUserByEmail(ctx, svc.store, email); err != nil {
return err
}
@@ -874,7 +874,7 @@ func (svc auth) SendPasswordResetToken(ctx context.Context, email string) (err e
// CanRegister verifies if user can register
func (svc auth) CanRegister(ctx context.Context) error {
if svc.subscription != nil {
c, err := svc.store.CountUsers(ctx, types.UserFilter{})
c, err := store.CountUsers(ctx, svc.store, types.UserFilter{})
if err != nil {
return fmt.Errorf("can not check if user can register: %w", err)
}
@@ -913,7 +913,7 @@ func (svc auth) loadUserFromToken(ctx context.Context, token, kind string) (u *t
return nil, AuthErrInvalidToken(aam)
}
c, err := svc.store.LookupCredentialsByID(ctx, credentialsID)
c, err := store.LookupCredentialsByID(ctx, svc.store, credentialsID)
if errors.Is(err, store.ErrNotFound) {
return nil, AuthErrInvalidToken(aam)
}
@@ -924,7 +924,7 @@ func (svc auth) loadUserFromToken(ctx context.Context, token, kind string) (u *t
return
}
if err = svc.store.DeleteCredentialsByID(ctx, c.ID); err != nil {
if err = store.DeleteCredentialsByID(ctx, svc.store, c.ID); err != nil {
return
}
@@ -932,7 +932,7 @@ func (svc auth) loadUserFromToken(ctx context.Context, token, kind string) (u *t
return nil, AuthErrInvalidToken(aam)
}
u, err = svc.store.LookupUserByID(ctx, c.OwnerID)
u, err = store.LookupUserByID(ctx, svc.store, c.OwnerID)
if err != nil {
return nil, err
}
@@ -994,7 +994,7 @@ func (svc auth) createUserToken(ctx context.Context, u *types.User, kind string)
ExpiresAt: &expiresAt,
}
err := svc.store.CreateCredentials(ctx, c)
err := store.CreateCredentials(ctx, svc.store, c)
if err != nil {
return err
@@ -1016,7 +1016,7 @@ func (svc auth) autoPromote(ctx context.Context, u *types.User) (err error) {
)
err = func() error {
if c, err = svc.store.CountUsers(ctx, types.UserFilter{}); err != nil {
if c, err = store.CountUsers(ctx, svc.store, types.UserFilter{}); err != nil {
return err
}
@@ -1024,7 +1024,7 @@ func (svc auth) autoPromote(ctx context.Context, u *types.User) (err error) {
return nil
}
return svc.store.CreateRoleMember(ctx, &types.RoleMember{roleID, u.ID})
return store.CreateRoleMember(ctx, svc.store, &types.RoleMember{roleID, u.ID})
}()
return svc.recordAction(ctx, aam, AuthActionAutoPromote, err)
@@ -1034,7 +1034,7 @@ func (svc auth) autoPromote(ctx context.Context, u *types.User) (err error) {
//
// @todo move this to role service
func (svc auth) LoadRoleMemberships(ctx context.Context, u *types.User) error {
rr, _, err := svc.store.SearchRoles(ctx, types.RoleFilter{MemberID: u.ID})
rr, _, err := store.SearchRoles(ctx, svc.store, types.RoleFilter{MemberID: u.ID})
if err != nil {
return err
}
+3 -3
View File
@@ -108,8 +108,8 @@ func TestAuth_External(t *testing.T) {
svc.settings.Auth.External.Enabled = true
req.NoError(svc.store.TruncateUsers(ctx))
req.NoError(svc.store.TruncateCredentials(ctx))
req.NoError(svc.store.CreateUser(ctx, validUser, suspendedUser))
req.NoError(svc.store.CreateCredentials(ctx, fooCredentials, barCredentials))
req.NoError(store.CreateUser(ctx, svc.store, validUser, suspendedUser))
req.NoError(store.CreateCredentials(ctx, svc.store, fooCredentials, barCredentials))
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
@@ -192,7 +192,7 @@ func TestAuth_InternalLogin(t *testing.T) {
svc.settings.Auth.Internal.Enabled = true
req.NoError(svc.store.TruncateUsers(ctx))
req.NoError(svc.store.TruncateCredentials(ctx))
req.NoError(svc.store.CreateUser(ctx, validUser, suspendedUser))
req.NoError(store.CreateUser(ctx, svc.store, validUser, suspendedUser))
req.NoError(svc.SetPasswordCredentials(ctx, validUser.ID, validPass))
for _, tt := range tests {
+10 -10
View File
@@ -50,7 +50,7 @@ func (svc reminder) Find(ctx context.Context, filter types.ReminderFilter) (rr t
)
err = func() (err error) {
rr, f, err = svc.store.SearchReminders(ctx, filter)
rr, f, err = store.SearchReminders(ctx, svc.store, filter)
if err != nil {
return err
}
@@ -71,7 +71,7 @@ func (svc reminder) FindByID(ctx context.Context, ID uint64) (r *types.Reminder,
return ReminderErrInvalidID()
}
r, err = svc.store.LookupReminderByID(ctx, ID)
r, err = store.LookupReminderByID(ctx, svc.store, ID)
if err != nil {
return err
}
@@ -122,7 +122,7 @@ func (svc reminder) Create(ctx context.Context, new *types.Reminder) (r *types.R
r.ID = id.Next()
r.CreatedAt = now()
if err = svc.store.CreateReminder(ctx, new); err != nil {
if err = store.CreateReminder(ctx, svc.store, new); err != nil {
return err
}
@@ -143,7 +143,7 @@ func (svc reminder) Update(ctx context.Context, upd *types.Reminder) (r *types.R
return ReminderErrInvalidID()
}
if r, err = svc.store.LookupReminderByID(ctx, upd.ID); err != nil {
if r, err = store.LookupReminderByID(ctx, svc.store, upd.ID); err != nil {
return
}
@@ -163,7 +163,7 @@ func (svc reminder) Update(ctx context.Context, upd *types.Reminder) (r *types.R
r.Resource = upd.Resource
r.UpdatedAt = nowPtr()
if err = svc.store.UpdateReminder(ctx, r); err != nil {
if err = store.UpdateReminder(ctx, svc.store, r); err != nil {
return err
}
@@ -185,7 +185,7 @@ func (svc reminder) Dismiss(ctx context.Context, ID uint64) (err error) {
return ReminderErrInvalidID()
}
if r, err = svc.store.LookupReminderByID(ctx, ID); err != nil {
if r, err = store.LookupReminderByID(ctx, svc.store, ID); err != nil {
return ReminderErrNotFound()
}
@@ -196,7 +196,7 @@ func (svc reminder) Dismiss(ctx context.Context, ID uint64) (err error) {
r.DismissedAt = &n
r.DismissedBy = svc.currentUser(ctx)
if err = svc.store.UpdateReminder(ctx, r); err != nil {
if err = store.UpdateReminder(ctx, svc.store, r); err != nil {
return err
}
@@ -218,7 +218,7 @@ func (svc reminder) Snooze(ctx context.Context, ID uint64, remindAt *time.Time)
return ReminderErrInvalidID()
}
if r, err = svc.store.LookupReminderByID(ctx, ID); err != nil {
if r, err = store.LookupReminderByID(ctx, svc.store, ID); err != nil {
return ReminderErrNotFound()
}
@@ -228,7 +228,7 @@ func (svc reminder) Snooze(ctx context.Context, ID uint64, remindAt *time.Time)
r.SnoozeCount++
r.RemindAt = remindAt
if err = svc.store.UpdateReminder(ctx, r); err != nil {
if err = store.UpdateReminder(ctx, svc.store, r); err != nil {
return err
}
@@ -258,7 +258,7 @@ func (svc reminder) Delete(ctx context.Context, ID uint64) (err error) {
raProps.setReminder(r)
return svc.store.UpdateReminder(ctx, r)
return store.UpdateReminder(ctx, svc.store, r)
}()
return svc.recordAction(ctx, raProps, ReminderActionDelete, err)
+17 -17
View File
@@ -113,7 +113,7 @@ func (svc role) Find(filter types.RoleFilter) (rr types.RoleSet, f types.RoleFil
}
}
rr, f, err = svc.store.SearchRoles(svc.ctx, filter)
rr, f, err = store.SearchRoles(svc.ctx, svc.store, filter)
return err
}()
@@ -139,7 +139,7 @@ func (svc role) findByID(roleID uint64) (*types.Role, error) {
return nil, RoleErrInvalidID()
}
return svc.store.LookupRoleByID(svc.ctx, roleID)
return store.LookupRoleByID(svc.ctx, svc.store, roleID)
}
func (svc role) FindByName(name string) (r *types.Role, err error) {
@@ -148,7 +148,7 @@ func (svc role) FindByName(name string) (r *types.Role, err error) {
)
err = func() error {
r, err = svc.store.LookupRoleByName(svc.ctx, name)
r, err = store.LookupRoleByName(svc.ctx, svc.store, name)
raProps.setRole(r)
return err
}()
@@ -162,7 +162,7 @@ func (svc role) FindByHandle(h string) (r *types.Role, err error) {
)
err = func() error {
r, err = svc.store.LookupRoleByName(svc.ctx, h)
r, err = store.LookupRoleByName(svc.ctx, svc.store, h)
raProps.setRole(r)
return err
}()
@@ -215,7 +215,7 @@ func (svc role) Create(new *types.Role) (r *types.Role, err error) {
new.ID = id.Next()
new.CreatedAt = now()
if err = svc.store.CreateRole(svc.ctx, new); err != nil {
if err = store.CreateRole(svc.ctx, svc.store, new); err != nil {
return
}
@@ -247,7 +247,7 @@ func (svc role) Update(upd *types.Role) (r *types.Role, err error) {
return RoleErrNotAllowedToUpdate()
}
if r, err = svc.store.LookupRoleByID(svc.ctx, upd.ID); err != nil {
if r, err = store.LookupRoleByID(svc.ctx, svc.store, upd.ID); err != nil {
return
}
@@ -266,7 +266,7 @@ func (svc role) Update(upd *types.Role) (r *types.Role, err error) {
r.UpdatedAt = nowPtr()
// Assign changed values
if err = svc.store.UpdateRole(svc.ctx, r); err != nil {
if err = store.UpdateRole(svc.ctx, svc.store, r); err != nil {
return err
}
@@ -284,14 +284,14 @@ func (svc role) UniqueCheck(r *types.Role) (err error) {
)
if r.Handle != "" {
if ex, _ := svc.store.LookupRoleByHandle(svc.ctx, r.Handle); ex != nil && ex.ID > 0 && ex.ID != r.ID {
if ex, _ := store.LookupRoleByHandle(svc.ctx, svc.store, r.Handle); ex != nil && ex.ID > 0 && ex.ID != r.ID {
raProps.setExisting(ex)
return RoleErrHandleNotUnique()
}
}
if r.Name != "" {
if ex, _ := svc.store.LookupRoleByName(svc.ctx, r.Name); ex != nil && ex.ID > 0 && ex.ID != r.ID {
if ex, _ := store.LookupRoleByName(svc.ctx, svc.store, r.Name); ex != nil && ex.ID > 0 && ex.ID != r.ID {
raProps.setExisting(ex)
return RoleErrNameNotUnique()
}
@@ -323,7 +323,7 @@ func (svc role) Delete(roleID uint64) (err error) {
r.DeletedAt = nowPtr()
if err = svc.store.UpdateRole(svc.ctx, r); err != nil {
if err = store.UpdateRole(svc.ctx, svc.store, r); err != nil {
return
}
@@ -354,7 +354,7 @@ func (svc role) Undelete(roleID uint64) (err error) {
r.DeletedAt = nil
if err = svc.store.UpdateRole(svc.ctx, r); err != nil {
if err = store.UpdateRole(svc.ctx, svc.store, r); err != nil {
return
}
@@ -382,7 +382,7 @@ func (svc role) Archive(roleID uint64) (err error) {
}
r.ArchivedAt = nowPtr()
if err = svc.store.UpdateRole(svc.ctx, r); err != nil {
if err = store.UpdateRole(svc.ctx, svc.store, r); err != nil {
return
}
@@ -410,7 +410,7 @@ func (svc role) Unarchive(roleID uint64) (err error) {
}
r.ArchivedAt = nil
if err = svc.store.UpdateRole(svc.ctx, r); err != nil {
if err = store.UpdateRole(svc.ctx, svc.store, r); err != nil {
return
}
@@ -421,7 +421,7 @@ func (svc role) Unarchive(roleID uint64) (err error) {
}
func (svc role) Membership(userID uint64) (types.RoleMemberSet, error) {
mm, _, err := svc.store.SearchRoleMembers(svc.ctx, types.RoleMemberFilter{UserID: userID})
mm, _, err := store.SearchRoleMembers(svc.ctx, svc.store, types.RoleMemberFilter{UserID: userID})
return mm, err
}
@@ -447,7 +447,7 @@ func (svc role) MemberList(roleID uint64) (mm types.RoleMemberSet, err error) {
return RoleErrNotAllowedToRead()
}
mm, _, err = svc.store.SearchRoleMembers(svc.ctx, types.RoleMemberFilter{RoleID: roleID})
mm, _, err = store.SearchRoleMembers(svc.ctx, svc.store, types.RoleMemberFilter{RoleID: roleID})
return err
}()
@@ -491,7 +491,7 @@ func (svc role) MemberAdd(roleID, memberID uint64) (err error) {
return RoleErrNotAllowedToManageMembers()
}
if err = svc.store.CreateRoleMember(svc.ctx, &types.RoleMember{RoleID: r.ID, UserID: m.ID}); err != nil {
if err = store.CreateRoleMember(svc.ctx, svc.store, &types.RoleMember{RoleID: r.ID, UserID: m.ID}); err != nil {
return
}
@@ -538,7 +538,7 @@ func (svc role) MemberRemove(roleID, memberID uint64) (err error) {
return RoleErrNotAllowedToManageMembers()
}
if err = svc.store.DeleteRoleMember(svc.ctx, &types.RoleMember{RoleID: r.ID, UserID: m.ID}); err != nil {
if err = store.DeleteRoleMember(svc.ctx, svc.store, &types.RoleMember{RoleID: r.ID, UserID: m.ID}); err != nil {
return
}
+9 -9
View File
@@ -65,7 +65,7 @@ func (svc settings) findByPrefix(ctx context.Context, pp ...string) (types.Setti
}
)
vv, _, err := svc.store.SearchSettings(ctx, f)
vv, _, err := store.SearchSettings(ctx, svc.store, f)
return vv, err
}
@@ -74,7 +74,7 @@ func (svc settings) Get(ctx context.Context, name string, ownedBy uint64) (out *
return nil, ErrNoReadPermission
}
out, err = svc.store.LookupSettingByNameOwnedBy(ctx, name, ownedBy)
out, err = store.LookupSettingByNameOwnedBy(ctx, svc.store, name, ownedBy)
if err != nil && err != store.ErrNotFound {
return nil, err
}
@@ -105,17 +105,17 @@ func (svc settings) Set(ctx context.Context, v *types.SettingValue) (err error)
}
var current *types.SettingValue
current, err = svc.store.LookupSettingByNameOwnedBy(ctx, v.Name, v.OwnedBy)
current, err = store.LookupSettingByNameOwnedBy(ctx, svc.store, v.Name, v.OwnedBy)
if err == store.ErrNotFound {
v.UpdatedAt = time.Now()
err = svc.store.CreateSetting(ctx, v)
err = store.CreateSetting(ctx, svc.store, v)
} else if err != nil {
return err
}
if !current.Eq(v) {
v.UpdatedAt = time.Now()
err = svc.store.UpdateSetting(ctx, v)
err = store.UpdateSetting(ctx, svc.store, v)
}
if err != nil || current.Eq(v) {
@@ -147,11 +147,11 @@ func (svc settings) BulkSet(ctx context.Context, vv types.SettingValueSet) (err
new = current.New(vv)
}
if err = svc.store.UpdateSetting(ctx, old...); err != nil {
if err = store.UpdateSetting(ctx, svc.store, old...); err != nil {
return
}
if err = svc.store.CreateSetting(ctx, new...); err != nil {
if err = store.CreateSetting(ctx, svc.store, new...); err != nil {
return
}
@@ -177,13 +177,13 @@ func (svc settings) Delete(ctx context.Context, name string, ownedBy uint64) (er
}
var current *types.SettingValue
if current, err = svc.store.LookupSettingByNameOwnedBy(ctx, name, ownedBy); err == store.ErrNotFound {
if current, err = store.LookupSettingByNameOwnedBy(ctx, svc.store, name, ownedBy); err == store.ErrNotFound {
return nil
} else if err != nil {
return
}
err = svc.store.DeleteSetting(ctx, current)
err = store.DeleteSetting(ctx, svc.store, current)
if err != nil {
return
}
+20 -20
View File
@@ -143,7 +143,7 @@ func (svc user) FindByID(userID uint64) (u *types.User, err error) {
return nil
}
u, err = svc.proc(svc.store.LookupUserByID(svc.ctx, userID))
u, err = svc.proc(store.LookupUserByID(svc.ctx, svc.store, userID))
return err
}()
@@ -156,7 +156,7 @@ func (svc user) FindByEmail(email string) (u *types.User, err error) {
)
err = func() error {
u, err = svc.proc(svc.store.LookupUserByEmail(svc.ctx, email))
u, err = svc.proc(store.LookupUserByEmail(svc.ctx, svc.store, email))
return err
}()
@@ -169,7 +169,7 @@ func (svc user) FindByUsername(username string) (u *types.User, err error) {
)
err = func() error {
u, err = svc.proc(svc.store.LookupUserByUsername(svc.ctx, username))
u, err = svc.proc(store.LookupUserByUsername(svc.ctx, svc.store, username))
return err
}()
@@ -182,7 +182,7 @@ func (svc user) FindByHandle(handle string) (u *types.User, err error) {
)
err = func() error {
u, err = svc.proc(svc.store.LookupUserByHandle(svc.ctx, handle))
u, err = svc.proc(store.LookupUserByHandle(svc.ctx, svc.store, handle))
return err
}()
@@ -221,7 +221,7 @@ func (svc user) FindByAny(ctx context.Context, identifier interface{}) (u *types
return
}
rr, _, err := svc.store.SearchRoles(svc.ctx, types.RoleFilter{MemberID: u.ID})
rr, _, err := store.SearchRoles(svc.ctx, svc.store, types.RoleFilter{MemberID: u.ID})
if err != nil {
return nil, err
}
@@ -274,7 +274,7 @@ func (svc user) Find(filter types.UserFilter) (uu types.UserSet, f types.UserFil
}
}
uu, f, err = svc.store.SearchUsers(svc.ctx, filter)
uu, f, err = store.SearchUsers(svc.ctx, svc.store, filter)
if err != nil {
return err
}
@@ -308,7 +308,7 @@ func (svc user) Create(new *types.User) (u *types.User, err error) {
if svc.subscription != nil {
var c uint
if c, err = svc.store.CountUsers(svc.ctx, types.UserFilter{}); err != nil {
if c, err = store.CountUsers(svc.ctx, svc.store, types.UserFilter{}); err != nil {
return err
}
@@ -340,7 +340,7 @@ func (svc user) Create(new *types.User) (u *types.User, err error) {
// when creating user like this
new.EmailConfirmed = true
if err = svc.store.CreateUser(svc.ctx, new); err != nil {
if err = store.CreateUser(svc.ctx, svc.store, new); err != nil {
return
}
@@ -374,7 +374,7 @@ func (svc user) Update(upd *types.User) (u *types.User, err error) {
return UserErrInvalidEmail()
}
if u, err = svc.store.LookupUserByID(svc.ctx, upd.ID); err != nil {
if u, err = store.LookupUserByID(svc.ctx, svc.store, upd.ID); err != nil {
return
}
@@ -402,7 +402,7 @@ func (svc user) Update(upd *types.User) (u *types.User, err error) {
return
}
if err = svc.store.UpdateUser(svc.ctx, u); err != nil {
if err = store.UpdateUser(svc.ctx, svc.store, u); err != nil {
return
}
@@ -446,7 +446,7 @@ func (svc user) UniqueCheck(u *types.User) (err error) {
f.Handle = u.Handle
}
set, _, err := svc.store.SearchUsers(svc.ctx, f)
set, _, err := store.SearchUsers(svc.ctx, svc.store, f)
if err != nil || len(set) > 1 {
// In case of error or multiple users returned
return false
@@ -486,7 +486,7 @@ func (svc user) Delete(userID uint64) (err error) {
return UserErrInvalidID()
}
if u, err = svc.store.LookupUserByID(svc.ctx, userID); err != nil {
if u, err = store.LookupUserByID(svc.ctx, svc.store, userID); err != nil {
return
}
@@ -499,7 +499,7 @@ func (svc user) Delete(userID uint64) (err error) {
}
u.DeletedAt = nowPtr()
if err = svc.store.UpdateUser(svc.ctx, u); err != nil {
if err = store.UpdateUser(svc.ctx, svc.store, u); err != nil {
return
}
@@ -521,7 +521,7 @@ func (svc user) Undelete(userID uint64) (err error) {
return UserErrInvalidID()
}
if u, err = svc.store.LookupUserByID(svc.ctx, userID); err != nil {
if u, err = store.LookupUserByID(svc.ctx, svc.store, userID); err != nil {
return
}
@@ -536,7 +536,7 @@ func (svc user) Undelete(userID uint64) (err error) {
}
u.DeletedAt = nil
if err = svc.store.UpdateUser(svc.ctx, u); err != nil {
if err = store.UpdateUser(svc.ctx, svc.store, u); err != nil {
return
}
@@ -558,7 +558,7 @@ func (svc user) Suspend(userID uint64) (err error) {
return UserErrInvalidID()
}
if u, err = svc.store.LookupUserByID(svc.ctx, userID); err != nil {
if u, err = store.LookupUserByID(svc.ctx, svc.store, userID); err != nil {
return
}
@@ -569,7 +569,7 @@ func (svc user) Suspend(userID uint64) (err error) {
}
u.SuspendedAt = nowPtr()
if err = svc.store.UpdateUser(svc.ctx, u); err != nil {
if err = store.UpdateUser(svc.ctx, svc.store, u); err != nil {
return
}
@@ -591,7 +591,7 @@ func (svc user) Unsuspend(userID uint64) (err error) {
return UserErrInvalidID()
}
if u, err = svc.store.LookupUserByID(svc.ctx, userID); err != nil {
if u, err = store.LookupUserByID(svc.ctx, svc.store, userID); err != nil {
return
}
@@ -602,7 +602,7 @@ func (svc user) Unsuspend(userID uint64) (err error) {
}
u.SuspendedAt = nil
if err = svc.store.UpdateUser(svc.ctx, u); err != nil {
if err = store.UpdateUser(svc.ctx, svc.store, u); err != nil {
return
}
return nil
@@ -622,7 +622,7 @@ func (svc user) SetPassword(userID uint64, newPassword string) (err error) {
)
err = func() error {
if u, err = svc.store.LookupUserByID(svc.ctx, userID); err != nil {
if u, err = store.LookupUserByID(svc.ctx, svc.store, userID); err != nil {
return err
}