Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
corteza
corteza-server
Commits
4cef8eec
Commit
4cef8eec
authored
4 years ago
by
Denis Arh
Browse files
Options
Download
Email Patches
Plain Diff
Tidy up id.Next() and time.Now() use
parent
3a7cc105
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
93 additions
and
97 deletions
+93
-97
compose/service/attachment.go
compose/service/attachment.go
+2
-3
compose/service/chart.go
compose/service/chart.go
+4
-5
compose/service/chart_test.go
compose/service/chart_test.go
+2
-3
compose/service/import_session.go
compose/service/import_session.go
+1
-2
compose/service/module.go
compose/service/module.go
+9
-10
compose/service/namespace.go
compose/service/namespace.go
+2
-2
compose/service/page.go
compose/service/page.go
+2
-2
compose/service/record.go
compose/service/record.go
+5
-6
compose/service/service.go
compose/service/service.go
+12
-5
compose/service/values/shared.go
compose/service/values/shared.go
+0
-5
messaging/service/attachment.go
messaging/service/attachment.go
+2
-3
messaging/service/channel.go
messaging/service/channel.go
+2
-3
messaging/service/message.go
messaging/service/message.go
+2
-3
messaging/service/service.go
messaging/service/service.go
+12
-5
store/tests/attachments_test.go
store/tests/attachments_test.go
+1
-1
system/service/application.go
system/service/application.go
+3
-3
system/service/attachment.go
system/service/attachment.go
+2
-3
system/service/auth.go
system/service/auth.go
+19
-20
system/service/auth_test.go
system/service/auth_test.go
+7
-8
system/service/reminder.go
system/service/reminder.go
+4
-5
No files found.
compose/service/attachment.go
View file @
4cef8eec
...
...
@@ -6,7 +6,6 @@ import (
"github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/pkg/objstore"
"github.com/cortezaproject/corteza-server/store"
"github.com/disintegration/imaging"
...
...
@@ -155,7 +154,7 @@ func (svc attachment) DeleteByID(namespaceID, attachmentID uint64) (err error) {
aProps
.
setAttachment
(
att
)
att
.
DeletedAt
=
now
Ptr
()
att
.
DeletedAt
=
now
()
return
store
.
UpdateComposeAttachment
(
ctx
,
s
,
att
)
})
...
...
@@ -348,7 +347,7 @@ func (svc attachment) create(name string, size int64, fh io.ReadSeeker, att *typ
)
// preset attachment ID because we need ref for storage
att
.
ID
=
id
.
N
ext
()
att
.
ID
=
n
ext
ID
()
if
att
.
OwnerID
==
0
{
att
.
OwnerID
=
auth
.
GetIdentityFromContext
(
svc
.
ctx
)
.
Identity
()
...
...
This diff is collapsed.
Click to expand it.
compose/service/chart.go
View file @
4cef8eec
...
...
@@ -6,7 +6,6 @@ import (
"github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
"github.com/cortezaproject/corteza-server/pkg/handle"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/store"
)
...
...
@@ -132,8 +131,8 @@ func (svc chart) Create(new *types.Chart) (*types.Chart, error) {
return
ChartErrNotAllowedToCreate
()
}
new
.
ID
=
id
.
N
ext
()
new
.
CreatedAt
=
*
now
Ptr
()
new
.
ID
=
n
ext
ID
()
new
.
CreatedAt
=
*
now
()
new
.
UpdatedAt
=
nil
new
.
DeletedAt
=
nil
...
...
@@ -249,7 +248,7 @@ func (svc chart) handleUpdate(upd *types.Chart) chartUpdateHandler {
c
.
Name
=
upd
.
Name
c
.
Handle
=
upd
.
Handle
c
.
Config
=
upd
.
Config
c
.
UpdatedAt
=
now
Ptr
()
c
.
UpdatedAt
=
now
()
return
true
,
nil
}
}
...
...
@@ -264,7 +263,7 @@ func (svc chart) handleDelete(ctx context.Context, ns *types.Namespace, c *types
return
false
,
nil
}
c
.
DeletedAt
=
now
Ptr
()
c
.
DeletedAt
=
now
()
return
true
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
compose/service/chart_test.go
View file @
4cef8eec
...
...
@@ -4,7 +4,6 @@ import (
"context"
"errors"
"github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/pkg/permissions"
"github.com/cortezaproject/corteza-server/store"
"github.com/cortezaproject/corteza-server/store/sqlite3"
...
...
@@ -18,7 +17,7 @@ func TestCharts(t *testing.T) {
ctx
=
context
.
Background
()
s
,
err
=
sqlite3
.
ConnectInMemory
(
ctx
)
namespaceID
=
id
.
N
ext
()
namespaceID
=
n
ext
ID
()
ns
*
types
.
Namespace
)
...
...
@@ -43,7 +42,7 @@ func TestCharts(t *testing.T) {
t
.
Fatalf
(
"failed to truncate compose charts: %v"
,
err
)
}
ns
=
&
types
.
Namespace
{
Name
:
"testing"
,
ID
:
namespaceID
,
CreatedAt
:
*
now
Ptr
()}
ns
=
&
types
.
Namespace
{
Name
:
"testing"
,
ID
:
namespaceID
,
CreatedAt
:
*
now
()}
if
err
=
store
.
CreateComposeNamespace
(
ctx
,
s
,
ns
);
err
!=
nil
{
t
.
Fatalf
(
"failed to seed namespaces: %v"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
compose/service/import_session.go
View file @
4cef8eec
...
...
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/id"
"sync"
"time"
)
...
...
@@ -64,7 +63,7 @@ func (svc *importSession) SetByID(ctx context.Context, sessionID, namespaceID, m
ris
=
svc
.
records
[
i
]
}
else
{
ris
=
&
RecordImportSession
{
SessionID
:
id
.
N
ext
(),
SessionID
:
n
ext
ID
(),
CreatedAt
:
time
.
Now
(),
}
svc
.
records
=
append
(
svc
.
records
,
ris
)
...
...
This diff is collapsed.
Click to expand it.
compose/service/module.go
View file @
4cef8eec
...
...
@@ -10,7 +10,6 @@ import (
"github.com/cortezaproject/corteza-server/pkg/eventbus"
"github.com/cortezaproject/corteza-server/pkg/filter"
"github.com/cortezaproject/corteza-server/pkg/handle"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/store"
"sort"
"strconv"
...
...
@@ -187,15 +186,15 @@ func (svc module) Create(new *types.Module) (*types.Module, error) {
return
err
}
new
.
ID
=
id
.
N
ext
()
new
.
CreatedAt
=
*
now
Ptr
()
new
.
ID
=
n
ext
ID
()
new
.
CreatedAt
=
*
now
()
new
.
UpdatedAt
=
nil
new
.
DeletedAt
=
nil
if
new
.
Fields
!=
nil
{
_
=
new
.
Fields
.
Walk
(
func
(
f
*
types
.
ModuleField
)
error
{
f
.
ModuleID
=
new
.
ID
f
.
CreatedAt
=
*
now
Ptr
()
f
.
CreatedAt
=
*
now
()
f
.
UpdatedAt
=
nil
f
.
DeletedAt
=
nil
return
nil
...
...
@@ -387,7 +386,7 @@ func (svc module) handleUpdate(upd *types.Module) moduleUpdateHandler {
}
if
mch
{
m
.
UpdatedAt
=
now
Ptr
()
m
.
UpdatedAt
=
now
()
}
// for now, we assume that
...
...
@@ -405,7 +404,7 @@ func (svc module) handleDelete(ctx context.Context, ns *types.Namespace, m *type
return
false
,
false
,
nil
}
m
.
DeletedAt
=
now
Ptr
()
m
.
DeletedAt
=
now
()
return
true
,
false
,
nil
}
...
...
@@ -449,7 +448,7 @@ func updateModuleFields(ctx context.Context, s store.Storer, m *types.Module, ne
continue
}
ef
.
DeletedAt
=
now
Ptr
()
ef
.
DeletedAt
=
now
()
err
=
store
.
UpdateComposeModuleField
(
ctx
,
s
,
ef
)
if
err
!=
nil
{
return
err
...
...
@@ -471,12 +470,12 @@ func updateModuleFields(ctx context.Context, s store.Storer, m *types.Module, ne
f
.
Kind
=
e
.
Kind
}
f
.
UpdatedAt
=
now
Ptr
()
f
.
UpdatedAt
=
now
()
err
=
store
.
UpdateComposeModuleField
(
ctx
,
s
,
f
)
}
else
{
f
.
ID
=
id
.
N
ext
()
f
.
CreatedAt
=
*
now
Ptr
()
f
.
ID
=
n
ext
ID
()
f
.
CreatedAt
=
*
now
()
err
=
store
.
CreateComposeModuleField
(
ctx
,
s
,
f
)
}
...
...
This diff is collapsed.
Click to expand it.
compose/service/namespace.go
View file @
4cef8eec
...
...
@@ -293,7 +293,7 @@ func (svc namespace) handleUpdate(upd *types.Namespace) namespaceUpdateHandler {
ns
.
Slug
=
upd
.
Slug
ns
.
Meta
=
upd
.
Meta
ns
.
Enabled
=
upd
.
Enabled
ns
.
UpdatedAt
=
now
Ptr
()
ns
.
UpdatedAt
=
now
()
return
true
,
nil
}
...
...
@@ -309,7 +309,7 @@ func (svc namespace) handleDelete(ctx context.Context, ns *types.Namespace) (boo
return
false
,
nil
}
ns
.
DeletedAt
=
now
Ptr
()
ns
.
DeletedAt
=
now
()
return
true
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
compose/service/page.go
View file @
4cef8eec
...
...
@@ -409,7 +409,7 @@ func (svc page) handleUpdate(upd *types.Page) pageUpdateHandler {
p
.
Description
=
upd
.
Description
p
.
Visible
=
upd
.
Visible
p
.
Weight
=
upd
.
Weight
p
.
UpdatedAt
=
now
Ptr
()
p
.
UpdatedAt
=
now
()
return
true
,
nil
}
...
...
@@ -425,7 +425,7 @@ func (svc page) handleDelete(ctx context.Context, ns *types.Namespace, m *types.
return
false
,
nil
}
m
.
DeletedAt
=
now
Ptr
()
m
.
DeletedAt
=
now
()
return
true
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
compose/service/record.go
View file @
4cef8eec
...
...
@@ -12,7 +12,6 @@ import (
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/corredor"
"github.com/cortezaproject/corteza-server/pkg/eventbus"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/store"
"regexp"
"strconv"
...
...
@@ -684,9 +683,9 @@ func (svc record) procCreate(ctx context.Context, s store.Storer, invokerID uint
// Reset values to new record
// to make sure nobody slips in something we do not want
new
.
ID
=
id
.
N
ext
()
new
.
ID
=
n
ext
ID
()
new
.
CreatedBy
=
invokerID
new
.
CreatedAt
=
*
now
Ptr
()
new
.
CreatedAt
=
*
now
()
new
.
UpdatedAt
=
nil
new
.
UpdatedBy
=
0
new
.
DeletedAt
=
nil
...
...
@@ -738,7 +737,7 @@ func (svc record) procUpdate(ctx context.Context, s store.Storer, invokerID uint
// to make sure nobody slips in something we do not want
upd
.
CreatedAt
=
old
.
CreatedAt
upd
.
CreatedBy
=
old
.
CreatedBy
upd
.
UpdatedAt
=
now
Ptr
()
upd
.
UpdatedAt
=
now
()
upd
.
UpdatedBy
=
invokerID
upd
.
DeletedAt
=
old
.
DeletedAt
upd
.
DeletedBy
=
old
.
DeletedBy
...
...
@@ -805,7 +804,7 @@ func (svc record) delete(namespaceID, moduleID, recordID uint64) (del *types.Rec
}
}
del
.
DeletedAt
=
now
Ptr
()
del
.
DeletedAt
=
now
()
del
.
DeletedBy
=
invokerID
err
=
store
.
Tx
(
svc
.
ctx
,
svc
.
store
,
func
(
ctx
context
.
Context
,
s
store
.
Storer
)
error
{
...
...
@@ -1193,7 +1192,7 @@ func (svc record) Iterator(f types.RecordFilter, fn eventbus.HandlerFn, action s
recordableAction
=
RecordActionIteratorDelete
return
store
.
Tx
(
svc
.
ctx
,
svc
.
store
,
func
(
ctx
context
.
Context
,
s
store
.
Storer
)
error
{
rec
.
DeletedAt
=
now
Ptr
()
rec
.
DeletedAt
=
now
()
rec
.
DeletedBy
=
invokerID
return
store
.
UpdateComposeRecord
(
ctx
,
s
,
m
,
rec
)
})
...
...
This diff is collapsed.
Click to expand it.
compose/service/service.go
View file @
4cef8eec
...
...
@@ -9,6 +9,7 @@ import (
"github.com/cortezaproject/corteza-server/pkg/corredor"
"github.com/cortezaproject/corteza-server/pkg/eventbus"
"github.com/cortezaproject/corteza-server/pkg/healthcheck"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/pkg/objstore"
"github.com/cortezaproject/corteza-server/pkg/objstore/minio"
"github.com/cortezaproject/corteza-server/pkg/objstore/plain"
...
...
@@ -72,6 +73,17 @@ var (
DefaultSystemUser
systemService
.
UserService
//DefaultSystemUser *systemUser
//DefaultSystemRole *systemRole
// wrapper around time.Now() that will aid service testing
now
=
func
()
*
time
.
Time
{
c
:=
time
.
Now
()
return
&
c
}
// wrapper around nextID that will aid service testing
nextID
=
func
()
uint64
{
return
id
.
Next
()
}
)
// Initializes compose-only services
...
...
@@ -225,11 +237,6 @@ func isStale(new *time.Time, updatedAt *time.Time, createdAt time.Time) bool {
return
new
.
Equal
(
createdAt
)
}
func
nowPtr
()
*
time
.
Time
{
now
:=
time
.
Now
()
return
&
now
}
// trim1st removes 1st param and returns only error
func
trim1st
(
_
interface
{},
err
error
)
error
{
return
err
...
...
This diff is collapsed.
Click to expand it.
compose/service/values/shared.go
View file @
4cef8eec
...
...
@@ -36,8 +36,3 @@ var (
isoDaty
=
regexp
.
MustCompile
(
`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}`
)
hasTimezone
=
regexp
.
MustCompile
(
`(Z|\+\d{2}:\d{2})$`
)
)
func
nowPtr
()
*
time
.
Time
{
now
:=
time
.
Now
()
return
&
now
}
This diff is collapsed.
Click to expand it.
messaging/service/attachment.go
View file @
4cef8eec
...
...
@@ -8,7 +8,6 @@ import (
"github.com/cortezaproject/corteza-server/messaging/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
intAuth
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/id"
files
"github.com/cortezaproject/corteza-server/pkg/objstore"
"github.com/cortezaproject/corteza-server/store"
"github.com/disintegration/imaging"
...
...
@@ -117,7 +116,7 @@ func (svc attachment) CreateMessageAttachment(name string, size int64, fh io.Rea
}
att
=
&
types
.
Attachment
{
ID
:
id
.
N
ext
(),
ID
:
n
ext
ID
(),
OwnerID
:
currentUserID
,
Name
:
strings
.
TrimSpace
(
name
),
CreatedAt
:
*
now
(),
...
...
@@ -133,7 +132,7 @@ func (svc attachment) CreateMessageAttachment(name string, size int64, fh io.Rea
}
msg
:=
&
types
.
Message
{
ID
:
id
.
N
ext
(),
ID
:
n
ext
ID
(),
Attachment
:
att
,
Message
:
name
,
Type
:
types
.
MessageTypeAttachment
,
...
...
This diff is collapsed.
Click to expand it.
messaging/service/channel.go
View file @
4cef8eec
...
...
@@ -7,7 +7,6 @@ import (
"github.com/cortezaproject/corteza-server/messaging/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/store"
)
...
...
@@ -317,7 +316,7 @@ func (svc *channel) Create(new *types.Channel) (ch *types.Channel, err error) {
// This is a fresh channel, just copy values
ch
=
&
types
.
Channel
{
ID
:
id
.
N
ext
(),
ID
:
n
ext
ID
(),
Name
:
new
.
Name
,
Topic
:
new
.
Topic
,
Type
:
new
.
Type
,
...
...
@@ -968,7 +967,7 @@ func (svc *channel) flushSystemMessages() (err error) {
}()
return
svc
.
sysmsgs
.
Walk
(
func
(
msg
*
types
.
Message
)
error
{
msg
.
ID
=
id
.
N
ext
()
msg
.
ID
=
n
ext
ID
()
msg
.
CreatedAt
=
*
now
()
if
err
=
store
.
CreateMessagingMessage
(
svc
.
ctx
,
svc
.
store
,
msg
);
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
messaging/service/message.go
View file @
4cef8eec
...
...
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/cortezaproject/corteza-server/messaging/types"
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/pkg/payload"
"github.com/cortezaproject/corteza-server/store"
"io"
...
...
@@ -142,7 +141,7 @@ func (svc message) readableChannels(f types.MessageFilter) ([]uint64, error) {
}
func
(
svc
message
)
Create
(
msg
*
types
.
Message
)
(
*
types
.
Message
,
error
)
{
msg
.
ID
=
id
.
N
ext
()
msg
.
ID
=
n
ext
ID
()
msg
.
CreatedAt
=
*
now
()
msg
.
Message
=
strings
.
TrimSpace
(
msg
.
Message
)
...
...
@@ -594,7 +593,7 @@ func (svc message) flag(messageID uint64, flag string, remove bool) (err error)
}
else
{
ff
=
[]
*
types
.
MessageFlag
{
{
ID
:
id
.
N
ext
(),
ID
:
n
ext
ID
(),
UserID
:
currentUserID
,
CreatedAt
:
*
now
(),
ChannelID
:
msg
.
ChannelID
,
...
...
This diff is collapsed.
Click to expand it.
messaging/service/service.go
View file @
4cef8eec
...
...
@@ -4,6 +4,7 @@ import (
"context"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
"github.com/cortezaproject/corteza-server/pkg/healthcheck"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/pkg/objstore"
"github.com/cortezaproject/corteza-server/pkg/objstore/minio"
"github.com/cortezaproject/corteza-server/pkg/objstore/plain"
...
...
@@ -51,6 +52,17 @@ var (
DefaultMessage
MessageService
DefaultEvent
EventService
DefaultCommand
CommandService
// wrapper around time.Now() that will aid service testing
now
=
func
()
*
time
.
Time
{
c
:=
time
.
Now
()
return
&
c
}
// wrapper around nextID that will aid service testing
nextID
=
func
()
uint64
{
return
id
.
Next
()
}
)
func
Initialize
(
ctx
context
.
Context
,
log
*
zap
.
Logger
,
s
store
.
Storer
,
c
Config
)
(
err
error
)
{
...
...
@@ -140,8 +152,3 @@ func Activate(ctx context.Context) (err error) {
func
Watchers
(
ctx
context
.
Context
)
{
DefaultPermissions
.
Watch
(
ctx
)
}
func
now
()
*
time
.
Time
{
now
:=
time
.
Now
()
return
&
now
}
This diff is collapsed.
Click to expand it.
store/tests/attachments_test.go
View file @
4cef8eec
...
...
@@ -3,9 +3,9 @@ package tests
import
(
"context"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/pkg/rand"
"github.com/cortezaproject/corteza-server/store"
"github.com/cortezaproject/corteza-server/system/types"
"github.com/cortezaproject/corteza-server/pkg/rand"
_
"github.com/joho/godotenv/autoload"
"github.com/stretchr/testify/require"
"strings"
...
...
This diff is collapsed.
Click to expand it.
system/service/application.go
View file @
4cef8eec
...
...
@@ -106,7 +106,7 @@ func (svc *application) Create(ctx context.Context, new *types.Application) (app
// Set new values after beforeCreate events are emitted
new
.
ID
=
nextID
()
new
.
CreatedAt
=
now
()
new
.
CreatedAt
=
*
now
()
if
new
.
Unify
==
nil
{
new
.
Unify
=
&
types
.
ApplicationUnify
{}
...
...
@@ -152,7 +152,7 @@ func (svc *application) Update(ctx context.Context, upd *types.Application) (app
// Assign changed values after afterUpdate events are emitted
app
.
Name
=
upd
.
Name
app
.
Enabled
=
upd
.
Enabled
app
.
UpdatedAt
=
now
Ptr
()
app
.
UpdatedAt
=
now
()
if
upd
.
Unify
!=
nil
{
app
.
Unify
=
upd
.
Unify
...
...
@@ -194,7 +194,7 @@ func (svc *application) Delete(ctx context.Context, ID uint64) (err error) {
return
}
app
.
DeletedAt
=
now
Ptr
()
app
.
DeletedAt
=
now
()
if
err
=
store
.
UpdateApplication
(
ctx
,
svc
.
store
,
app
);
err
!=
nil
{
return
}
...
...
This diff is collapsed.
Click to expand it.
system/service/attachment.go
View file @
4cef8eec
...
...
@@ -5,7 +5,6 @@ import (
"context"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
intAuth
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/id"
files
"github.com/cortezaproject/corteza-server/pkg/objstore"
"github.com/cortezaproject/corteza-server/store"
"github.com/cortezaproject/corteza-server/system/types"
...
...
@@ -108,7 +107,7 @@ func (svc attachment) DeleteByID(ID uint64) (err error) {
return
err
}
att
.
DeletedAt
=
now
Ptr
()
att
.
DeletedAt
=
now
()
aaProps
.
setAttachment
(
att
)
return
store
.
UpdateAttachment
(
svc
.
ctx
,
svc
.
store
,
att
)
...
...
@@ -158,7 +157,7 @@ func (svc attachment) CreateSettingsAttachment(name string, size int64, fh io.Re
}
att
=
&
types
.
Attachment
{
ID
:
id
.
N
ext
(),
ID
:
n
ext
ID
(),
OwnerID
:
currentUserID
,
Name
:
strings
.
TrimSpace
(
name
),
Kind
:
types
.
AttachmentKindSettings
,
...
...
This diff is collapsed.
Click to expand it.
system/service/auth.go
View file @
4cef8eec
...
...
@@ -8,7 +8,6 @@ import (
internalAuth
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/eventbus"
"github.com/cortezaproject/corteza-server/pkg/handle"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/pkg/permissions"
"github.com/cortezaproject/corteza-server/pkg/rand"
"github.com/cortezaproject/corteza-server/store"
...
...
@@ -154,7 +153,7 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
if
u
.
Valid
()
{
// Valid user, Bingo!
c
.
LastUsedAt
=
now
Ptr
()
c
.
LastUsedAt
=
now
()
if
err
=
store
.
UpdateCredentials
(
ctx
,
svc
.
store
,
c
);
err
!=
nil
{
return
err
}
...
...
@@ -214,8 +213,8 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
createHandle
(
ctx
,
svc
.
store
,
u
)
}
u
.
ID
=
id
.
N
ext
()
u
.
CreatedAt
=
now
()
u
.
ID
=
n
ext
ID
()
u
.
CreatedAt
=
*
now
()
if
err
=
store
.
CreateUser
(
ctx
,
svc
.
store
,
u
);
err
!=
nil
{
return
err
}
...
...
@@ -255,12 +254,12 @@ func (svc auth) External(ctx context.Context, profile goth.User) (u *types.User,
// If we got to this point, assume that user is authenticated
// but credentials need to be stored
c
:=
&
types
.
Credentials
{
ID
:
id
.
N
ext
(),
CreatedAt
:
now
(),
ID
:
n
ext
ID
(),
CreatedAt
:
*
now
(),
Kind
:
profile
.
Provider
,
OwnerID
:
u
.
ID
,
Credentials
:
profile
.
UserID
,
LastUsedAt
:
now
Ptr
(),
LastUsedAt
:
now
(),
}
if
err
=
store
.
CreateCredentials
(
ctx
,
svc
.
store
,
c
);
err
!=
nil
{
...
...
@@ -331,8 +330,8 @@ func (svc auth) InternalSignUp(ctx context.Context, input *types.User, password
return
AuthErrInvalidCredentials
(
aam
)
}
else
{
// Update last-used-by timestamp on matching credentials
c
.
LastUsedAt
=
now
Ptr
()
c
.
UpdatedAt
=
now
Ptr
()
c
.
LastUsedAt
=
now
()
c
.
UpdatedAt
=
now
()
aam
.
setCredentials
(
c
)
if
err
=
store
.
UpdateCredentials
(
ctx
,
svc
.
store
,
c
);
err
!=
nil
{
...
...
@@ -377,7 +376,7 @@ func (svc auth) InternalSignUp(ctx context.Context, input *types.User, password
}
var
nUser
=
&
types
.
User
{
ID
:
id
.
N
ext
(),
ID
:
n
ext
ID
(),
Email
:
input
.
Email
,
Name
:
input
.
Name
,
Username
:
input
.
Username
,
...
...
@@ -483,8 +482,8 @@ func (svc auth) InternalLogin(ctx context.Context, email string, password string
return
AuthErrInvalidCredentials
(
aam
)
}
else
{
// Update last-used-by timestamp on matching credentials
c
.
UpdatedAt
=
now
Ptr
()
c
.
LastUsedAt
=
now
Ptr
()
c
.
UpdatedAt
=
now
()
c
.
LastUsedAt
=
now
()
aam
.
setCredentials
(
c
)
if
err
=
store
.
UpdateCredentials
(
ctx
,
svc
.
store
,
c
);
err
!=
nil
{
...
...
@@ -664,7 +663,7 @@ func (svc auth) SetPasswordCredentials(ctx context.Context, userID uint64, passw
// Mark all credentials as deleted
_
=
cc
.
Walk
(
func
(
c
*
types
.
Credentials
)
error
{
c
.
DeletedAt
=
now
Ptr
()
c
.
DeletedAt
=
now
()
return
nil
})
...
...
@@ -675,8 +674,8 @@ func (svc auth) SetPasswordCredentials(ctx context.Context, userID uint64, passw
// Add new credentials with new password
c
:=
&
types
.
Credentials
{
ID
:
id
.
N
ext
(),
CreatedAt
:
now
(),
ID
:
n
ext
ID
(),
CreatedAt
:
*
now
(),
OwnerID
:
userID
,
Kind
:
credentialsTypePassword
,
Credentials
:
string
(
hash
),
...
...
@@ -747,7 +746,7 @@ func (svc auth) loadFromTokenAndConfirmEmail(ctx context.Context, token, tokenTy
}
u
.
EmailConfirmed
=
true
u
.
UpdatedAt
=
now
Ptr
()
u
.
UpdatedAt
=
now
()
if
err
=
store
.
UpdateUser
(
ctx
,
svc
.
store
,
u
);
err
!=
nil
{
return
err
}
...
...
@@ -979,15 +978,15 @@ func (svc auth) createUserToken(ctx context.Context, u *types.User, kind string)
switch
kind
{
case
credentialsTypeAuthToken
:
// 15 sec expiration for all tokens that are part of redirection
expiresAt
=
now
Ptr
()
.
Add
(
time
.
Second
*
15
)
expiresAt
=
now
()
.
Add
(
time
.
Second
*
15
)
default
:
// 1h expiration for all tokens send via email
expiresAt
=
now
Ptr
()
.
Add
(
time
.
Minute
*
60
)
expiresAt
=
now
()
.
Add
(
time
.
Minute
*
60
)
}
c
:=
&
types
.
Credentials
{
ID
:
id
.
N
ext
(),
CreatedAt
:
now
(),
ID
:
n
ext
ID
(),
CreatedAt
:
*
now
(),
OwnerID
:
u
.
ID
,
Kind
:
kind
,
Credentials
:
string
(
rand
.
Bytes
(
credentialsTokenLength
)),
...
...
This diff is collapsed.
Click to expand it.
system/service/auth_test.go
View file @
4cef8eec
...
...
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"github.com/cortezaproject/corteza-server/pkg/eventbus"
"github.com/cortezaproject/corteza-server/pkg/id"
"github.com/cortezaproject/corteza-server/store"
"github.com/cortezaproject/corteza-server/store/sqlite3"
"github.com/cortezaproject/corteza-server/system/types"
...
...
@@ -55,15 +54,15 @@ func TestAuth_External(t *testing.T) {
ctx
=
context
.
Background
()
// Create some virtual user and credentials
validUser
=
&
types
.
User
{
Email
:
"valid@test.cortezaproject.org"
,
ID
:
id
.
N
ext
(),
CreatedAt
:
now
()}
suspendedUser
=
&
types
.
User
{
Email
:
"suspended@test.cortezaproject.org"
,
ID
:
id
.
N
ext
(),
CreatedAt
:
now
(),
SuspendedAt
:
now
Ptr
()}
validUser
=
&
types
.
User
{
Email
:
"valid@test.cortezaproject.org"
,
ID
:
n
ext
ID
(),
CreatedAt
:
*
now
()}
suspendedUser
=
&
types
.
User
{
Email
:
"suspended@test.cortezaproject.org"
,
ID
:
n
ext
ID
(),
CreatedAt
:
*
now
(),
SuspendedAt
:
now
()}
freshProfileID
=
func
()
string
{
return
fmt
.
Sprintf
(
"fresh-profile-id-%d"
,
id
.
N
ext
())
return
fmt
.
Sprintf
(
"fresh-profile-id-%d"
,
n
ext
ID
())
}
fooCredentials
=
&
types
.
Credentials
{
ID
:
id
.
N
ext
(),
ID
:
n
ext
ID
(),
OwnerID
:
validUser
.
ID
,
Label
:
"credentials for foo provider"
,
Kind
:
"foo"
,
...
...
@@ -72,7 +71,7 @@ func TestAuth_External(t *testing.T) {
}
barCredentials
=
&
types
.
Credentials
{
ID
:
id
.
N
ext
(),
ID
:
n
ext
ID
(),
OwnerID
:
validUser
.
ID
,
Label
:
"credentials for bar provider"
,
Kind
:
"bar"
,
...
...
@@ -146,8 +145,8 @@ func TestAuth_InternalLogin(t *testing.T) {
ctx
=
context
.
Background
()
validPass
=
"this is a valid password !! 42"
validUser
=
&
types
.
User
{
Email
:
"valid@test.cortezaproject.org"
,
ID
:
id
.
N
ext
(),
CreatedAt
:
now
(),
EmailConfirmed
:
true
}
suspendedUser
=
&
types
.
User
{
Email
:
"suspended@test.cortezaproject.org"
,
ID
:
id
.
N
ext
(),
CreatedAt
:
now
(),
SuspendedAt
:
now
Ptr
()}
validUser
=
&
types
.
User
{
Email
:
"valid@test.cortezaproject.org"
,
ID
:
n
ext
ID
(),
CreatedAt
:
*
now
(),
EmailConfirmed
:
true
}
suspendedUser
=
&
types
.
User
{
Email
:
"suspended@test.cortezaproject.org"
,
ID
:
n
ext
ID
(),
CreatedAt
:
*
now
(),
SuspendedAt
:
now
()}
tests
=
[]
struct
{
name
string
...
...
This diff is collapsed.
Click to expand it.
system/service/reminder.go
View file @
4cef8eec
...
...
@@ -4,7 +4,6 @@ import (
"context"
"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/store"
"github.com/cortezaproject/corteza-server/system/types"
"time"
...
...
@@ -119,8 +118,8 @@ func (svc reminder) Create(ctx context.Context, new *types.Reminder) (r *types.R
return
err
}
r
.
ID
=
id
.
N
ext
()
r
.
CreatedAt
=
now
()
r
.
ID
=
n
ext
ID
()
r
.
CreatedAt
=
*
now
()
if
err
=
store
.
CreateReminder
(
ctx
,
svc
.
store
,
new
);
err
!=
nil
{
return
err
...
...
@@ -161,7 +160,7 @@ func (svc reminder) Update(ctx context.Context, upd *types.Reminder) (r *types.R
r
.
Payload
=
upd
.
Payload
r
.
RemindAt
=
upd
.
RemindAt
r
.
Resource
=
upd
.
Resource
r
.
UpdatedAt
=
now
Ptr
()
r
.
UpdatedAt
=
now
()
if
err
=
store
.
UpdateReminder
(
ctx
,
svc
.
store
,
r
);
err
!=
nil
{
return
err
...
...
@@ -254,7 +253,7 @@ func (svc reminder) Delete(ctx context.Context, ID uint64) (err error) {
return
ReminderErrNotFound
()
}
r
.
DeletedAt
=
now
Ptr
()
r
.
DeletedAt
=
now
()
raProps
.
setReminder
(
r
)
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment