events

package
v0.0.0-...-afa1830 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2021 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PublicMode  = "public"
	LimitedMode = "limited"
)

enum for access mode

Variables

This section is empty.

Functions

func BuildAggregate

func BuildAggregate(ctx context.Context, exec boil.ContextExecutor, e *Event) error

BuildAggregate of an event by modifying the received pointer value

func BuildMemberOrgBoxCache

func BuildMemberOrgBoxCache(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client,
	identityID string,
) (map[string]map[string][]string, error)

BuildMemberBoxIDsCache computes the full cache for the given identity: org_*:datatag_*:boxIDs considering membership return a map[orgID][datatagID]boxIDs

func BuildSubjectBoxIDsCache

func BuildSubjectBoxIDsCache(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client,
	subjectID string,
) (map[string]map[string][]string, error)

BuildSubjectBoxIDsCache computes the full cache for the given identity: org_*:datatag_*:boxIDs considering data subject return a map[orgID][datatagID]boxIDs

func ClearBox

func ClearBox(ctx context.Context, exec boil.ContextExecutor, boxID string) error

ClearBox ...

func CountActiveFilesByBoxID

func CountActiveFilesByBoxID(ctx context.Context, exec boil.ContextExecutor, boxID string) (int, error)

CountActiveFilesByBoxID ...

func CountBoxesForIdentity

func CountBoxesForIdentity(ctx context.Context, exec boil.ContextExecutor, redConn *redis.Client, identityID, ownerOrgID string, datatagIDs []string, dataSubjectID *string) (int, error)

CountBoxesForIdentity returns the number of boxes the identity is concerned by

func CountByBoxID

func CountByBoxID(ctx context.Context, exec boil.ContextExecutor, boxID string, etypes []string) (int, error)

CountByBoxID ...

func CountEventsBoxForIdentity

func CountEventsBoxForIdentity(ctx context.Context, redConn *redis.Client, identityID, boxID string) (int, error)

CountEventBoxForIdentity for the asked box and identity and return it as an int

func CreateInvitationActions

func CreateInvitationActions(
	ctx context.Context, cryptoRepo external.CryptoRepo, identityMapper *IdentityMapper,
	box Box, guests []SenderView, senderID string, actionsDataJSON null.JSON,
	nonIdentified bool, senderIsOrg bool,
) error

createInvitationActions creates crypto actions from a list of guests and from crypto action data provided by the querier. With option `nonIdentified` it only uses the “non-identified public keys” of the the guests; With option `senderIsOrg` it looks for an appropriate crypto provision if no crypto action was found that matches an identity public key of the guest.

func DelAllDigestCountForIdentity

func DelAllDigestCountForIdentity(ctx context.Context, redConn *redis.Client, identityID string) error

DelAllDigestCountForIdentity identityID

func DelCounts

func DelCounts(ctx context.Context, redConn *redis.Client, identityID, boxID string) error

DelCounts for couple <identityID, boxID>

func DelDigestCount

func DelDigestCount(ctx context.Context, redConn *redis.Client, identityID, boxID string) error

DelDigestCount for couple <identityID, boxID>

func DeleteAllForBox

func DeleteAllForBox(
	ctx context.Context,
	exec boil.ContextExecutor,
	boxID string,
) error

DeleteAllForBox ...

func DeleteOrphanFiles

func DeleteOrphanFiles(ctx context.Context, exec boil.ContextExecutor, filesRepo files.FileStorageRepo, fileIDs []string) error

DeleteOrphanFiles ...

func GetAdminID

func GetAdminID(ctx context.Context, exec boil.ContextExecutor, boxID string) (string, error)

GetAdminID ...

func GetAllDigestCountKeys

func GetAllDigestCountKeys(ctx context.Context, redConn *redis.Client) ([]string, error)

GetAllDigestCountKeys ...

func GetBoxCountForMember

func GetBoxCountForMember(ctx context.Context, redConn *redis.Client, senderID, boxID string) int

func GetCreateInfo

func GetCreateInfo(
	ctx context.Context,
	exec boil.ContextExecutor,
	boxID string,
) (info createInfo, err error)

GetCreateInfo retrieves the create event of the box and marshals its content into a CreationContent structure aside its creator id

func GetEventCountsForIdentity

