diff --git a/README.md b/README.md index 3542138..cab710c 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Once you are done with your changes run `go generate` in the changed packages to ## Tooling ### Mocks -[`counterfeiter`](https://github.com/maxbrunsfeld/counterfeiter) enables generating mocks for defined interfaces. To update the mocks, run `go generate` in package admindb. +[`counterfeiter`](https://github.com/maxbrunsfeld/counterfeiter) enables generating mocks for defined interfaces. To update the mocks, run `go generate` in package roomdb. * TODO: setup tool as dependency (no manual install) ### Database schema diff --git a/cmd/insert-user/main.go b/cmd/insert-user/main.go index 4b2a2b3..124abbf 100644 --- a/cmd/insert-user/main.go +++ b/cmd/insert-user/main.go @@ -12,7 +12,7 @@ import ( _ "github.com/mattn/go-sqlite3" "golang.org/x/crypto/ssh/terminal" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/sqlite" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" ) diff --git a/cmd/server/main.go b/cmd/server/main.go index 448188d..bd0d3cf 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -29,7 +29,7 @@ import ( "github.com/unrolled/secure" "go.cryptoscope.co/muxrpc/v2/debug" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/sqlite" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" "github.com/ssb-ngi-pointer/go-ssb-room/roomsrv" mksrv "github.com/ssb-ngi-pointer/go-ssb-room/roomsrv" diff --git a/admindb/interface.go b/roomdb/interface.go similarity index 94% rename from admindb/interface.go rename to roomdb/interface.go index ce7b6c9..a14ecf6 100644 --- a/admindb/interface.go +++ b/roomdb/interface.go @@ -1,14 +1,14 @@ // SPDX-License-Identifier: MIT -// Package admindb implements all the persisted database needs of the room server. +// Package roomdb implements all the persisted database needs of the room server. // This includes authentication, allow/deny list managment, invite and alias creation and also the notice content for the CMS. // // The interfaces defined here are implemented twice. Once in SQLite for production and once as mocks for testing, generated by counterfeiter (https://github.com/maxbrunsfeld/counterfeiter). // -// See the package documentation of admindb/sqlite for how to update it. +// See the package documentation of roomdb/sqlite for how to update it. // It's important not to use the types generated by sqlboiler (sqlite/models) in the argument and return values of the interfaces here. -// This would leak details of the internal implementation of the admindb/sqlite package and we want to have full control over how these interfaces can be used. -package admindb +// This would leak details of the internal implementation of the roomdb/sqlite package and we want to have full control over how these interfaces can be used. +package roomdb import ( "context" diff --git a/admindb/mockdb/alias.go b/roomdb/mockdb/alias.go similarity index 89% rename from admindb/mockdb/alias.go rename to roomdb/mockdb/alias.go index 6bf3b5d..e97baa5 100644 --- a/admindb/mockdb/alias.go +++ b/roomdb/mockdb/alias.go @@ -4,7 +4,7 @@ package mockdb import ( "sync" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) type FakeAliasService struct { @@ -34,4 +34,4 @@ func (fake *FakeAliasService) recordInvocation(key string, args []interface{}) { fake.invocations[key] = append(fake.invocations[key], args) } -var _ admindb.AliasService = new(FakeAliasService) +var _ roomdb.AliasService = new(FakeAliasService) diff --git a/admindb/mockdb/allow.go b/roomdb/mockdb/allow.go similarity index 93% rename from admindb/mockdb/allow.go rename to roomdb/mockdb/allow.go index f089707..6992c81 100644 --- a/admindb/mockdb/allow.go +++ b/roomdb/mockdb/allow.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" refs "go.mindeco.de/ssb-refs" ) @@ -22,18 +22,18 @@ type FakeAllowListService struct { addReturnsOnCall map[int]struct { result1 error } - GetByIDStub func(context.Context, int64) (admindb.ListEntry, error) + GetByIDStub func(context.Context, int64) (roomdb.ListEntry, error) getByIDMutex sync.RWMutex getByIDArgsForCall []struct { arg1 context.Context arg2 int64 } getByIDReturns struct { - result1 admindb.ListEntry + result1 roomdb.ListEntry result2 error } getByIDReturnsOnCall map[int]struct { - result1 admindb.ListEntry + result1 roomdb.ListEntry result2 error } HasFeedStub func(context.Context, refs.FeedRef) bool @@ -60,17 +60,17 @@ type FakeAllowListService struct { hasIDReturnsOnCall map[int]struct { result1 bool } - ListStub func(context.Context) (admindb.ListEntries, error) + ListStub func(context.Context) (roomdb.ListEntries, error) listMutex sync.RWMutex listArgsForCall []struct { arg1 context.Context } listReturns struct { - result1 admindb.ListEntries + result1 roomdb.ListEntries result2 error } listReturnsOnCall map[int]struct { - result1 admindb.ListEntries + result1 roomdb.ListEntries result2 error } RemoveFeedStub func(context.Context, refs.FeedRef) error @@ -163,7 +163,7 @@ func (fake *FakeAllowListService) AddReturnsOnCall(i int, result1 error) { }{result1} } -func (fake *FakeAllowListService) GetByID(arg1 context.Context, arg2 int64) (admindb.ListEntry, error) { +func (fake *FakeAllowListService) GetByID(arg1 context.Context, arg2 int64) (roomdb.ListEntry, error) { fake.getByIDMutex.Lock() ret, specificReturn := fake.getByIDReturnsOnCall[len(fake.getByIDArgsForCall)] fake.getByIDArgsForCall = append(fake.getByIDArgsForCall, struct { @@ -189,7 +189,7 @@ func (fake *FakeAllowListService) GetByIDCallCount() int { return len(fake.getByIDArgsForCall) } -func (fake *FakeAllowListService) GetByIDCalls(stub func(context.Context, int64) (admindb.ListEntry, error)) { +func (fake *FakeAllowListService) GetByIDCalls(stub func(context.Context, int64) (roomdb.ListEntry, error)) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = stub @@ -202,28 +202,28 @@ func (fake *FakeAllowListService) GetByIDArgsForCall(i int) (context.Context, in return argsForCall.arg1, argsForCall.arg2 } -func (fake *FakeAllowListService) GetByIDReturns(result1 admindb.ListEntry, result2 error) { +func (fake *FakeAllowListService) GetByIDReturns(result1 roomdb.ListEntry, result2 error) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = nil fake.getByIDReturns = struct { - result1 admindb.ListEntry + result1 roomdb.ListEntry result2 error }{result1, result2} } -func (fake *FakeAllowListService) GetByIDReturnsOnCall(i int, result1 admindb.ListEntry, result2 error) { +func (fake *FakeAllowListService) GetByIDReturnsOnCall(i int, result1 roomdb.ListEntry, result2 error) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = nil if fake.getByIDReturnsOnCall == nil { fake.getByIDReturnsOnCall = make(map[int]struct { - result1 admindb.ListEntry + result1 roomdb.ListEntry result2 error }) } fake.getByIDReturnsOnCall[i] = struct { - result1 admindb.ListEntry + result1 roomdb.ListEntry result2 error }{result1, result2} } @@ -352,7 +352,7 @@ func (fake *FakeAllowListService) HasIDReturnsOnCall(i int, result1 bool) { }{result1} } -func (fake *FakeAllowListService) List(arg1 context.Context) (admindb.ListEntries, error) { +func (fake *FakeAllowListService) List(arg1 context.Context) (roomdb.ListEntries, error) { fake.listMutex.Lock() ret, specificReturn := fake.listReturnsOnCall[len(fake.listArgsForCall)] fake.listArgsForCall = append(fake.listArgsForCall, struct { @@ -377,7 +377,7 @@ func (fake *FakeAllowListService) ListCallCount() int { return len(fake.listArgsForCall) } -func (fake *FakeAllowListService) ListCalls(stub func(context.Context) (admindb.ListEntries, error)) { +func (fake *FakeAllowListService) ListCalls(stub func(context.Context) (roomdb.ListEntries, error)) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = stub @@ -390,28 +390,28 @@ func (fake *FakeAllowListService) ListArgsForCall(i int) context.Context { return argsForCall.arg1 } -func (fake *FakeAllowListService) ListReturns(result1 admindb.ListEntries, result2 error) { +func (fake *FakeAllowListService) ListReturns(result1 roomdb.ListEntries, result2 error) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = nil fake.listReturns = struct { - result1 admindb.ListEntries + result1 roomdb.ListEntries result2 error }{result1, result2} } -func (fake *FakeAllowListService) ListReturnsOnCall(i int, result1 admindb.ListEntries, result2 error) { +func (fake *FakeAllowListService) ListReturnsOnCall(i int, result1 roomdb.ListEntries, result2 error) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = nil if fake.listReturnsOnCall == nil { fake.listReturnsOnCall = make(map[int]struct { - result1 admindb.ListEntries + result1 roomdb.ListEntries result2 error }) } fake.listReturnsOnCall[i] = struct { - result1 admindb.ListEntries + result1 roomdb.ListEntries result2 error }{result1, result2} } @@ -576,4 +576,4 @@ func (fake *FakeAllowListService) recordInvocation(key string, args []interface{ fake.invocations[key] = append(fake.invocations[key], args) } -var _ admindb.AllowListService = new(FakeAllowListService) +var _ roomdb.AllowListService = new(FakeAllowListService) diff --git a/admindb/mockdb/auth.go b/roomdb/mockdb/auth.go similarity index 88% rename from admindb/mockdb/auth.go rename to roomdb/mockdb/auth.go index 8925115..81109d2 100644 --- a/admindb/mockdb/auth.go +++ b/roomdb/mockdb/auth.go @@ -4,7 +4,7 @@ package mockdb import ( "sync" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) type FakeAuthWithSSBService struct { @@ -34,4 +34,4 @@ func (fake *FakeAuthWithSSBService) recordInvocation(key string, args []interfac fake.invocations[key] = append(fake.invocations[key], args) } -var _ admindb.AuthWithSSBService = new(FakeAuthWithSSBService) +var _ roomdb.AuthWithSSBService = new(FakeAuthWithSSBService) diff --git a/admindb/mockdb/auth_fallback.go b/roomdb/mockdb/auth_fallback.go similarity index 93% rename from admindb/mockdb/auth_fallback.go rename to roomdb/mockdb/auth_fallback.go index 095a01d..575a8a2 100644 --- a/admindb/mockdb/auth_fallback.go +++ b/roomdb/mockdb/auth_fallback.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) type FakeAuthFallbackService struct { @@ -38,18 +38,18 @@ type FakeAuthFallbackService struct { result1 int64 result2 error } - GetByIDStub func(context.Context, int64) (*admindb.User, error) + GetByIDStub func(context.Context, int64) (*roomdb.User, error) getByIDMutex sync.RWMutex getByIDArgsForCall []struct { arg1 context.Context arg2 int64 } getByIDReturns struct { - result1 *admindb.User + result1 *roomdb.User result2 error } getByIDReturnsOnCall map[int]struct { - result1 *admindb.User + result1 *roomdb.User result2 error } invocations map[string][][]interface{} @@ -192,7 +192,7 @@ func (fake *FakeAuthFallbackService) CreateReturnsOnCall(i int, result1 int64, r }{result1, result2} } -func (fake *FakeAuthFallbackService) GetByID(arg1 context.Context, arg2 int64) (*admindb.User, error) { +func (fake *FakeAuthFallbackService) GetByID(arg1 context.Context, arg2 int64) (*roomdb.User, error) { fake.getByIDMutex.Lock() ret, specificReturn := fake.getByIDReturnsOnCall[len(fake.getByIDArgsForCall)] fake.getByIDArgsForCall = append(fake.getByIDArgsForCall, struct { @@ -218,7 +218,7 @@ func (fake *FakeAuthFallbackService) GetByIDCallCount() int { return len(fake.getByIDArgsForCall) } -func (fake *FakeAuthFallbackService) GetByIDCalls(stub func(context.Context, int64) (*admindb.User, error)) { +func (fake *FakeAuthFallbackService) GetByIDCalls(stub func(context.Context, int64) (*roomdb.User, error)) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = stub @@ -231,28 +231,28 @@ func (fake *FakeAuthFallbackService) GetByIDArgsForCall(i int) (context.Context, return argsForCall.arg1, argsForCall.arg2 } -func (fake *FakeAuthFallbackService) GetByIDReturns(result1 *admindb.User, result2 error) { +func (fake *FakeAuthFallbackService) GetByIDReturns(result1 *roomdb.User, result2 error) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = nil fake.getByIDReturns = struct { - result1 *admindb.User + result1 *roomdb.User result2 error }{result1, result2} } -func (fake *FakeAuthFallbackService) GetByIDReturnsOnCall(i int, result1 *admindb.User, result2 error) { +func (fake *FakeAuthFallbackService) GetByIDReturnsOnCall(i int, result1 *roomdb.User, result2 error) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = nil if fake.getByIDReturnsOnCall == nil { fake.getByIDReturnsOnCall = make(map[int]struct { - result1 *admindb.User + result1 *roomdb.User result2 error }) } fake.getByIDReturnsOnCall[i] = struct { - result1 *admindb.User + result1 *roomdb.User result2 error }{result1, result2} } @@ -285,4 +285,4 @@ func (fake *FakeAuthFallbackService) recordInvocation(key string, args []interfa fake.invocations[key] = append(fake.invocations[key], args) } -var _ admindb.AuthFallbackService = new(FakeAuthFallbackService) +var _ roomdb.AuthFallbackService = new(FakeAuthFallbackService) diff --git a/admindb/mockdb/fixed_pages.go b/roomdb/mockdb/fixed_pages.go similarity index 80% rename from admindb/mockdb/fixed_pages.go rename to roomdb/mockdb/fixed_pages.go index 0d479ad..d9b1eef 100644 --- a/admindb/mockdb/fixed_pages.go +++ b/roomdb/mockdb/fixed_pages.go @@ -5,43 +5,43 @@ import ( "context" "sync" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) type FakePinnedNoticesService struct { - GetStub func(context.Context, admindb.PinnedNoticeName, string) (*admindb.Notice, error) + GetStub func(context.Context, roomdb.PinnedNoticeName, string) (*roomdb.Notice, error) getMutex sync.RWMutex getArgsForCall []struct { arg1 context.Context - arg2 admindb.PinnedNoticeName + arg2 roomdb.PinnedNoticeName arg3 string } getReturns struct { - result1 *admindb.Notice + result1 *roomdb.Notice result2 error } getReturnsOnCall map[int]struct { - result1 *admindb.Notice + result1 *roomdb.Notice result2 error } - ListStub func(context.Context) (admindb.PinnedNotices, error) + ListStub func(context.Context) (roomdb.PinnedNotices, error) listMutex sync.RWMutex listArgsForCall []struct { arg1 context.Context } listReturns struct { - result1 admindb.PinnedNotices + result1 roomdb.PinnedNotices result2 error } listReturnsOnCall map[int]struct { - result1 admindb.PinnedNotices + result1 roomdb.PinnedNotices result2 error } - SetStub func(context.Context, admindb.PinnedNoticeName, int64) error + SetStub func(context.Context, roomdb.PinnedNoticeName, int64) error setMutex sync.RWMutex setArgsForCall []struct { arg1 context.Context - arg2 admindb.PinnedNoticeName + arg2 roomdb.PinnedNoticeName arg3 int64 } setReturns struct { @@ -54,12 +54,12 @@ type FakePinnedNoticesService struct { invocationsMutex sync.RWMutex } -func (fake *FakePinnedNoticesService) Get(arg1 context.Context, arg2 admindb.PinnedNoticeName, arg3 string) (*admindb.Notice, error) { +func (fake *FakePinnedNoticesService) Get(arg1 context.Context, arg2 roomdb.PinnedNoticeName, arg3 string) (*roomdb.Notice, error) { fake.getMutex.Lock() ret, specificReturn := fake.getReturnsOnCall[len(fake.getArgsForCall)] fake.getArgsForCall = append(fake.getArgsForCall, struct { arg1 context.Context - arg2 admindb.PinnedNoticeName + arg2 roomdb.PinnedNoticeName arg3 string }{arg1, arg2, arg3}) stub := fake.GetStub @@ -81,46 +81,46 @@ func (fake *FakePinnedNoticesService) GetCallCount() int { return len(fake.getArgsForCall) } -func (fake *FakePinnedNoticesService) GetCalls(stub func(context.Context, admindb.PinnedNoticeName, string) (*admindb.Notice, error)) { +func (fake *FakePinnedNoticesService) GetCalls(stub func(context.Context, roomdb.PinnedNoticeName, string) (*roomdb.Notice, error)) { fake.getMutex.Lock() defer fake.getMutex.Unlock() fake.GetStub = stub } -func (fake *FakePinnedNoticesService) GetArgsForCall(i int) (context.Context, admindb.PinnedNoticeName, string) { +func (fake *FakePinnedNoticesService) GetArgsForCall(i int) (context.Context, roomdb.PinnedNoticeName, string) { fake.getMutex.RLock() defer fake.getMutex.RUnlock() argsForCall := fake.getArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } -func (fake *FakePinnedNoticesService) GetReturns(result1 *admindb.Notice, result2 error) { +func (fake *FakePinnedNoticesService) GetReturns(result1 *roomdb.Notice, result2 error) { fake.getMutex.Lock() defer fake.getMutex.Unlock() fake.GetStub = nil fake.getReturns = struct { - result1 *admindb.Notice + result1 *roomdb.Notice result2 error }{result1, result2} } -func (fake *FakePinnedNoticesService) GetReturnsOnCall(i int, result1 *admindb.Notice, result2 error) { +func (fake *FakePinnedNoticesService) GetReturnsOnCall(i int, result1 *roomdb.Notice, result2 error) { fake.getMutex.Lock() defer fake.getMutex.Unlock() fake.GetStub = nil if fake.getReturnsOnCall == nil { fake.getReturnsOnCall = make(map[int]struct { - result1 *admindb.Notice + result1 *roomdb.Notice result2 error }) } fake.getReturnsOnCall[i] = struct { - result1 *admindb.Notice + result1 *roomdb.Notice result2 error }{result1, result2} } -func (fake *FakePinnedNoticesService) List(arg1 context.Context) (admindb.PinnedNotices, error) { +func (fake *FakePinnedNoticesService) List(arg1 context.Context) (roomdb.PinnedNotices, error) { fake.listMutex.Lock() ret, specificReturn := fake.listReturnsOnCall[len(fake.listArgsForCall)] fake.listArgsForCall = append(fake.listArgsForCall, struct { @@ -145,7 +145,7 @@ func (fake *FakePinnedNoticesService) ListCallCount() int { return len(fake.listArgsForCall) } -func (fake *FakePinnedNoticesService) ListCalls(stub func(context.Context) (admindb.PinnedNotices, error)) { +func (fake *FakePinnedNoticesService) ListCalls(stub func(context.Context) (roomdb.PinnedNotices, error)) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = stub @@ -158,38 +158,38 @@ func (fake *FakePinnedNoticesService) ListArgsForCall(i int) context.Context { return argsForCall.arg1 } -func (fake *FakePinnedNoticesService) ListReturns(result1 admindb.PinnedNotices, result2 error) { +func (fake *FakePinnedNoticesService) ListReturns(result1 roomdb.PinnedNotices, result2 error) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = nil fake.listReturns = struct { - result1 admindb.PinnedNotices + result1 roomdb.PinnedNotices result2 error }{result1, result2} } -func (fake *FakePinnedNoticesService) ListReturnsOnCall(i int, result1 admindb.PinnedNotices, result2 error) { +func (fake *FakePinnedNoticesService) ListReturnsOnCall(i int, result1 roomdb.PinnedNotices, result2 error) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = nil if fake.listReturnsOnCall == nil { fake.listReturnsOnCall = make(map[int]struct { - result1 admindb.PinnedNotices + result1 roomdb.PinnedNotices result2 error }) } fake.listReturnsOnCall[i] = struct { - result1 admindb.PinnedNotices + result1 roomdb.PinnedNotices result2 error }{result1, result2} } -func (fake *FakePinnedNoticesService) Set(arg1 context.Context, arg2 admindb.PinnedNoticeName, arg3 int64) error { +func (fake *FakePinnedNoticesService) Set(arg1 context.Context, arg2 roomdb.PinnedNoticeName, arg3 int64) error { fake.setMutex.Lock() ret, specificReturn := fake.setReturnsOnCall[len(fake.setArgsForCall)] fake.setArgsForCall = append(fake.setArgsForCall, struct { arg1 context.Context - arg2 admindb.PinnedNoticeName + arg2 roomdb.PinnedNoticeName arg3 int64 }{arg1, arg2, arg3}) stub := fake.SetStub @@ -211,13 +211,13 @@ func (fake *FakePinnedNoticesService) SetCallCount() int { return len(fake.setArgsForCall) } -func (fake *FakePinnedNoticesService) SetCalls(stub func(context.Context, admindb.PinnedNoticeName, int64) error) { +func (fake *FakePinnedNoticesService) SetCalls(stub func(context.Context, roomdb.PinnedNoticeName, int64) error) { fake.setMutex.Lock() defer fake.setMutex.Unlock() fake.SetStub = stub } -func (fake *FakePinnedNoticesService) SetArgsForCall(i int) (context.Context, admindb.PinnedNoticeName, int64) { +func (fake *FakePinnedNoticesService) SetArgsForCall(i int) (context.Context, roomdb.PinnedNoticeName, int64) { fake.setMutex.RLock() defer fake.setMutex.RUnlock() argsForCall := fake.setArgsForCall[i] @@ -275,4 +275,4 @@ func (fake *FakePinnedNoticesService) recordInvocation(key string, args []interf fake.invocations[key] = append(fake.invocations[key], args) } -var _ admindb.PinnedNoticesService = new(FakePinnedNoticesService) +var _ roomdb.PinnedNoticesService = new(FakePinnedNoticesService) diff --git a/admindb/mockdb/invite.go b/roomdb/mockdb/invite.go similarity index 88% rename from admindb/mockdb/invite.go rename to roomdb/mockdb/invite.go index 080a8a6..36a87a2 100644 --- a/admindb/mockdb/invite.go +++ b/roomdb/mockdb/invite.go @@ -5,12 +5,12 @@ import ( "context" "sync" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" refs "go.mindeco.de/ssb-refs" ) type FakeInviteService struct { - ConsumeStub func(context.Context, string, refs.FeedRef) (admindb.Invite, error) + ConsumeStub func(context.Context, string, refs.FeedRef) (roomdb.Invite, error) consumeMutex sync.RWMutex consumeArgsForCall []struct { arg1 context.Context @@ -18,11 +18,11 @@ type FakeInviteService struct { arg3 refs.FeedRef } consumeReturns struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error } consumeReturnsOnCall map[int]struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error } CreateStub func(context.Context, int64, string) (string, error) @@ -40,45 +40,45 @@ type FakeInviteService struct { result1 string result2 error } - GetByIDStub func(context.Context, int64) (admindb.Invite, error) + GetByIDStub func(context.Context, int64) (roomdb.Invite, error) getByIDMutex sync.RWMutex getByIDArgsForCall []struct { arg1 context.Context arg2 int64 } getByIDReturns struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error } getByIDReturnsOnCall map[int]struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error } - GetByTokenStub func(context.Context, string) (admindb.Invite, error) + GetByTokenStub func(context.Context, string) (roomdb.Invite, error) getByTokenMutex sync.RWMutex getByTokenArgsForCall []struct { arg1 context.Context arg2 string } getByTokenReturns struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error } getByTokenReturnsOnCall map[int]struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error } - ListStub func(context.Context) ([]admindb.Invite, error) + ListStub func(context.Context) ([]roomdb.Invite, error) listMutex sync.RWMutex listArgsForCall []struct { arg1 context.Context } listReturns struct { - result1 []admindb.Invite + result1 []roomdb.Invite result2 error } listReturnsOnCall map[int]struct { - result1 []admindb.Invite + result1 []roomdb.Invite result2 error } RevokeStub func(context.Context, int64) error @@ -97,7 +97,7 @@ type FakeInviteService struct { invocationsMutex sync.RWMutex } -func (fake *FakeInviteService) Consume(arg1 context.Context, arg2 string, arg3 refs.FeedRef) (admindb.Invite, error) { +func (fake *FakeInviteService) Consume(arg1 context.Context, arg2 string, arg3 refs.FeedRef) (roomdb.Invite, error) { fake.consumeMutex.Lock() ret, specificReturn := fake.consumeReturnsOnCall[len(fake.consumeArgsForCall)] fake.consumeArgsForCall = append(fake.consumeArgsForCall, struct { @@ -124,7 +124,7 @@ func (fake *FakeInviteService) ConsumeCallCount() int { return len(fake.consumeArgsForCall) } -func (fake *FakeInviteService) ConsumeCalls(stub func(context.Context, string, refs.FeedRef) (admindb.Invite, error)) { +func (fake *FakeInviteService) ConsumeCalls(stub func(context.Context, string, refs.FeedRef) (roomdb.Invite, error)) { fake.consumeMutex.Lock() defer fake.consumeMutex.Unlock() fake.ConsumeStub = stub @@ -137,28 +137,28 @@ func (fake *FakeInviteService) ConsumeArgsForCall(i int) (context.Context, strin return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } -func (fake *FakeInviteService) ConsumeReturns(result1 admindb.Invite, result2 error) { +func (fake *FakeInviteService) ConsumeReturns(result1 roomdb.Invite, result2 error) { fake.consumeMutex.Lock() defer fake.consumeMutex.Unlock() fake.ConsumeStub = nil fake.consumeReturns = struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }{result1, result2} } -func (fake *FakeInviteService) ConsumeReturnsOnCall(i int, result1 admindb.Invite, result2 error) { +func (fake *FakeInviteService) ConsumeReturnsOnCall(i int, result1 roomdb.Invite, result2 error) { fake.consumeMutex.Lock() defer fake.consumeMutex.Unlock() fake.ConsumeStub = nil if fake.consumeReturnsOnCall == nil { fake.consumeReturnsOnCall = make(map[int]struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }) } fake.consumeReturnsOnCall[i] = struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }{result1, result2} } @@ -229,7 +229,7 @@ func (fake *FakeInviteService) CreateReturnsOnCall(i int, result1 string, result }{result1, result2} } -func (fake *FakeInviteService) GetByID(arg1 context.Context, arg2 int64) (admindb.Invite, error) { +func (fake *FakeInviteService) GetByID(arg1 context.Context, arg2 int64) (roomdb.Invite, error) { fake.getByIDMutex.Lock() ret, specificReturn := fake.getByIDReturnsOnCall[len(fake.getByIDArgsForCall)] fake.getByIDArgsForCall = append(fake.getByIDArgsForCall, struct { @@ -255,7 +255,7 @@ func (fake *FakeInviteService) GetByIDCallCount() int { return len(fake.getByIDArgsForCall) } -func (fake *FakeInviteService) GetByIDCalls(stub func(context.Context, int64) (admindb.Invite, error)) { +func (fake *FakeInviteService) GetByIDCalls(stub func(context.Context, int64) (roomdb.Invite, error)) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = stub @@ -268,33 +268,33 @@ func (fake *FakeInviteService) GetByIDArgsForCall(i int) (context.Context, int64 return argsForCall.arg1, argsForCall.arg2 } -func (fake *FakeInviteService) GetByIDReturns(result1 admindb.Invite, result2 error) { +func (fake *FakeInviteService) GetByIDReturns(result1 roomdb.Invite, result2 error) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = nil fake.getByIDReturns = struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }{result1, result2} } -func (fake *FakeInviteService) GetByIDReturnsOnCall(i int, result1 admindb.Invite, result2 error) { +func (fake *FakeInviteService) GetByIDReturnsOnCall(i int, result1 roomdb.Invite, result2 error) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = nil if fake.getByIDReturnsOnCall == nil { fake.getByIDReturnsOnCall = make(map[int]struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }) } fake.getByIDReturnsOnCall[i] = struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }{result1, result2} } -func (fake *FakeInviteService) GetByToken(arg1 context.Context, arg2 string) (admindb.Invite, error) { +func (fake *FakeInviteService) GetByToken(arg1 context.Context, arg2 string) (roomdb.Invite, error) { fake.getByTokenMutex.Lock() ret, specificReturn := fake.getByTokenReturnsOnCall[len(fake.getByTokenArgsForCall)] fake.getByTokenArgsForCall = append(fake.getByTokenArgsForCall, struct { @@ -320,7 +320,7 @@ func (fake *FakeInviteService) GetByTokenCallCount() int { return len(fake.getByTokenArgsForCall) } -func (fake *FakeInviteService) GetByTokenCalls(stub func(context.Context, string) (admindb.Invite, error)) { +func (fake *FakeInviteService) GetByTokenCalls(stub func(context.Context, string) (roomdb.Invite, error)) { fake.getByTokenMutex.Lock() defer fake.getByTokenMutex.Unlock() fake.GetByTokenStub = stub @@ -333,33 +333,33 @@ func (fake *FakeInviteService) GetByTokenArgsForCall(i int) (context.Context, st return argsForCall.arg1, argsForCall.arg2 } -func (fake *FakeInviteService) GetByTokenReturns(result1 admindb.Invite, result2 error) { +func (fake *FakeInviteService) GetByTokenReturns(result1 roomdb.Invite, result2 error) { fake.getByTokenMutex.Lock() defer fake.getByTokenMutex.Unlock() fake.GetByTokenStub = nil fake.getByTokenReturns = struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }{result1, result2} } -func (fake *FakeInviteService) GetByTokenReturnsOnCall(i int, result1 admindb.Invite, result2 error) { +func (fake *FakeInviteService) GetByTokenReturnsOnCall(i int, result1 roomdb.Invite, result2 error) { fake.getByTokenMutex.Lock() defer fake.getByTokenMutex.Unlock() fake.GetByTokenStub = nil if fake.getByTokenReturnsOnCall == nil { fake.getByTokenReturnsOnCall = make(map[int]struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }) } fake.getByTokenReturnsOnCall[i] = struct { - result1 admindb.Invite + result1 roomdb.Invite result2 error }{result1, result2} } -func (fake *FakeInviteService) List(arg1 context.Context) ([]admindb.Invite, error) { +func (fake *FakeInviteService) List(arg1 context.Context) ([]roomdb.Invite, error) { fake.listMutex.Lock() ret, specificReturn := fake.listReturnsOnCall[len(fake.listArgsForCall)] fake.listArgsForCall = append(fake.listArgsForCall, struct { @@ -384,7 +384,7 @@ func (fake *FakeInviteService) ListCallCount() int { return len(fake.listArgsForCall) } -func (fake *FakeInviteService) ListCalls(stub func(context.Context) ([]admindb.Invite, error)) { +func (fake *FakeInviteService) ListCalls(stub func(context.Context) ([]roomdb.Invite, error)) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = stub @@ -397,28 +397,28 @@ func (fake *FakeInviteService) ListArgsForCall(i int) context.Context { return argsForCall.arg1 } -func (fake *FakeInviteService) ListReturns(result1 []admindb.Invite, result2 error) { +func (fake *FakeInviteService) ListReturns(result1 []roomdb.Invite, result2 error) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = nil fake.listReturns = struct { - result1 []admindb.Invite + result1 []roomdb.Invite result2 error }{result1, result2} } -func (fake *FakeInviteService) ListReturnsOnCall(i int, result1 []admindb.Invite, result2 error) { +func (fake *FakeInviteService) ListReturnsOnCall(i int, result1 []roomdb.Invite, result2 error) { fake.listMutex.Lock() defer fake.listMutex.Unlock() fake.ListStub = nil if fake.listReturnsOnCall == nil { fake.listReturnsOnCall = make(map[int]struct { - result1 []admindb.Invite + result1 []roomdb.Invite result2 error }) } fake.listReturnsOnCall[i] = struct { - result1 []admindb.Invite + result1 []roomdb.Invite result2 error }{result1, result2} } @@ -519,4 +519,4 @@ func (fake *FakeInviteService) recordInvocation(key string, args []interface{}) fake.invocations[key] = append(fake.invocations[key], args) } -var _ admindb.InviteService = new(FakeInviteService) +var _ roomdb.InviteService = new(FakeInviteService) diff --git a/admindb/mockdb/pages.go b/roomdb/mockdb/pages.go similarity index 90% rename from admindb/mockdb/pages.go rename to roomdb/mockdb/pages.go index 556a49e..eced52d 100644 --- a/admindb/mockdb/pages.go +++ b/roomdb/mockdb/pages.go @@ -5,22 +5,22 @@ import ( "context" "sync" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) type FakeNoticesService struct { - GetByIDStub func(context.Context, int64) (admindb.Notice, error) + GetByIDStub func(context.Context, int64) (roomdb.Notice, error) getByIDMutex sync.RWMutex getByIDArgsForCall []struct { arg1 context.Context arg2 int64 } getByIDReturns struct { - result1 admindb.Notice + result1 roomdb.Notice result2 error } getByIDReturnsOnCall map[int]struct { - result1 admindb.Notice + result1 roomdb.Notice result2 error } RemoveIDStub func(context.Context, int64) error @@ -35,11 +35,11 @@ type FakeNoticesService struct { removeIDReturnsOnCall map[int]struct { result1 error } - SaveStub func(context.Context, *admindb.Notice) error + SaveStub func(context.Context, *roomdb.Notice) error saveMutex sync.RWMutex saveArgsForCall []struct { arg1 context.Context - arg2 *admindb.Notice + arg2 *roomdb.Notice } saveReturns struct { result1 error @@ -51,7 +51,7 @@ type FakeNoticesService struct { invocationsMutex sync.RWMutex } -func (fake *FakeNoticesService) GetByID(arg1 context.Context, arg2 int64) (admindb.Notice, error) { +func (fake *FakeNoticesService) GetByID(arg1 context.Context, arg2 int64) (roomdb.Notice, error) { fake.getByIDMutex.Lock() ret, specificReturn := fake.getByIDReturnsOnCall[len(fake.getByIDArgsForCall)] fake.getByIDArgsForCall = append(fake.getByIDArgsForCall, struct { @@ -77,7 +77,7 @@ func (fake *FakeNoticesService) GetByIDCallCount() int { return len(fake.getByIDArgsForCall) } -func (fake *FakeNoticesService) GetByIDCalls(stub func(context.Context, int64) (admindb.Notice, error)) { +func (fake *FakeNoticesService) GetByIDCalls(stub func(context.Context, int64) (roomdb.Notice, error)) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = stub @@ -90,28 +90,28 @@ func (fake *FakeNoticesService) GetByIDArgsForCall(i int) (context.Context, int6 return argsForCall.arg1, argsForCall.arg2 } -func (fake *FakeNoticesService) GetByIDReturns(result1 admindb.Notice, result2 error) { +func (fake *FakeNoticesService) GetByIDReturns(result1 roomdb.Notice, result2 error) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = nil fake.getByIDReturns = struct { - result1 admindb.Notice + result1 roomdb.Notice result2 error }{result1, result2} } -func (fake *FakeNoticesService) GetByIDReturnsOnCall(i int, result1 admindb.Notice, result2 error) { +func (fake *FakeNoticesService) GetByIDReturnsOnCall(i int, result1 roomdb.Notice, result2 error) { fake.getByIDMutex.Lock() defer fake.getByIDMutex.Unlock() fake.GetByIDStub = nil if fake.getByIDReturnsOnCall == nil { fake.getByIDReturnsOnCall = make(map[int]struct { - result1 admindb.Notice + result1 roomdb.Notice result2 error }) } fake.getByIDReturnsOnCall[i] = struct { - result1 admindb.Notice + result1 roomdb.Notice result2 error }{result1, result2} } @@ -178,12 +178,12 @@ func (fake *FakeNoticesService) RemoveIDReturnsOnCall(i int, result1 error) { }{result1} } -func (fake *FakeNoticesService) Save(arg1 context.Context, arg2 *admindb.Notice) error { +func (fake *FakeNoticesService) Save(arg1 context.Context, arg2 *roomdb.Notice) error { fake.saveMutex.Lock() ret, specificReturn := fake.saveReturnsOnCall[len(fake.saveArgsForCall)] fake.saveArgsForCall = append(fake.saveArgsForCall, struct { arg1 context.Context - arg2 *admindb.Notice + arg2 *roomdb.Notice }{arg1, arg2}) stub := fake.SaveStub fakeReturns := fake.saveReturns @@ -204,13 +204,13 @@ func (fake *FakeNoticesService) SaveCallCount() int { return len(fake.saveArgsForCall) } -func (fake *FakeNoticesService) SaveCalls(stub func(context.Context, *admindb.Notice) error) { +func (fake *FakeNoticesService) SaveCalls(stub func(context.Context, *roomdb.Notice) error) { fake.saveMutex.Lock() defer fake.saveMutex.Unlock() fake.SaveStub = stub } -func (fake *FakeNoticesService) SaveArgsForCall(i int) (context.Context, *admindb.Notice) { +func (fake *FakeNoticesService) SaveArgsForCall(i int) (context.Context, *roomdb.Notice) { fake.saveMutex.RLock() defer fake.saveMutex.RUnlock() argsForCall := fake.saveArgsForCall[i] @@ -268,4 +268,4 @@ func (fake *FakeNoticesService) recordInvocation(key string, args []interface{}) fake.invocations[key] = append(fake.invocations[key], args) } -var _ admindb.NoticesService = new(FakeNoticesService) +var _ roomdb.NoticesService = new(FakeNoticesService) diff --git a/admindb/sqlite/aliases.go b/roomdb/sqlite/aliases.go similarity index 65% rename from admindb/sqlite/aliases.go rename to roomdb/sqlite/aliases.go index 2b798e9..b2e276e 100644 --- a/admindb/sqlite/aliases.go +++ b/roomdb/sqlite/aliases.go @@ -5,11 +5,11 @@ package sqlite import ( "database/sql" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) // compiler assertion to ensure the struct fullfills the interface -var _ admindb.AliasService = (*Aliases)(nil) +var _ roomdb.AliasService = (*Aliases)(nil) type Aliases struct { db *sql.DB diff --git a/admindb/sqlite/auth_fallback.go b/roomdb/sqlite/auth_fallback.go similarity index 86% rename from admindb/sqlite/auth_fallback.go rename to roomdb/sqlite/auth_fallback.go index 08a2609..3e713bd 100644 --- a/admindb/sqlite/auth_fallback.go +++ b/roomdb/sqlite/auth_fallback.go @@ -11,14 +11,14 @@ import ( "golang.org/x/crypto/bcrypt" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/sqlite/models" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite/models" "github.com/volatiletech/sqlboiler/v4/queries/qm" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) // compiler assertion to ensure the struct fullfills the interface -var _ admindb.AuthFallbackService = (*AuthFallback)(nil) +var _ roomdb.AuthFallbackService = (*AuthFallback)(nil) type AuthFallback struct { db *sql.DB @@ -58,12 +58,12 @@ func (ah AuthFallback) Create(ctx context.Context, name string, password []byte) return u.ID, nil } -func (ah AuthFallback) GetByID(ctx context.Context, uid int64) (*admindb.User, error) { +func (ah AuthFallback) GetByID(ctx context.Context, uid int64) (*roomdb.User, error) { modelU, err := models.FindAuthFallback(ctx, ah.db, uid) if err != nil { return nil, err } - return &admindb.User{ + return &roomdb.User{ ID: modelU.ID, Name: modelU.Name, }, nil diff --git a/admindb/sqlite/auth_withssb.go b/roomdb/sqlite/auth_withssb.go similarity index 63% rename from admindb/sqlite/auth_withssb.go rename to roomdb/sqlite/auth_withssb.go index fc4232f..5a8902c 100644 --- a/admindb/sqlite/auth_withssb.go +++ b/roomdb/sqlite/auth_withssb.go @@ -5,11 +5,11 @@ package sqlite import ( "database/sql" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) // compiler assertion to ensure the struct fullfills the interface -var _ admindb.AuthWithSSBService = (*AuthWithSSB)(nil) +var _ roomdb.AuthWithSSBService = (*AuthWithSSB)(nil) type AuthWithSSB struct { db *sql.DB diff --git a/admindb/sqlite/generate_models.sh b/roomdb/sqlite/generate_models.sh similarity index 100% rename from admindb/sqlite/generate_models.sh rename to roomdb/sqlite/generate_models.sh diff --git a/admindb/sqlite/invites.go b/roomdb/sqlite/invites.go similarity index 89% rename from admindb/sqlite/invites.go rename to roomdb/sqlite/invites.go index f671d15..547b338 100644 --- a/admindb/sqlite/invites.go +++ b/roomdb/sqlite/invites.go @@ -13,15 +13,15 @@ import ( "github.com/volatiletech/sqlboiler/v4/boil" "github.com/volatiletech/sqlboiler/v4/queries/qm" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/sqlite/models" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite/models" refs "go.mindeco.de/ssb-refs" ) // compiler assertion to ensure the struct fullfills the interface -var _ admindb.InviteService = (*Invites)(nil) +var _ roomdb.InviteService = (*Invites)(nil) -// Invites implements the admindb.InviteService. +// Invites implements the roomdb.InviteService. // Tokens are stored as sha256 hashes on disk to protect against attackers gaining database read-access. type Invites struct { db *sql.DB @@ -85,8 +85,8 @@ func (i Invites) Create(ctx context.Context, createdBy int64, aliasSuggestion st // Consume checks if the passed token is still valid. If it is it adds newMember to the members of the room and invalidates the token. // If the token isn't valid, it returns an error. // Tokens need to be base64 URL encoded and when decoded be of tokenLength. -func (i Invites) Consume(ctx context.Context, token string, newMember refs.FeedRef) (admindb.Invite, error) { - var inv admindb.Invite +func (i Invites) Consume(ctx context.Context, token string, newMember refs.FeedRef) (roomdb.Invite, error) { + var inv roomdb.Invite hashedToken, err := getHashedToken(token) if err != nil { @@ -124,7 +124,7 @@ func (i Invites) Consume(ctx context.Context, token string, newMember refs.FeedR if err != nil { if errors.Is(err, sql.ErrNoRows) { - return inv, admindb.ErrNotFound + return inv, roomdb.ErrNotFound } return inv, err } @@ -142,8 +142,8 @@ func deleteConsumedInvites(tx boil.ContextExecutor) error { return nil } -func (i Invites) GetByToken(ctx context.Context, token string) (admindb.Invite, error) { - var inv admindb.Invite +func (i Invites) GetByToken(ctx context.Context, token string) (roomdb.Invite, error) { + var inv roomdb.Invite ht, err := getHashedToken(token) if err != nil { @@ -156,7 +156,7 @@ func (i Invites) GetByToken(ctx context.Context, token string) (admindb.Invite, ).One(ctx, i.db) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return inv, admindb.ErrNotFound + return inv, roomdb.ErrNotFound } return inv, err } @@ -169,8 +169,8 @@ func (i Invites) GetByToken(ctx context.Context, token string) (admindb.Invite, return inv, nil } -func (i Invites) GetByID(ctx context.Context, id int64) (admindb.Invite, error) { - var inv admindb.Invite +func (i Invites) GetByID(ctx context.Context, id int64) (roomdb.Invite, error) { + var inv roomdb.Invite entry, err := models.Invites( qm.Where("active = true AND id = ?", id), @@ -178,7 +178,7 @@ func (i Invites) GetByID(ctx context.Context, id int64) (admindb.Invite, error) ).One(ctx, i.db) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return inv, admindb.ErrNotFound + return inv, roomdb.ErrNotFound } return inv, err } @@ -192,8 +192,8 @@ func (i Invites) GetByID(ctx context.Context, id int64) (admindb.Invite, error) } // List returns a list of all the valid invites -func (i Invites) List(ctx context.Context) ([]admindb.Invite, error) { - var invs []admindb.Invite +func (i Invites) List(ctx context.Context) ([]roomdb.Invite, error) { + var invs []roomdb.Invite err := transact(i.db, func(tx *sql.Tx) error { entries, err := models.Invites( @@ -204,9 +204,9 @@ func (i Invites) List(ctx context.Context) ([]admindb.Invite, error) { return err } - invs = make([]admindb.Invite, len(entries)) + invs = make([]roomdb.Invite, len(entries)) for i, e := range entries { - var inv admindb.Invite + var inv roomdb.Invite inv.ID = e.ID inv.AliasSuggestion = e.AliasSuggestion inv.CreatedBy.ID = e.R.CreatedByAuthFallback.ID @@ -232,7 +232,7 @@ func (i Invites) Revoke(ctx context.Context, id int64) error { ).One(ctx, tx) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return admindb.ErrNotFound + return roomdb.ErrNotFound } return err } diff --git a/admindb/sqlite/invites_test.go b/roomdb/sqlite/invites_test.go similarity index 99% rename from admindb/sqlite/invites_test.go rename to roomdb/sqlite/invites_test.go index 32dce16..4e5a5fb 100644 --- a/admindb/sqlite/invites_test.go +++ b/roomdb/sqlite/invites_test.go @@ -9,8 +9,9 @@ import ( "path/filepath" "testing" - "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" "github.com/stretchr/testify/require" + + "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" refs "go.mindeco.de/ssb-refs" ) diff --git a/admindb/sqlite/migrations.go b/roomdb/sqlite/migrations.go similarity index 100% rename from admindb/sqlite/migrations.go rename to roomdb/sqlite/migrations.go diff --git a/admindb/sqlite/migrations/1-create-auth-fallback.sql b/roomdb/sqlite/migrations/1-create-auth-fallback.sql similarity index 100% rename from admindb/sqlite/migrations/1-create-auth-fallback.sql rename to roomdb/sqlite/migrations/1-create-auth-fallback.sql diff --git a/admindb/sqlite/migrations/2-create-allow-list.sql b/roomdb/sqlite/migrations/2-create-allow-list.sql similarity index 100% rename from admindb/sqlite/migrations/2-create-allow-list.sql rename to roomdb/sqlite/migrations/2-create-allow-list.sql diff --git a/admindb/sqlite/migrations/3-notices.sql b/roomdb/sqlite/migrations/3-notices.sql similarity index 100% rename from admindb/sqlite/migrations/3-notices.sql rename to roomdb/sqlite/migrations/3-notices.sql diff --git a/admindb/sqlite/migrations/4-invites.sql b/roomdb/sqlite/migrations/4-invites.sql similarity index 100% rename from admindb/sqlite/migrations/4-invites.sql rename to roomdb/sqlite/migrations/4-invites.sql diff --git a/admindb/sqlite/models/allow_list.go b/roomdb/sqlite/models/allow_list.go similarity index 97% rename from admindb/sqlite/models/allow_list.go rename to roomdb/sqlite/models/allow_list.go index a1f877b..02c1a6b 100644 --- a/admindb/sqlite/models/allow_list.go +++ b/roomdb/sqlite/models/allow_list.go @@ -13,7 +13,7 @@ import ( "time" "github.com/friendsofgo/errors" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/volatiletech/sqlboiler/v4/boil" "github.com/volatiletech/sqlboiler/v4/queries" "github.com/volatiletech/sqlboiler/v4/queries/qm" @@ -24,7 +24,7 @@ import ( // AllowList is an object representing the database table. type AllowList struct { ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"` - PubKey admindb.DBFeedRef `boil:"pub_key" json:"pub_key" toml:"pub_key" yaml:"pub_key"` + PubKey roomdb.DBFeedRef `boil:"pub_key" json:"pub_key" toml:"pub_key" yaml:"pub_key"` R *allowListR `boil:"-" json:"-" toml:"-" yaml:"-"` L allowListL `boil:"-" json:"-" toml:"-" yaml:"-"` @@ -65,22 +65,22 @@ func (w whereHelperint64) NIN(slice []int64) qm.QueryMod { type whereHelperadmindb_DBFeedRef struct{ field string } -func (w whereHelperadmindb_DBFeedRef) EQ(x admindb.DBFeedRef) qm.QueryMod { +func (w whereHelperadmindb_DBFeedRef) EQ(x roomdb.DBFeedRef) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) } -func (w whereHelperadmindb_DBFeedRef) NEQ(x admindb.DBFeedRef) qm.QueryMod { +func (w whereHelperadmindb_DBFeedRef) NEQ(x roomdb.DBFeedRef) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) } -func (w whereHelperadmindb_DBFeedRef) LT(x admindb.DBFeedRef) qm.QueryMod { +func (w whereHelperadmindb_DBFeedRef) LT(x roomdb.DBFeedRef) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) } -func (w whereHelperadmindb_DBFeedRef) LTE(x admindb.DBFeedRef) qm.QueryMod { +func (w whereHelperadmindb_DBFeedRef) LTE(x roomdb.DBFeedRef) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) } -func (w whereHelperadmindb_DBFeedRef) GT(x admindb.DBFeedRef) qm.QueryMod { +func (w whereHelperadmindb_DBFeedRef) GT(x roomdb.DBFeedRef) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) } -func (w whereHelperadmindb_DBFeedRef) GTE(x admindb.DBFeedRef) qm.QueryMod { +func (w whereHelperadmindb_DBFeedRef) GTE(x roomdb.DBFeedRef) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) } diff --git a/admindb/sqlite/models/auth_fallback.go b/roomdb/sqlite/models/auth_fallback.go similarity index 100% rename from admindb/sqlite/models/auth_fallback.go rename to roomdb/sqlite/models/auth_fallback.go diff --git a/admindb/sqlite/models/boil_queries.go b/roomdb/sqlite/models/boil_queries.go similarity index 100% rename from admindb/sqlite/models/boil_queries.go rename to roomdb/sqlite/models/boil_queries.go diff --git a/admindb/sqlite/models/boil_table_names.go b/roomdb/sqlite/models/boil_table_names.go similarity index 100% rename from admindb/sqlite/models/boil_table_names.go rename to roomdb/sqlite/models/boil_table_names.go diff --git a/admindb/sqlite/models/boil_types.go b/roomdb/sqlite/models/boil_types.go similarity index 100% rename from admindb/sqlite/models/boil_types.go rename to roomdb/sqlite/models/boil_types.go diff --git a/admindb/sqlite/models/invites.go b/roomdb/sqlite/models/invites.go similarity index 100% rename from admindb/sqlite/models/invites.go rename to roomdb/sqlite/models/invites.go diff --git a/admindb/sqlite/models/notices.go b/roomdb/sqlite/models/notices.go similarity index 100% rename from admindb/sqlite/models/notices.go rename to roomdb/sqlite/models/notices.go diff --git a/admindb/sqlite/models/pins.go b/roomdb/sqlite/models/pins.go similarity index 100% rename from admindb/sqlite/models/pins.go rename to roomdb/sqlite/models/pins.go diff --git a/admindb/sqlite/new.go b/roomdb/sqlite/new.go similarity index 91% rename from admindb/sqlite/new.go rename to roomdb/sqlite/new.go index 9609e4d..0990f53 100644 --- a/admindb/sqlite/new.go +++ b/roomdb/sqlite/new.go @@ -26,23 +26,23 @@ import ( migrate "github.com/rubenv/sql-migrate" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" ) type Database struct { db *sql.DB - AuthWithSSB admindb.AuthWithSSBService - AuthFallback admindb.AuthFallbackService + AuthWithSSB roomdb.AuthWithSSBService + AuthFallback roomdb.AuthFallbackService - AllowList admindb.AllowListService - Aliases admindb.AliasService + AllowList roomdb.AllowListService + Aliases roomdb.AliasService - PinnedNotices admindb.PinnedNoticesService - Notices admindb.NoticesService + PinnedNotices roomdb.PinnedNoticesService + Notices roomdb.NoticesService - Invites admindb.InviteService + Invites roomdb.InviteService } // Open looks for a database file 'fname' diff --git a/admindb/sqlite/new_test.go b/roomdb/sqlite/new_test.go similarity index 100% rename from admindb/sqlite/new_test.go rename to roomdb/sqlite/new_test.go diff --git a/admindb/sqlite/notices.go b/roomdb/sqlite/notices.go similarity index 76% rename from admindb/sqlite/notices.go rename to roomdb/sqlite/notices.go index 08d8567..92b813c 100644 --- a/admindb/sqlite/notices.go +++ b/roomdb/sqlite/notices.go @@ -9,19 +9,19 @@ import ( "github.com/volatiletech/sqlboiler/v4/boil" "github.com/volatiletech/sqlboiler/v4/queries/qm" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/sqlite/models" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite/models" ) // compiler assertion to ensure the struct fullfills the interface -var _ admindb.PinnedNoticesService = (*PinnedNotices)(nil) +var _ roomdb.PinnedNoticesService = (*PinnedNotices)(nil) type PinnedNotices struct { db *sql.DB } // List returns a sortable map of all the pinned notices -func (pn PinnedNotices) List(ctx context.Context) (admindb.PinnedNotices, error) { +func (pn PinnedNotices) List(ctx context.Context) (roomdb.PinnedNotices, error) { // get all the pins and eager-load the related notices lst, err := models.Pins(qm.Load("Notices")).All(ctx, pn.db) @@ -30,7 +30,7 @@ func (pn PinnedNotices) List(ctx context.Context) (admindb.PinnedNotices, error) } // prepare a map for them - var pinnedMap = make(admindb.PinnedNotices, len(lst)) + var pinnedMap = make(roomdb.PinnedNotices, len(lst)) for _, entry := range lst { @@ -40,17 +40,17 @@ func (pn PinnedNotices) List(ctx context.Context) (admindb.PinnedNotices, error) continue } - name := admindb.PinnedNoticeName(entry.Name) + name := roomdb.PinnedNoticeName(entry.Name) // get the exisint map entry or create a new slice notices, has := pinnedMap[name] if !has { - notices = make([]admindb.Notice, 0, noticeCount) + notices = make([]roomdb.Notice, 0, noticeCount) } // add all the related notice to the slice for _, n := range entry.R.Notices { - relatedNotice := admindb.Notice{ + relatedNotice := roomdb.Notice{ ID: n.ID, Title: n.Title, Content: n.Content, @@ -66,7 +66,7 @@ func (pn PinnedNotices) List(ctx context.Context) (admindb.PinnedNotices, error) return pinnedMap, nil } -func (pn PinnedNotices) Get(ctx context.Context, name admindb.PinnedNoticeName, lang string) (*admindb.Notice, error) { +func (pn PinnedNotices) Get(ctx context.Context, name roomdb.PinnedNoticeName, lang string) (*roomdb.Notice, error) { p, err := models.Pins( qm.Where("name = ?", name), qm.Load("Notices", qm.Where("language = ?", lang)), @@ -81,7 +81,7 @@ func (pn PinnedNotices) Get(ctx context.Context, name admindb.PinnedNoticeName, modelNotice := p.R.Notices[0] - return &admindb.Notice{ + return &roomdb.Notice{ ID: modelNotice.ID, Title: modelNotice.Title, Content: modelNotice.Content, @@ -89,7 +89,7 @@ func (pn PinnedNotices) Get(ctx context.Context, name admindb.PinnedNoticeName, }, nil } -func (pn PinnedNotices) Set(ctx context.Context, name admindb.PinnedNoticeName, noticeID int64) error { +func (pn PinnedNotices) Set(ctx context.Context, name roomdb.PinnedNoticeName, noticeID int64) error { if !name.Valid() { return fmt.Errorf("pinned notice: invalid notice name: %s", name) } @@ -113,19 +113,19 @@ func (pn PinnedNotices) Set(ctx context.Context, name admindb.PinnedNoticeName, } // compiler assertion to ensure the struct fullfills the interface -var _ admindb.NoticesService = (*Notices)(nil) +var _ roomdb.NoticesService = (*Notices)(nil) type Notices struct { db *sql.DB } -func (n Notices) GetByID(ctx context.Context, id int64) (admindb.Notice, error) { - var notice admindb.Notice +func (n Notices) GetByID(ctx context.Context, id int64) (roomdb.Notice, error) { + var notice roomdb.Notice dbEntry, err := models.FindNotice(ctx, n.db, id) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return notice, admindb.ErrNotFound + return notice, roomdb.ErrNotFound } return notice, err } @@ -143,7 +143,7 @@ func (n Notices) RemoveID(ctx context.Context, id int64) error { dbEntry, err := models.FindNotice(ctx, n.db, id) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return admindb.ErrNotFound + return roomdb.ErrNotFound } return err } @@ -156,7 +156,7 @@ func (n Notices) RemoveID(ctx context.Context, id int64) error { return nil } -func (n Notices) Save(ctx context.Context, p *admindb.Notice) error { +func (n Notices) Save(ctx context.Context, p *roomdb.Notice) error { if p.ID == 0 { var newEntry models.Notice newEntry.Title = p.Title @@ -178,7 +178,7 @@ func (n Notices) Save(ctx context.Context, p *admindb.Notice) error { _, err := existing.Update(ctx, n.db, boil.Whitelist("title", "content", "language")) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return admindb.ErrNotFound + return roomdb.ErrNotFound } return err } diff --git a/admindb/sqlite/notices_test.go b/roomdb/sqlite/notices_test.go similarity index 79% rename from admindb/sqlite/notices_test.go rename to roomdb/sqlite/notices_test.go index 6ef68a7..1912470 100644 --- a/admindb/sqlite/notices_test.go +++ b/roomdb/sqlite/notices_test.go @@ -8,7 +8,7 @@ import ( "path/filepath" "testing" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" "github.com/stretchr/testify/require" ) @@ -33,16 +33,16 @@ func TestNoticesCRUD(t *testing.T) { _, err = db.Notices.GetByID(ctx, 9999) r.Error(err) - r.EqualError(err, admindb.ErrNotFound.Error()) + r.EqualError(err, roomdb.ErrNotFound.Error()) err = db.Notices.RemoveID(ctx, 9999) r.Error(err) - r.EqualError(err, admindb.ErrNotFound.Error()) + r.EqualError(err, roomdb.ErrNotFound.Error()) }) t.Run("new and update", func(t *testing.T) { r := require.New(t) - var n admindb.Notice + var n roomdb.Notice n.Title = fmt.Sprintf("Test notice %d", rand.Int()) n.Content = `# This is **not** a test!` @@ -70,7 +70,7 @@ func TestNoticesCRUD(t *testing.T) { _, err = db.Notices.GetByID(ctx, oldID) r.Error(err) - r.EqualError(err, admindb.ErrNotFound.Error()) + r.EqualError(err, roomdb.ErrNotFound.Error()) }) } @@ -91,15 +91,15 @@ func TestPinnedNotices(t *testing.T) { r.NoError(err) type expectedNotices struct { - Name admindb.PinnedNoticeName + Name roomdb.PinnedNoticeName Count int } cases := []expectedNotices{ - {admindb.NoticeDescription, 2}, - {admindb.NoticeNews, 1}, - {admindb.NoticePrivacyPolicy, 2}, - {admindb.NoticeCodeOfConduct, 1}, + {roomdb.NoticeDescription, 2}, + {roomdb.NoticeNews, 1}, + {roomdb.NoticePrivacyPolicy, 2}, + {roomdb.NoticeCodeOfConduct, 1}, } for i, tcase := range cases { @@ -110,14 +110,14 @@ func TestPinnedNotices(t *testing.T) { }) t.Run("validity", func(t *testing.T) { - var empty admindb.Notice + var empty roomdb.Notice // no id - err = db.PinnedNotices.Set(ctx, admindb.NoticeNews, empty.ID) + err = db.PinnedNotices.Set(ctx, roomdb.NoticeNews, empty.ID) r.Error(err) // not-null id empty.ID = 999 - err = db.PinnedNotices.Set(ctx, admindb.NoticeNews, empty.ID) + err = db.PinnedNotices.Set(ctx, roomdb.NoticeNews, empty.ID) r.Error(err) // invalid notice name @@ -126,7 +126,7 @@ func TestPinnedNotices(t *testing.T) { }) t.Run("add new localization", func(t *testing.T) { - var notice admindb.Notice + var notice roomdb.Notice notice.Title = "polĂ­tica de privacidad" notice.Content = "solo una prueba" notice.Language = "es" @@ -136,11 +136,11 @@ func TestPinnedNotices(t *testing.T) { r.NoError(err) // set it - err = db.PinnedNotices.Set(ctx, admindb.NoticePrivacyPolicy, notice.ID) + err = db.PinnedNotices.Set(ctx, roomdb.NoticePrivacyPolicy, notice.ID) r.NoError(err) // retreive it - ret, err := db.PinnedNotices.Get(ctx, admindb.NoticePrivacyPolicy, notice.Language) + ret, err := db.PinnedNotices.Get(ctx, roomdb.NoticePrivacyPolicy, notice.Language) r.NoError(err) r.Equal(notice, *ret, "notices are not the same") @@ -148,7 +148,7 @@ func TestPinnedNotices(t *testing.T) { allTheNotices, err := db.PinnedNotices.List(ctx) r.NoError(err) - notices, has := allTheNotices[admindb.NoticePrivacyPolicy] + notices, has := allTheNotices[roomdb.NoticePrivacyPolicy] r.True(has) r.Len(notices, 3) diff --git a/admindb/sqlite/roomcfg.go b/roomdb/sqlite/roomcfg.go similarity index 83% rename from admindb/sqlite/roomcfg.go rename to roomdb/sqlite/roomcfg.go index 1847701..0f0dc0e 100644 --- a/admindb/sqlite/roomcfg.go +++ b/roomdb/sqlite/roomcfg.go @@ -12,13 +12,13 @@ import ( "github.com/volatiletech/sqlboiler/v4/boil" "github.com/volatiletech/sqlboiler/v4/queries/qm" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/sqlite/models" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite/models" refs "go.mindeco.de/ssb-refs" ) // compiler assertion to ensure the struct fullfills the interface -var _ admindb.AllowListService = (*AllowList)(nil) +var _ roomdb.AllowListService = (*AllowList)(nil) type AllowList struct { db *sql.DB @@ -46,7 +46,7 @@ func (l AllowList) add(ctx context.Context, tx *sql.Tx, a refs.FeedRef) error { if err != nil { var sqlErr sqlite3.Error if errors.As(err, &sqlErr) && sqlErr.ExtendedCode == sqlite3.ErrConstraintUnique { - return admindb.ErrAlreadyAdded{Ref: a} + return roomdb.ErrAlreadyAdded{Ref: a} } return fmt.Errorf("allow-list: failed to insert new entry %s: %w - type:%T", entry.PubKey, err, err) @@ -74,12 +74,12 @@ func (l AllowList) HasID(ctx context.Context, id int64) bool { } // GetByID returns the entry if a feed with that ID is on the list. -func (l AllowList) GetByID(ctx context.Context, id int64) (admindb.ListEntry, error) { - var le admindb.ListEntry +func (l AllowList) GetByID(ctx context.Context, id int64) (roomdb.ListEntry, error) { + var le roomdb.ListEntry entry, err := models.FindAllowList(ctx, l.db, id) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return le, admindb.ErrNotFound + return le, roomdb.ErrNotFound } return le, err } @@ -91,16 +91,16 @@ func (l AllowList) GetByID(ctx context.Context, id int64) (admindb.ListEntry, er } // List returns a list of all the feeds. -func (l AllowList) List(ctx context.Context) (admindb.ListEntries, error) { +func (l AllowList) List(ctx context.Context) (roomdb.ListEntries, error) { all, err := models.AllowLists().All(ctx, l.db) if err != nil { return nil, err } - var asRefs = make(admindb.ListEntries, len(all)) + var asRefs = make(roomdb.ListEntries, len(all)) for i, allowed := range all { - asRefs[i] = admindb.ListEntry{ + asRefs[i] = roomdb.ListEntry{ ID: allowed.ID, PubKey: allowed.PubKey.FeedRef, } @@ -114,7 +114,7 @@ func (l AllowList) RemoveFeed(ctx context.Context, r refs.FeedRef) error { entry, err := models.AllowLists(qm.Where("pub_key = ?", r.Ref())).One(ctx, l.db) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return admindb.ErrNotFound + return roomdb.ErrNotFound } return err } @@ -132,7 +132,7 @@ func (l AllowList) RemoveID(ctx context.Context, id int64) error { entry, err := models.FindAllowList(ctx, l.db, id) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return admindb.ErrNotFound + return roomdb.ErrNotFound } return err } diff --git a/admindb/sqlite/roomcfg_test.go b/roomdb/sqlite/roomcfg_test.go similarity index 94% rename from admindb/sqlite/roomcfg_test.go rename to roomdb/sqlite/roomcfg_test.go index b6db956..f85f107 100644 --- a/admindb/sqlite/roomcfg_test.go +++ b/roomdb/sqlite/roomcfg_test.go @@ -7,9 +7,9 @@ import ( "path/filepath" "testing" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/sqlite/models" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite/models" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" "github.com/stretchr/testify/require" refs "go.mindeco.de/ssb-refs" @@ -124,7 +124,7 @@ func TestAllowListByID(t *testing.T) { err = db.AllowList.RemoveID(ctx, 666) r.Error(err) - r.EqualError(err, admindb.ErrNotFound.Error()) + r.EqualError(err, roomdb.ErrNotFound.Error()) err = db.AllowList.RemoveID(ctx, lst[0].ID) r.NoError(err) diff --git a/admindb/sqlite/sqlboiler.toml b/roomdb/sqlite/sqlboiler.toml similarity index 78% rename from admindb/sqlite/sqlboiler.toml rename to roomdb/sqlite/sqlboiler.toml index 34f33dd..17ff8b9 100644 --- a/admindb/sqlite/sqlboiler.toml +++ b/roomdb/sqlite/sqlboiler.toml @@ -13,7 +13,7 @@ blacklist = ["gorp_migrations"] nullable = false [types.replace] - type = "admindb.DBFeedRef" + type = "roomdb.DBFeedRef" [types.imports] - third_party = ['"github.com/ssb-ngi-pointer/go-ssb-room/admindb"'] \ No newline at end of file + third_party = ['"github.com/ssb-ngi-pointer/go-ssb-room/roomdb"'] \ No newline at end of file diff --git a/roomdb/sqlite/testrun/TestAllowList/roomdb b/roomdb/sqlite/testrun/TestAllowList/roomdb new file mode 100644 index 0000000..d13da5d Binary files /dev/null and b/roomdb/sqlite/testrun/TestAllowList/roomdb differ diff --git a/roomdb/sqlite/testrun/TestAllowListByID/roomdb b/roomdb/sqlite/testrun/TestAllowListByID/roomdb new file mode 100644 index 0000000..36ce9e5 Binary files /dev/null and b/roomdb/sqlite/testrun/TestAllowListByID/roomdb differ diff --git a/roomdb/sqlite/testrun/TestAllowListUnique/roomdb b/roomdb/sqlite/testrun/TestAllowListUnique/roomdb new file mode 100644 index 0000000..b0fb2a6 Binary files /dev/null and b/roomdb/sqlite/testrun/TestAllowListUnique/roomdb differ diff --git a/roomdb/sqlite/testrun/TestInvites/roomdb b/roomdb/sqlite/testrun/TestInvites/roomdb new file mode 100644 index 0000000..234fd1d Binary files /dev/null and b/roomdb/sqlite/testrun/TestInvites/roomdb differ diff --git a/roomdb/sqlite/testrun/TestNotices/roomdb b/roomdb/sqlite/testrun/TestNotices/roomdb new file mode 100644 index 0000000..60394af Binary files /dev/null and b/roomdb/sqlite/testrun/TestNotices/roomdb differ diff --git a/roomdb/sqlite/testrun/TestNoticesCRUD/roomdb b/roomdb/sqlite/testrun/TestNoticesCRUD/roomdb new file mode 100644 index 0000000..9d3c5ac Binary files /dev/null and b/roomdb/sqlite/testrun/TestNoticesCRUD/roomdb differ diff --git a/roomdb/sqlite/testrun/TestPinnedNotices/roomdb b/roomdb/sqlite/testrun/TestPinnedNotices/roomdb new file mode 100644 index 0000000..17cd9cb Binary files /dev/null and b/roomdb/sqlite/testrun/TestPinnedNotices/roomdb differ diff --git a/roomdb/sqlite/testrun/TestSimple/roomdb b/roomdb/sqlite/testrun/TestSimple/roomdb new file mode 100644 index 0000000..e4f45f4 Binary files /dev/null and b/roomdb/sqlite/testrun/TestSimple/roomdb differ diff --git a/admindb/types.go b/roomdb/types.go similarity index 95% rename from admindb/types.go rename to roomdb/types.go index faab751..da9890d 100644 --- a/admindb/types.go +++ b/roomdb/types.go @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -package admindb +package roomdb import ( "database/sql/driver" @@ -12,7 +12,7 @@ import ( ) // ErrNotFound is returned by the admin db if an object couldn't be found. -var ErrNotFound = errors.New("admindb: object not found") +var ErrNotFound = errors.New("roomdb: object not found") // User holds all the information an authenticated user of the site has. type User struct { @@ -25,7 +25,7 @@ type ErrAlreadyAdded struct { } func (aa ErrAlreadyAdded) Error() string { - return fmt.Sprintf("admindb: the item (%s) is already on the list", aa.Ref.Ref()) + return fmt.Sprintf("roomdb: the item (%s) is already on the list", aa.Ref.Ref()) } // Invite is a combination of an invite id, who created it and an (optional) alias suggestion. diff --git a/roomsrv/server.go b/roomsrv/server.go index 60f92bb..f051f0e 100644 --- a/roomsrv/server.go +++ b/roomsrv/server.go @@ -12,10 +12,6 @@ import ( "path/filepath" "sync" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" - - "github.com/ssb-ngi-pointer/go-ssb-room/roomstate" - kitlog "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "go.cryptoscope.co/netwrap" @@ -25,6 +21,8 @@ import ( "github.com/ssb-ngi-pointer/go-ssb-room/internal/maybemuxrpc" "github.com/ssb-ngi-pointer/go-ssb-room/internal/network" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomstate" refs "go.mindeco.de/ssb-refs" ) @@ -58,7 +56,7 @@ type Server struct { public maybemuxrpc.PluginManager master maybemuxrpc.PluginManager - authorizer admindb.AllowListService + authorizer roomdb.AllowListService StateManager *roomstate.Manager } @@ -67,7 +65,7 @@ func (s Server) Whoami() refs.FeedRef { return s.keyPair.Feed } -func New(allow admindb.AllowListService, opts ...Option) (*Server, error) { +func New(allow roomdb.AllowListService, opts ...Option) (*Server, error) { var s Server s.authorizer = allow diff --git a/test/go/utils_test.go b/test/go/utils_test.go index 29c50df..686572b 100644 --- a/test/go/utils_test.go +++ b/test/go/utils_test.go @@ -18,7 +18,7 @@ import ( "github.com/stretchr/testify/require" "go.cryptoscope.co/muxrpc/v2/debug" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/sqlite" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/sqlite" "github.com/ssb-ngi-pointer/go-ssb-room/internal/maybemod/testutils" "github.com/ssb-ngi-pointer/go-ssb-room/internal/network" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" diff --git a/test/nodejs/announce_test.go b/test/nodejs/announce_test.go index 9546c87..00bf025 100644 --- a/test/nodejs/announce_test.go +++ b/test/nodejs/announce_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/mockdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/mockdb" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/test/nodejs/setup_test.go b/test/nodejs/setup_test.go index abd491a..f45adb2 100644 --- a/test/nodejs/setup_test.go +++ b/test/nodejs/setup_test.go @@ -17,7 +17,7 @@ import ( "path/filepath" "testing" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "golang.org/x/sync/errgroup" @@ -86,7 +86,7 @@ func newSession(t *testing.T, appKey []byte) *testSession { return ts } -func (ts *testSession) startGoServer(al admindb.AllowListService, opts ...roomsrv.Option) *roomsrv.Server { +func (ts *testSession) startGoServer(al roomdb.AllowListService, opts ...roomsrv.Option) *roomsrv.Server { r := require.New(ts.t) // prepend defaults diff --git a/web/handlers/admin/allow_list.go b/web/handlers/admin/allow_list.go index de989ce..f610ae8 100644 --- a/web/handlers/admin/allow_list.go +++ b/web/handlers/admin/allow_list.go @@ -10,14 +10,14 @@ import ( refs "go.mindeco.de/ssb-refs" "github.com/gorilla/csrf" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors" ) type allowListHandler struct { r *render.Renderer - al admindb.AllowListService + al roomdb.AllowListService } const redirectToMembers = "/admin/members" @@ -45,7 +45,7 @@ func (h allowListHandler) add(w http.ResponseWriter, req *http.Request) { err = h.al.Add(req.Context(), *newEntryParsed) if err != nil { code := http.StatusInternalServerError - var aa admindb.ErrAlreadyAdded + var aa roomdb.ErrAlreadyAdded if errors.As(err, &aa) { code = http.StatusBadRequest // TODO: localized error pages @@ -92,7 +92,7 @@ func (h allowListHandler) removeConfirm(rw http.ResponseWriter, req *http.Reques entry, err := h.al.GetByID(req.Context(), id) if err != nil { - if errors.Is(err, admindb.ErrNotFound) { + if errors.Is(err, roomdb.ErrNotFound) { http.Redirect(rw, req, redirectToMembers, http.StatusFound) return nil, ErrRedirected } @@ -125,7 +125,7 @@ func (h allowListHandler) remove(rw http.ResponseWriter, req *http.Request) { status := http.StatusFound err = h.al.RemoveID(req.Context(), id) if err != nil { - if !errors.Is(err, admindb.ErrNotFound) { + if !errors.Is(err, roomdb.ErrNotFound) { // TODO "flash" errors h.r.Error(rw, req, http.StatusInternalServerError, err) return diff --git a/web/handlers/admin/allow_list_test.go b/web/handlers/admin/allow_list_test.go index 68726fb..0a0953c 100644 --- a/web/handlers/admin/allow_list_test.go +++ b/web/handlers/admin/allow_list_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/ssb-ngi-pointer/go-ssb-room/web" "github.com/ssb-ngi-pointer/go-ssb-room/web/router" refs "go.mindeco.de/ssb-refs" @@ -111,7 +111,7 @@ func TestAllowList(t *testing.T) { ts := newSession(t) a := assert.New(t) - lst := admindb.ListEntries{ + lst := roomdb.ListEntries{ {ID: 1, PubKey: refs.FeedRef{ID: bytes.Repeat([]byte{0}, 32), Algo: "fake"}}, {ID: 2, PubKey: refs.FeedRef{ID: bytes.Repeat([]byte("1312"), 8), Algo: "test"}}, {ID: 3, PubKey: refs.FeedRef{ID: bytes.Repeat([]byte("acab"), 8), Algo: "true"}}, @@ -129,7 +129,7 @@ func TestAllowList(t *testing.T) { a.EqualValues(html.Find("#theList li").Length(), 3) - lst = admindb.ListEntries{ + lst = roomdb.ListEntries{ {ID: 666, PubKey: refs.FeedRef{ID: bytes.Repeat([]byte{1}, 32), Algo: "one"}}, } ts.AllowListDB.ListReturns(lst, nil) @@ -158,7 +158,7 @@ func TestAllowListRemoveConfirmation(t *testing.T) { testKey, err := refs.ParseFeedRef("@x7iOLUcq3o+sjGeAnipvWeGzfuYgrXl8L4LYlxIhwDc=.ed25519") a.NoError(err) - testEntry := admindb.ListEntry{ID: 666, PubKey: *testKey} + testEntry := roomdb.ListEntry{ID: 666, PubKey: *testKey} ts.AllowListDB.GetByIDReturns(testEntry, nil) urlTo := web.NewURLTo(ts.Router) @@ -213,7 +213,7 @@ func TestAllowListRemove(t *testing.T) { a.EqualValues(666, theID) // now for unknown ID - ts.AllowListDB.RemoveIDReturns(admindb.ErrNotFound) + ts.AllowListDB.RemoveIDReturns(roomdb.ErrNotFound) addVals = url.Values{"id": []string{"667"}} rec = ts.Client.PostForm(urlRemove.String(), addVals) a.Equal(http.StatusNotFound, rec.Code) diff --git a/web/handlers/admin/app_test.go b/web/handlers/admin/app_test.go index f2ec299..832c156 100644 --- a/web/handlers/admin/app_test.go +++ b/web/handlers/admin/app_test.go @@ -14,8 +14,8 @@ import ( "go.mindeco.de/http/tester" "go.mindeco.de/logging/logtest" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/mockdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/mockdb" "github.com/ssb-ngi-pointer/go-ssb-room/roomstate" "github.com/ssb-ngi-pointer/go-ssb-room/web" "github.com/ssb-ngi-pointer/go-ssb-room/web/router" @@ -32,7 +32,7 @@ type testSession struct { NoticeDB *mockdb.FakeNoticesService InvitesDB *mockdb.FakeInviteService - User *admindb.User + User *roomdb.User Domain string @@ -57,7 +57,7 @@ func newSession(t *testing.T) *testSession { ts.Domain = randomString(10) // fake user - ts.User = &admindb.User{ + ts.User = &roomdb.User{ ID: 1234, Name: "room mate", } @@ -76,7 +76,7 @@ func newSession(t *testing.T) *testSession { testFuncs["current_page_is"] = func(routeName string) bool { return true } - testFuncs["is_logged_in"] = func() *admindb.User { return nil } + testFuncs["is_logged_in"] = func() *roomdb.User { return nil } testFuncs["urlToNotice"] = func(name string) string { return "" } r, err := render.New(web.Templates, diff --git a/web/handlers/admin/handler.go b/web/handlers/admin/handler.go index f4349d9..719a4a4 100644 --- a/web/handlers/admin/handler.go +++ b/web/handlers/admin/handler.go @@ -14,7 +14,7 @@ import ( "github.com/vcraescu/go-paginator/v2/view" "go.mindeco.de/http/render" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/ssb-ngi-pointer/go-ssb-room/roomstate" ) @@ -34,10 +34,10 @@ var HTMLTemplates = []string{ // Databases is an option struct that encapsualtes the required database services type Databases struct { - AllowList admindb.AllowListService - Invites admindb.InviteService - Notices admindb.NoticesService - PinnedNotices admindb.PinnedNoticesService + AllowList roomdb.AllowListService + Invites roomdb.InviteService + Notices roomdb.NoticesService + PinnedNotices roomdb.PinnedNoticesService } // Handler supplies the elevated access pages to known users. diff --git a/web/handlers/admin/invites.go b/web/handlers/admin/invites.go index bdb1275..6ca5eca 100644 --- a/web/handlers/admin/invites.go +++ b/web/handlers/admin/invites.go @@ -9,7 +9,7 @@ import ( "github.com/gorilla/csrf" "go.mindeco.de/http/render" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/ssb-ngi-pointer/go-ssb-room/web" weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors" "github.com/ssb-ngi-pointer/go-ssb-room/web/router" @@ -19,7 +19,7 @@ import ( type invitesHandler struct { r *render.Renderer - db admindb.InviteService + db roomdb.InviteService domainName string } @@ -88,7 +88,7 @@ func (h invitesHandler) revokeConfirm(rw http.ResponseWriter, req *http.Request) invite, err := h.db.GetByID(req.Context(), id) if err != nil { - if errors.Is(err, admindb.ErrNotFound) { + if errors.Is(err, roomdb.ErrNotFound) { return nil, weberrors.ErrNotFound{What: "invite"} } return nil, err @@ -122,7 +122,7 @@ func (h invitesHandler) revoke(rw http.ResponseWriter, req *http.Request) { status := http.StatusFound err = h.db.Revoke(req.Context(), id) if err != nil { - if !errors.Is(err, admindb.ErrNotFound) { + if !errors.Is(err, roomdb.ErrNotFound) { // TODO "flash" errors h.r.Error(rw, req, http.StatusInternalServerError, err) return diff --git a/web/handlers/admin/notices.go b/web/handlers/admin/notices.go index 9b47697..c84e708 100644 --- a/web/handlers/admin/notices.go +++ b/web/handlers/admin/notices.go @@ -11,7 +11,7 @@ import ( "github.com/gorilla/csrf" "github.com/russross/blackfriday/v2" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors" "go.mindeco.de/http/render" ) @@ -19,14 +19,14 @@ import ( type noticeHandler struct { r *render.Renderer - noticeDB admindb.NoticesService - pinnedDB admindb.PinnedNoticesService + noticeDB roomdb.NoticesService + pinnedDB roomdb.PinnedNoticesService } func (nh noticeHandler) draftTranslation(rw http.ResponseWriter, req *http.Request) (interface{}, error) { pinnedName := req.URL.Query().Get("name") - if !admindb.PinnedNoticeName(pinnedName).Valid() { + if !roomdb.PinnedNoticeName(pinnedName).Valid() { return nil, weberrors.ErrBadRequest{Where: "pinnedName", Details: fmt.Errorf("invalid pinned notice name")} } @@ -45,14 +45,14 @@ func (nh noticeHandler) addTranslation(rw http.ResponseWriter, req *http.Request return } - pinnedName := admindb.PinnedNoticeName(req.FormValue("name")) + pinnedName := roomdb.PinnedNoticeName(req.FormValue("name")) if !pinnedName.Valid() { err := weberrors.ErrBadRequest{Where: "name", Details: fmt.Errorf("invalid pinned notice name")} nh.r.Error(rw, req, http.StatusInternalServerError, err) return } - var n admindb.Notice + var n roomdb.Notice n.Title = req.FormValue("title") // TODO: validate languages properly @@ -128,7 +128,7 @@ func (nh noticeHandler) save(rw http.ResponseWriter, req *http.Request) { redirect = "/" } - var n admindb.Notice + var n roomdb.Notice n.ID, err = strconv.ParseInt(req.FormValue("id"), 10, 64) if err != nil { err = weberrors.ErrBadRequest{Where: "id", Details: err} diff --git a/web/handlers/http.go b/web/handlers/http.go index aa759b4..c60c48e 100644 --- a/web/handlers/http.go +++ b/web/handlers/http.go @@ -19,7 +19,7 @@ import ( "go.mindeco.de/logging" "golang.org/x/crypto/ed25519" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" "github.com/ssb-ngi-pointer/go-ssb-room/roomstate" "github.com/ssb-ngi-pointer/go-ssb-room/web" @@ -42,12 +42,12 @@ var HTMLTemplates = []string{ // Databases is an options stuct for the required databases of the web handlers type Databases struct { - AuthWithSSB admindb.AuthWithSSBService - AuthFallback admindb.AuthFallbackService - AllowList admindb.AllowListService - Invites admindb.InviteService - Notices admindb.NoticesService - PinnedNotices admindb.PinnedNoticesService + AuthWithSSB roomdb.AuthWithSSBService + AuthFallback roomdb.AuthFallbackService + AllowList roomdb.AllowListService + Invites roomdb.InviteService + Notices roomdb.NoticesService + PinnedNotices roomdb.PinnedNoticesService } // NetworkInfo encapsulates the domain name of the room, it's ssb/secret-handshake public key and the HTTP and MUXRPC TCP ports. @@ -106,7 +106,7 @@ func New( }), render.InjectTemplateFunc("urlToNotice", func(r *http.Request) interface{} { return func(name string) *url.URL { - noticeName := admindb.PinnedNoticeName(name) + noticeName := roomdb.PinnedNoticeName(name) if !noticeName.Valid() { return nil } @@ -157,13 +157,13 @@ func New( // localize some specific error messages var ( - aa admindb.ErrAlreadyAdded + aa roomdb.ErrAlreadyAdded ) switch { case err == auth.ErrBadLogin: msg = ih.LocalizeSimple("AuthErrorBadLogin") - case errors.Is(err, admindb.ErrNotFound): + case errors.Is(err, roomdb.ErrNotFound): msg = ih.LocalizeSimple("ErrorNotFound") case errors.As(err, &aa): @@ -235,7 +235,7 @@ func New( mainMux.Handle("/admin/", a.Authenticate(adminHandler)) m.Get(router.CompleteIndex).Handler(r.HTML("landing/index.tmpl", func(w http.ResponseWriter, req *http.Request) (interface{}, error) { - notice, err := dbs.PinnedNotices.Get(req.Context(), admindb.NoticeDescription, "en-GB") + notice, err := dbs.PinnedNotices.Get(req.Context(), roomdb.NoticeDescription, "en-GB") if err != nil { return nil, fmt.Errorf("failed to find description: %w", err) } diff --git a/web/handlers/invites.go b/web/handlers/invites.go index 2fcc93b..a1881b7 100644 --- a/web/handlers/invites.go +++ b/web/handlers/invites.go @@ -12,7 +12,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/gorilla/csrf" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors" refs "go.mindeco.de/ssb-refs" ) @@ -20,8 +20,8 @@ import ( type inviteHandler struct { r *render.Renderer - invites admindb.InviteService - alaises admindb.AliasService + invites roomdb.InviteService + alaises roomdb.AliasService muxrpcHostAndPort string roomPubKey ed25519.PublicKey @@ -32,7 +32,7 @@ func (h inviteHandler) acceptForm(rw http.ResponseWriter, req *http.Request) (in inv, err := h.invites.GetByToken(req.Context(), token) if err != nil { - if errors.Is(err, admindb.ErrNotFound) { + if errors.Is(err, roomdb.ErrNotFound) { return nil, weberrors.ErrNotFound{What: "invite"} } return nil, err @@ -62,7 +62,7 @@ func (h inviteHandler) consume(rw http.ResponseWriter, req *http.Request) (inter inv, err := h.invites.Consume(req.Context(), token, *newMember) if err != nil { - if errors.Is(err, admindb.ErrNotFound) { + if errors.Is(err, roomdb.ErrNotFound) { return nil, weberrors.ErrNotFound{What: "invite"} } return nil, err diff --git a/web/handlers/invites_test.go b/web/handlers/invites_test.go index eb82812..0ca7095 100644 --- a/web/handlers/invites_test.go +++ b/web/handlers/invites_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" refs "go.mindeco.de/ssb-refs" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/ssb-ngi-pointer/go-ssb-room/web" weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors" "github.com/ssb-ngi-pointer/go-ssb-room/web/router" @@ -34,7 +34,7 @@ func TestInviteShowAcceptForm(t *testing.T) { r.NotNil(acceptURL404) // prep the mocked db for http:404 - ts.InvitesDB.GetByTokenReturns(admindb.Invite{}, admindb.ErrNotFound) + ts.InvitesDB.GetByTokenReturns(roomdb.Invite{}, roomdb.ErrNotFound) // request the form acceptForm := acceptURL404.String() @@ -68,7 +68,7 @@ func TestInviteShowAcceptForm(t *testing.T) { r.NotNil(validAcceptURL) // prep the mocked db for http:200 - fakeExistingInvite := admindb.Invite{ + fakeExistingInvite := roomdb.Invite{ ID: 1234, AliasSuggestion: "bestie", } @@ -109,7 +109,7 @@ func TestInviteShowAcceptForm(t *testing.T) { validAcceptURL := urlTo(router.CompleteInviteAccept, "token", testToken) r.NotNil(validAcceptURL) - inviteWithNoAlias := admindb.Invite{ID: 4321} + inviteWithNoAlias := roomdb.Invite{ID: 4321} ts.InvitesDB.GetByTokenReturns(inviteWithNoAlias, nil) // request the form @@ -152,7 +152,7 @@ func TestInviteConsumeInvite(t *testing.T) { validAcceptURL.Host = "localhost" validAcceptURL.Scheme = "https" - inviteWithNoAlias := admindb.Invite{ID: 4321} + inviteWithNoAlias := roomdb.Invite{ID: 4321} ts.InvitesDB.GetByTokenReturns(inviteWithNoAlias, nil) // request the form (for a valid csrf token) diff --git a/web/handlers/notices.go b/web/handlers/notices.go index b683add..d324b2e 100644 --- a/web/handlers/notices.go +++ b/web/handlers/notices.go @@ -7,13 +7,13 @@ import ( "github.com/russross/blackfriday/v2" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "github.com/ssb-ngi-pointer/go-ssb-room/web/errors" ) type noticeHandler struct { - pinned admindb.PinnedNoticesService - notices admindb.NoticesService + pinned roomdb.PinnedNoticesService + notices roomdb.NoticesService } func (h noticeHandler) list(rw http.ResponseWriter, req *http.Request) (interface{}, error) { @@ -24,7 +24,7 @@ func (h noticeHandler) list(rw http.ResponseWriter, req *http.Request) (interfac } return struct { - AllNotices admindb.SortedPinnedNotices + AllNotices roomdb.SortedPinnedNotices }{lst.Sorted()}, nil } diff --git a/web/handlers/setup_test.go b/web/handlers/setup_test.go index 6c42729..77003db 100644 --- a/web/handlers/setup_test.go +++ b/web/handlers/setup_test.go @@ -17,8 +17,8 @@ import ( "go.mindeco.de/http/tester" "go.mindeco.de/logging/logtest" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb/mockdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb/mockdb" "github.com/ssb-ngi-pointer/go-ssb-room/internal/repo" "github.com/ssb-ngi-pointer/go-ssb-room/roomstate" "github.com/ssb-ngi-pointer/go-ssb-room/web/i18n" @@ -64,7 +64,7 @@ func setup(t *testing.T) *testSession { ts.AllowListDB = new(mockdb.FakeAllowListService) ts.InvitesDB = new(mockdb.FakeInviteService) ts.PinnedDB = new(mockdb.FakePinnedNoticesService) - defaultNotice := &admindb.Notice{ + defaultNotice := &roomdb.Notice{ Title: "Default Notice Title", Content: "Default Notice Content", } diff --git a/web/user/helper.go b/web/user/helper.go index f13aa01..b9e42f1 100644 --- a/web/user/helper.go +++ b/web/user/helper.go @@ -5,7 +5,7 @@ import ( "context" "net/http" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" "go.mindeco.de/http/auth" ) @@ -14,10 +14,10 @@ type roomUserContextKeyType string var roomUserContextKey roomUserContextKeyType = "ssb:room:httpcontext:user" // FromContext returns the user or nil if not logged in -func FromContext(ctx context.Context) *admindb.User { +func FromContext(ctx context.Context) *roomdb.User { v := ctx.Value(roomUserContextKey) - user, ok := v.(*admindb.User) + user, ok := v.(*roomdb.User) if !ok { return nil } @@ -26,7 +26,7 @@ func FromContext(ctx context.Context) *admindb.User { } // ContextInjecter returns middleware for injecting a user id into the request context -func ContextInjecter(fs admindb.AuthFallbackService, a *auth.Handler) func(http.Handler) http.Handler { +func ContextInjecter(fs roomdb.AuthFallbackService, a *auth.Handler) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { v, err := a.AuthenticateRequest(req) @@ -57,14 +57,14 @@ func ContextInjecter(fs admindb.AuthFallbackService, a *auth.Handler) func(http. // It has to return a function twice because the first is evaluated with the request before it gets passed onto html/template's FuncMap. func TemplateHelper() func(*http.Request) interface{} { return func(r *http.Request) interface{} { - no := func() *admindb.User { return nil } + no := func() *roomdb.User { return nil } user := FromContext(r.Context()) if user == nil { return no } - yes := func() *admindb.User { return user } + yes := func() *roomdb.User { return user } return yes } } diff --git a/web/user/testing.go b/web/user/testing.go index 1a6f8db..3318e17 100644 --- a/web/user/testing.go +++ b/web/user/testing.go @@ -4,14 +4,14 @@ import ( "context" "net/http" - "github.com/ssb-ngi-pointer/go-ssb-room/admindb" + "github.com/ssb-ngi-pointer/go-ssb-room/roomdb" ) // MiddlewareForTests gives us a way to inject _test users_. It should not be used in production. // This is part of testing.go because we need to use roomUserContextKey, which shouldn't be exported either. // TODO: could be protected with an extra build tag. // (Sadly +build test does not exist https://github.com/golang/go/issues/21360 ) -func MiddlewareForTests(user *admindb.User) func(http.Handler) http.Handler { +func MiddlewareForTests(user *roomdb.User) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { ctx := context.WithValue(req.Context(), roomUserContextKey, user)