go-ssb-room/admindb/interface.go

83 lines
2.6 KiB
Go
Raw Normal View History

2021-02-09 11:53:33 +00:00
// SPDX-License-Identifier: MIT
2021-02-08 11:57:14 +00:00
package admindb
import (
"context"
2021-02-08 11:57:14 +00:00
"go.mindeco.de/http/auth"
2021-02-11 15:43:19 +00:00
refs "go.mindeco.de/ssb-refs"
2021-02-08 11:57:14 +00:00
)
2021-02-08 16:47:42 +00:00
// AuthFallbackService might be helpful for scenarios where one lost access to his ssb device or key
type AuthFallbackService interface {
2021-02-08 11:57:14 +00:00
auth.Auther
2021-02-08 16:47:42 +00:00
Create(ctx context.Context, user string, password []byte) error
GetByID(ctx context.Context, uid int64) (*User, error)
2021-02-08 11:57:14 +00:00
}
2021-02-08 16:47:42 +00:00
// AuthWithSSBService defines functions needed for the challange/response system of sign-in with ssb
type AuthWithSSBService interface{}
2021-02-08 11:57:14 +00:00
// AllowListService changes the lists of people that are allowed to get into the room
2021-02-11 15:43:19 +00:00
type AllowListService interface {
// Add adds the feed to the list.
Add(context.Context, refs.FeedRef) error
// HasFeed returns true if a feed is on the list.
HasFeed(context.Context, refs.FeedRef) bool
// HasFeed returns true if a feed is on the list.
HasID(context.Context, int64) bool
2021-02-11 15:43:19 +00:00
// GetByID returns the list entry for that ID or an error
GetByID(context.Context, int64) (ListEntry, error)
2021-02-11 15:43:19 +00:00
// List returns a list of all the feeds.
List(context.Context) (ListEntries, error)
// RemoveFeed removes the feed from the list.
RemoveFeed(context.Context, refs.FeedRef) error
2021-02-11 15:43:19 +00:00
// RemoveID removes the feed for the ID from the list.
RemoveID(context.Context, int64) error
2021-02-11 15:43:19 +00:00
}
2021-02-08 11:57:14 +00:00
// AliasService manages alias handle registration and lookup
type AliasService interface{}
// PinnedNoticesService allows an admin to assign Notices to specific placeholder pages.
// TODO: better name then _fixed_
// like updates, privacy policy, code of conduct
// TODO: enum these
type PinnedNoticesService interface {
// Set assigns a fixed page name to an page ID and a language to allow for multiple translated versions of the same page.
Set(name PinnedNoticeName, id int64, lang string) error
}
type NoticesService interface {
// GetByID returns the page for that ID or an error
GetByID(context.Context, int64) (Notice, error)
// Save updates the passed page or creates it if it's ID is zero
Save(context.Context, *Notice) error
// RemoveID removes the page for that ID.
RemoveID(context.Context, int64) error
}
2021-02-08 11:57:14 +00:00
// for tests we use generated mocks from these interfaces created with https://github.com/maxbrunsfeld/counterfeiter
2021-02-08 16:47:42 +00:00
//go:generate counterfeiter -o mockdb/auth.go . AuthWithSSBService
2021-02-08 11:57:14 +00:00
2021-02-08 16:47:42 +00:00
//go:generate counterfeiter -o mockdb/auth_fallback.go . AuthFallbackService
2021-02-08 11:57:14 +00:00
2021-02-11 15:43:19 +00:00
//go:generate counterfeiter -o mockdb/allow.go . AllowListService
2021-02-08 11:57:14 +00:00
//go:generate counterfeiter -o mockdb/alias.go . AliasService
//go:generate counterfeiter -o mockdb/fixed_pages.go . PinnedNoticesService
//go:generate counterfeiter -o mockdb/pages.go . NoticesService