func GetEventCountsForIdentity(ctx context.Context, redConn *redis.Client, identityID string) (map[string]int, error)

GetEventCountsForIdentity and return a map with box IDs and their corresponding new events count for the user

func HasAccess

func HasAccess(ctx context.Context,
	exec boil.ContextExecutor, identities *IdentityMapper,
	boxID, identityID string,
	identifierOnly bool,
) error

hasAccess returns no error if the received identityID match an active access rule identifierOnly set to true restricts the matching of access rules to only identifier restriction type.

func HasAccessOrHasSavedFile

func HasAccessOrHasSavedFile(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client,
	identityID string, fileID string,
) (bool, error)

HasAccessOrHasSavedFile ...

func HasAccessToFile

func HasAccessToFile(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client,
	identityID string, fileID string,
) (bool, error)

HasAccessToFile if the file is in a box the identity have access to

func IncrBoxCounts

func IncrBoxCounts(ctx context.Context, redConn *redis.Client, identityIDs []string, boxID string) error

IncrBoxCounts for a given box for all received identityIDs

func IncrDigestCount

func IncrDigestCount(ctx context.Context, redConn *redis.Client, identityIDs []string, boxID string) error

IncrDigestCount for a given box for all received identityIDs

func IsAdmin

func IsAdmin(ctx context.Context, exec boil.ContextExecutor, boxID, senderID string) (bool, error)

IsAdmin ...

func IsDeleted

func IsDeleted(event *sqlboiler.Event) (bool, error)

IsDeleted ...

func IsFileOrphan

func IsFileOrphan(ctx context.Context, exec boil.ContextExecutor, fileID string) (bool, error)

IsFileOrphan ...

func ListBoxMemberIDs

func ListBoxMemberIDs(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client,
	boxID string,
) ([]string, error)

ListBoxMemberIDs and return their identities ID

func ListCreatedBoxIDs

func ListCreatedBoxIDs(ctx context.Context, exec boil.ContextExecutor, identityID string) ([]string, error)

ListCreatedBoxIDs returns a list of box ids that have been created by the received identity id

func ListDatatagIDsForMember

func ListDatatagIDsForMember(ctx context.Context, exec boil.ContextExecutor, redConn *redis.Client, identityID, orgID string) ([]string, error)

ListDatatagIDsForMember by getting boxes corresponding to organization and extracting all the corresponding datatag

func ListFilesID

func ListFilesID(ctx context.Context, exec boil.ContextExecutor, boxID string) ([]string, error)

ListFilesID ...

func MapCreationContentByBoxID

func MapCreationContentByBoxID(
	ctx context.Context,
	exec boil.ContextExecutor,
	boxIDs []string,
) (map[string]CreationContent, error)

MapCreationContentByBoxID retrieves the create event of the boxes and marshal its content it returns a map[boxID]CreationContent

func MustBeAbleToJoin

func MustBeAbleToJoin(
	ctx context.Context,
	exec boil.ContextExecutor, identities *IdentityMapper,
	boxID, identityID string,
) error

CanJoin returns no error if the received identityID can joined the box related to the received box id

func MustBeAdmin

func MustBeAdmin(ctx context.Context, exec boil.ContextExecutor, boxID, senderID string) error

MustBeAdmin ...

func MustBeLegitimate

func MustBeLegitimate(
	ctx context.Context,
	exec boil.ContextExecutor, identities *IdentityMapper,
	boxID, identityID string,
) error

IsLegimate returns no error if the received identityID is legitimate to be in the box

func MustBeMember

func MustBeMember(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client,
	boxID, identityID string,
) error

MustBeMember ...

func MustBoxExists

func MustBoxExists(ctx context.Context, exec boil.ContextExecutor, boxID string) error

MustBoxExists ...

func SetCreateEvent

func SetCreateEvent(e *Event) func(*computer)

SetCreateEvent which avoid its later retrieval to compoute the box

func SetLastEvent

func SetLastEvent(e *Event) func(*BoxView)

SetLastEvent which avoid its retrieval in case of nil

func SetSavedStatus

func SetSavedStatus(ctx context.Context, exec boil.ContextExecutor, identityID string, fileEvents []*Event) error

SetSavedStatus on file events contents for identity identityID the function alters events in fileEvents and only returns an error

func UpdateBoxSetting

func UpdateBoxSetting(ctx context.Context, exec boil.ContextExecutor, boxSetting BoxSetting) error

UpdateBoxSetting ...

Types

type AccessModeContent

type AccessModeContent struct {
	Value string `json:"value"`
}

func (*AccessModeContent) Unmarshal

func (c *AccessModeContent) Unmarshal(content types.JSON) error

Unmarshal ...

func (AccessModeContent) Validate

func (c AccessModeContent) Validate() error

Validate ...

type Box

type Box struct {
	ID          string      `json:"id"`
	CreatedAt   time.Time   `json:"server_created_at"`
	OwnerOrgID  string      `json:"owner_org_id"`
	DatatagID   null.String `json:"datatag_id"`
	DataSubject *string     `json:"data_subject,omitempty"`
	PublicKey   string      `json:"public_key"`
	Title       string      `json:"title"`
	AccessMode  string      `json:"access_mode"`
	// contains filtered or unexported fields
}

Box is a volatile object built based on events linked to its ID

func GetSimpleBox

func GetSimpleBox(ctx context.Context, exec boil.ContextExecutor, identityMapper *IdentityMapper, boxID string) (Box, error)

GetSimpleBox by computing the box with simple mode activated

func ListMemberSimpleBoxes

func ListMemberSimpleBoxes(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client, identities *IdentityMapper,
	memberID, ownerOrgID string, datatagIDs []string, dataSubjectID *string,
	limit, offset int,
) ([]*Box, error)

type BoxSetting

type BoxSetting struct {
	IdentityID string `json:"identity_id"`
	BoxID      string `json:"box_id"`
	Muted      bool   `json:"muted"`
}

BoxSetting ...

func GetBoxSettings

func GetBoxSettings(ctx context.Context, exec boil.ContextExecutor, identityID, boxID string) (*BoxSetting, error)

GetBoxSettings

func GetDefaultBoxSetting

func GetDefaultBoxSetting(identityID, boxID string) *BoxSetting

GetDefaultBoxSetting return a default box settings value it is used while the identity has not configured one already for a box

func ListBoxSettings

func ListBoxSettings(ctx context.Context, exec boil.ContextExecutor, filters BoxSettingFilters) ([]*BoxSetting, error)

ListBoxSettings...

type BoxSettingFilters

type BoxSettingFilters struct {
	BoxIDs     []string
	IdentityID string
}

BoxSettingFilters ...

type BoxView

type BoxView struct {
	Box

	// aggregated data
	Subject     *SenderView `json:"subject"`
	Creator     SenderView  `json:"creator"`
	LastEvent   View        `json:"last_event"`
	EventsCount null.Int    `json:"events_count,omitempty"`
	BoxSettings *BoxSetting `json:"settings,omitempty"`
	// contains filtered or unexported fields
}

func CreateContactBox

func CreateContactBox(ctx context.Context, exec boil.ContextExecutor, ssoExec boil.ContextExecutor, redConn *redis.Client, identityMapper *IdentityMapper, _ files.FileStorageRepo, cryptoRepo external.CryptoRepo, contact ContactBox) (*BoxView, error)

CreateContactBox creates the box, sets the access mode to public and invite the contacted user

func GetBoxView

func GetBoxView(ctx context.Context, exec boil.ContextExecutor, identityMapper *IdentityMapper, redConn *redis.Client, boxID string, options ...func(*BoxView)) (BoxView, error)

GetBoxView ...

func ListMemberBoxViews

func ListMemberBoxViews(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client, identities *IdentityMapper,
	memberID, ownerOrgID string, datatagIDs []string,
	limit, offset int,
) ([]*BoxView, error)

ListMemberBoxViews returns the list of the boxes considering membership,

ordered from the latest activity to the oldest

taking into account the filters and pagination

type ContactBox

type ContactBox struct {
	// user info
	ContactedIdentityID string
	IdentityID          string

	// box info
	OwnerOrgID string
	Title      string
	PublicKey  string

	// contact info
	InvitationShareHash         string
	Share                       string
	EncryptedInvitationKeyShare string
	InvitationDataJSON          types.JSON
}

ContactBox model

type CreationContent

type CreationContent struct {
	OwnerOrgID        string  `json:"owner_org_id"`
	DatatagID         *string `json:"datatag_id,omitempty"`
	SubjectIdentityID *string `json:"subject_identity_id,omitempty"`
	PublicKey         string  `json:"public_key"`
	Title             string  `json:"title"`
}

CreationContent ...

func (*CreationContent) Unmarshal

func (c *CreationContent) Unmarshal(json types.JSON) error

Unmarshal ...

func (CreationContent) Validate

func (c CreationContent) Validate() error

Validate ...

type DeletedContent

type DeletedContent struct {
	Deleted struct {
		AtTime time.Time `json:"at_time"`
		// Stored but not in the view
		ByIdentityID string `json:"by_identity_id,omitempty"`
		// Set during view generation
		ByIdentity *SenderView `json:"by_identity,omitempty"`
	} `json:"deleted"`
}

DeletedContent ...

type EmptyContent

type EmptyContent struct{}

EmptyContent ...

func (*EmptyContent) Unmarshal

func (c *EmptyContent) Unmarshal(json types.JSON) error

Unmarshal ...

func (EmptyContent) Validate

func (c EmptyContent) Validate() error

Validate ...

type Event

type Event struct {
	ID          string
	CreatedAt   time.Time
	BoxID       string
	SenderID    string
	Type        string
	ReferrerID  null.String
	JSONContent types.JSON

	Content             interface{}
	MetadataForHandlers MetadataForUsedSpaceHandler
	// contains filtered or unexported fields
}

Event ...

func CreateCreateEvent

func CreateCreateEvent(
	ctx context.Context,
	exec boil.ContextExecutor, redConn *redis.Client, identities *IdentityMapper,
	title, publicKey, ownerOrgID string,
	datatagID, subjectIdentityID *string,
	senderID string,
) (Event, error)

CreateCreateEvent ...

func FindActiveAccesses

func FindActiveAccesses(ctx context.Context, exec boil.ContextExecutor, boxID string) ([]Event, error)

FindActiveAccesses ...

func GetLast

func GetLast(ctx context.Context, exec boil.ContextExecutor, boxID string) (Event, error)

GetLast ...

func GetMsgFile

func GetMsgFile(
	ctx context.Context,
	exec boil.ContextExecutor,
	boxID, fileID string,
) (Event, error)

GetMsgFile ...

func KickDeprecatedMembers

func KickDeprecatedMembers(
	ctx context.Context,
	exec boil.ContextExecutor, identities *IdentityMapper,
	boxID string, kickerID string,
) ([]Event, error)

KickDeprecatedMembers by checking if the member is still in the identifier accesses list.

func ListByBoxID

func ListByBoxID(ctx context.Context, exec boil.ContextExecutor, boxID string, etypes []string, limit, offset *int) ([]Event, error)

ListByBoxID ...

func ListByTypeAndBoxIDAndSenderID

func ListByTypeAndBoxIDAndSenderID(ctx context.Context, exec boil.ContextExecutor, eventType, boxID, senderID string) ([]Event, error)

ListByTypeAndBoxIDAndSenderID ...

func ListFilesForMembersByBoxID

func ListFilesForMembersByBoxID(ctx context.Context, exec boil.ContextExecutor, boxID string, limit, offset *int) ([]Event, error)

ListFilesForMembersByBoxID ...

func New

func New(eType string, jsonContent types.JSON, boxID, senderID string, referrerID *string) (Event, error)

New ...

func NewMsgFile

func NewMsgFile(
	ctx context.Context,
	boxID string, senderID string,
	encContent string, pubKey string,
) (e Event, fileID string, err error)

NewMsgFile ...

func (Event) Format

func (e Event) Format(ctx context.Context, identityMapper *IdentityMapper) (View, error)

Format event into its JSON view.

func (*Event) ToSQLBoiler

func (e *Event) ToSQLBoiler() *sqlboiler.Event

ToSQLBoiler ...

type EventHandler

type EventHandler struct {
	Do    doHandler
	After []afterHandler
}

EventHandler ...

func Handler

func Handler(eType string) EventHandler

Handler ...

type IdentityMapper

type IdentityMapper struct {
	sync.Mutex
	// contains filtered or unexported fields
}

IdentityMapper ...

func NewIdentityMapper

func NewIdentityMapper(querier external.IdentityRepo) *IdentityMapper

NewIdentityMapper ...

func (*IdentityMapper) CreateNotifs

func (mapper *IdentityMapper) CreateNotifs(ctx context.Context, identityIDs []string, nType string, details null.JSON)

CreateNotifs for identity

func (*IdentityMapper) Get

func (mapper *IdentityMapper) Get(ctx context.Context, identityID string) (SenderView, error)

Get the identity considering the ID

func (*IdentityMapper) GetByIdentifierValue

func (mapper *IdentityMapper) GetByIdentifierValue(ctx context.Context, identifierValue string) (SenderView, error)

GetByIdentifierValue the identity considering the IdentifierValue

func (*IdentityMapper) List

func (mapper *IdentityMapper) List(ctx context.Context, identityIDs []string) ([]SenderView, error)

List the identities considering IDs

type MemberKickContent

type MemberKickContent struct {
	// Stored but not return in json view
	KickerID string `json:"kicker_id,omitempty"`
	// in json
	Kicker *SenderView `json:"kicker,omitempty"`
}

MemberKickContent ...

func (*MemberKickContent) Unmarshal

func (c *MemberKickContent) Unmarshal(content types.JSON) error

Unmarshal ...

func (MemberKickContent) Validate

func (c MemberKickContent) Validate() error

Validate ...

type Message

type Message struct {
	Encrypted       string
	PublicKey       string
	LastEditedAt    time.Time
	DeletedAt       time.Time
	FileID          null.String
	BoxID           string
	Type            string
	InitialSenderID string
	LastSenderID    string
	OldSize         int
	NewSize         int
}

Message ...

type Metadata

type Metadata interface{}

Metadata ...

type MetadataForUsedSpaceHandler

type MetadataForUsedSpaceHandler struct {
	OldEventSize int64
	NewEventSize int64
}

MetadataForUsedSpaceHandler ...

type MsgEditContent

type MsgEditContent struct {
	NewEncrypted string `json:"new_encrypted"`
	NewPublicKey string `json:"new_public_key"`
}

MsgEditContent is exported because application layer need to access the "EventID" field

func (*MsgEditContent) Unmarshal

func (c *MsgEditContent) Unmarshal(content types.JSON) error

Unmarshal a msg.edit content JSON into its typed structure

func (MsgEditContent) Validate

func (c MsgEditContent) Validate() error

Validate a msg.edit content structure

type MsgFileContent

type MsgFileContent struct {
	Encrypted       string `json:"encrypted"`
	PublicKey       string `json:"public_key"`
	EncryptedFileID string `json:"encrypted_file_id"`

	// metadata
	IsSaved *bool `json:"is_saved,omitempty"`
}

MsgFileContent ...

func (*MsgFileContent) Unmarshal

func (c *MsgFileContent) Unmarshal(json types.JSON) error

Unmarshal ...

func (MsgFileContent) Validate

func (c MsgFileContent) Validate() error

Validate ...

type MsgTextContent

type MsgTextContent struct {
	Encrypted    string    `json:"encrypted"`
	PublicKey    string    `json:"public_key"`
	LastEditedAt null.Time `json:"last_edited_at"`
}

MsgTextContent ...

func (*MsgTextContent) Unmarshal

func (c *MsgTextContent) Unmarshal(content types.JSON) error

Unmarshal ...

func (MsgTextContent) Validate

func (c MsgTextContent) Validate() error

Validate ...

type SenderView

type SenderView struct {
	ID              string      `json:"id"`
	DisplayName     string      `json:"display_name"`
	AvatarURL       null.String `json:"avatar_url"`
	IdentifierValue string      `json:"identifier_value"`
	IdentifierKind  string      `json:"identifier_kind"`
	// contains filtered or unexported fields
}

SenderView is how an event sender (or box creator) is represented in JSON reponses

func SenderViewFrom

func SenderViewFrom(identity identity.Identity) SenderView

type View

type View struct {
	Type       string      `json:"type"`
	Content    *types.JSON `json:"content"`
	BoxID      string      `json:"box_id"`
	ID         string      `json:"id"`
	CreatedAt  time.Time   `json:"server_event_created_at"`
	ReferrerID null.String `json:"referrer_id"`
	Sender     SenderView  `json:"sender"`
}

View represent an event as it is represented in JSON responses

func (*View) ToJSON

func (v *View) ToJSON() ([]byte, error)

ToJSON ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL