fb

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateCommand

type CreateCommand struct {
	CollectionName string
	Data           interface{}
}

CreateCommand represent payload required to perform a create operation in the database

type DeleteCommand

type DeleteCommand struct {
	CollectionName string
	ID             string
}

DeleteCommand represent payload required to perform a delete operation in the database

type FirebaseClientExtension

type FirebaseClientExtension interface {
	GetUserByPhoneNumber(ctx context.Context, phone string) (*auth.UserRecord, error)
	CreateUser(ctx context.Context, user *auth.UserToCreate) (*auth.UserRecord, error)
	DeleteUser(ctx context.Context, uid string) error
}

FirebaseClientExtension represents the methods we need from firebase `auth.Client`

func NewFirebaseClientExtensionImpl

func NewFirebaseClientExtensionImpl() FirebaseClientExtension

NewFirebaseClientExtensionImpl initializes a new FirebaseClient extension

type FirebaseClientExtensionImpl

type FirebaseClientExtensionImpl struct{}

FirebaseClientExtensionImpl ...

func (*FirebaseClientExtensionImpl) CreateUser

CreateUser ...

func (*FirebaseClientExtensionImpl) DeleteUser

func (f *FirebaseClientExtensionImpl) DeleteUser(ctx context.Context, uid string) error

DeleteUser ...

func (*FirebaseClientExtensionImpl) GetUserByPhoneNumber

func (f *FirebaseClientExtensionImpl) GetUserByPhoneNumber(ctx context.Context, phone string) (*auth.UserRecord, error)

GetUserByPhoneNumber ...

type FirestoreClientExtension

type FirestoreClientExtension interface {
	GetAll(ctx context.Context, query *GetAllQuery) ([]*firestore.DocumentSnapshot, error)
	Create(ctx context.Context, command *CreateCommand) (*firestore.DocumentRef, error)
	Update(ctx context.Context, command *UpdateCommand) error
	Delete(ctx context.Context, command *DeleteCommand) error
	Get(ctx context.Context, query *GetSingleQuery) (*firestore.DocumentSnapshot, error)
}

FirestoreClientExtension represents the methods we need from firebase `firestore.Client`

type FirestoreClientExtensionImpl

type FirestoreClientExtensionImpl struct {
	// contains filtered or unexported fields
}

FirestoreClientExtensionImpl ...

func NewFirestoreClientExtension

func NewFirestoreClientExtension(fc *firestore.Client) *FirestoreClientExtensionImpl

NewFirestoreClientExtension initializes a new FirestoreClient extension

func (*FirestoreClientExtensionImpl) Create

Create persists data to a firestore collection

func (*FirestoreClientExtensionImpl) Delete

Delete deletes data to a firestore collection

func (*FirestoreClientExtensionImpl) Get

Get retrieves data to a firestore collection

func (*FirestoreClientExtensionImpl) GetAll

GetAll retrieve a value from the store

func (*FirestoreClientExtensionImpl) Update

Update updates data to a firestore collection

type GetAllQuery

type GetAllQuery struct {
	CollectionName string
	FieldName      string
	Value          interface{}
	Operator       string
}

GetAllQuery represent payload required to perform a request in the database

type GetSingleQuery

type GetSingleQuery struct {
	CollectionName string
	Value          string
}

GetSingleQuery represent payload required to get a single item from the database

type Repository

type Repository struct {
	FirestoreClient FirestoreClientExtension
	FirebaseClient  FirebaseClientExtension
}

Repository accesses and updates an item that is stored on Firebase

func NewFirebaseRepository

func NewFirebaseRepository(
	firestoreClient FirestoreClientExtension,
	firebaseClient FirebaseClientExtension,
) *Repository

NewFirebaseRepository initializes a Firebase repository

func (*Repository) AddUserAsExperimentParticipant

func (fr *Repository) AddUserAsExperimentParticipant(
	ctx context.Context,
	profile *profileutils.UserProfile,
) (bool, error)

AddUserAsExperimentParticipant adds the provided user profile as an experiment participant if does not already exist. this method is idempotent.

func (*Repository) CheckIfAdmin

func (fr *Repository) CheckIfAdmin(profile *profileutils.UserProfile) bool

CheckIfAdmin checks if a user has admin permissions

func (*Repository) CheckIfEmailExists

func (fr *Repository) CheckIfEmailExists(ctx context.Context, email string) (bool, error)

CheckIfEmailExists checks in both PRIMARY EMAIL and SECONDARY EMAIL for the existence of the argument email

func (*Repository) CheckIfExperimentParticipant

func (fr *Repository) CheckIfExperimentParticipant(
	ctx context.Context,
	profileID string,
) (bool, error)

CheckIfExperimentParticipant check if a user has subscribed to be an experiment participant

func (*Repository) CheckIfPhoneNumberExists

func (fr *Repository) CheckIfPhoneNumberExists(
	ctx context.Context,
	phoneNumber string,
) (bool, error)

CheckIfPhoneNumberExists checks both PRIMARY PHONE NUMBERs and SECONDARY PHONE NUMBERs for the existence of the argument phoneNumber.

func (*Repository) CheckIfRoleNameExists

func (fr *Repository) CheckIfRoleNameExists(ctx context.Context, name string) (bool, error)

CheckIfRoleNameExists checks if a role with a similar name exists Ensures unique name for each role during creation

func (*Repository) CheckIfUserHasPermission added in v0.0.2

func (fr *Repository) CheckIfUserHasPermission(
	ctx context.Context,
	UID string,
	requiredPermission profileutils.Permission,
) (bool, error)

CheckIfUserHasPermission checks if a user has the required permission

func (*Repository) CheckIfUsernameExists

func (fr *Repository) CheckIfUsernameExists(ctx context.Context, userName string) (bool, error)

CheckIfUsernameExists checks if the provided username exists. If true, it means its has already been associated with another user

func (*Repository) CreateDetailedUserProfile

func (fr *Repository) CreateDetailedUserProfile(
	ctx context.Context,
	phoneNumber string,
	profile profileutils.UserProfile,
) (*profileutils.UserProfile, error)

CreateDetailedUserProfile creates a new user profile that is pre-filled using the provided phone number

func (*Repository) CreateRole

func (fr *Repository) CreateRole(
	ctx context.Context,
	profileID string,
	input dto.RoleInput,
) (*profileutils.Role, error)

CreateRole creates a new role and persists it to the database

func (*Repository) CreateUserProfile

func (fr *Repository) CreateUserProfile(
	ctx context.Context,
	phoneNumber, uid string,
) (*profileutils.UserProfile, error)

CreateUserProfile creates a user profile of using the provided phone number and uid

func (*Repository) DeleteRole added in v0.0.2

func (fr *Repository) DeleteRole(
	ctx context.Context,
	roleID string,
) (bool, error)

DeleteRole removes a role permanently from the database

func (Repository) ExchangeRefreshTokenForIDToken

func (fr Repository) ExchangeRefreshTokenForIDToken(
	ctx context.Context,
	refreshToken string,
) (*profileutils.AuthCredentialResponse, error)

ExchangeRefreshTokenForIDToken takes a custom Firebase refresh token and tries to fetch an ID token and returns auth credentials if successful Otherwise, an error is returned

func (*Repository) FetchAdminUsers

func (fr *Repository) FetchAdminUsers(ctx context.Context) ([]*profileutils.UserProfile, error)

FetchAdminUsers fetches all admins

func (*Repository) GenerateAuthCredentials

func (fr *Repository) GenerateAuthCredentials(
	ctx context.Context,
	phone string,
	profile *profileutils.UserProfile,
) (*profileutils.AuthCredentialResponse, error)

GenerateAuthCredentials gets a Firebase user by phone and creates their tokens

func (*Repository) GenerateAuthCredentialsForAnonymousUser

func (fr *Repository) GenerateAuthCredentialsForAnonymousUser(
	ctx context.Context,
) (*profileutils.AuthCredentialResponse, error)

GenerateAuthCredentialsForAnonymousUser generates auth credentials for the anonymous user. This method is here since we don't want to delegate sign-in of anonymous users to the frontend. This is an effort the over reliance on firebase and lettin us handle all the heavy lifting

func (*Repository) GetAllRoles added in v0.0.2

func (fr *Repository) GetAllRoles(ctx context.Context) (*[]profileutils.Role, error)

GetAllRoles returns a list of all created roles

func (Repository) GetCommunicationsSettingsCollectionName

func (fr Repository) GetCommunicationsSettingsCollectionName() string

GetCommunicationsSettingsCollectionName ...

func (*Repository) GetExperimentParticipantCollectionName

func (fr *Repository) GetExperimentParticipantCollectionName() string

GetExperimentParticipantCollectionName fetches the collection where experiment participant will be saved

func (*Repository) GetOrCreatePhoneNumberUser

func (fr *Repository) GetOrCreatePhoneNumberUser(
	ctx context.Context,
	phone string,
) (*dto.CreatedUserResponse, error)

GetOrCreatePhoneNumberUser retrieves or creates an phone number user account in Firebase Authentication

func (*Repository) GetPINByProfileID

func (fr *Repository) GetPINByProfileID(
	ctx context.Context,
	profileID string,
) (*domain.PIN, error)

GetPINByProfileID gets a user's PIN by their profile ID

func (Repository) GetPINsCollectionName

func (fr Repository) GetPINsCollectionName() string

GetPINsCollectionName returns a well suffixed PINs collection name

func (Repository) GetProfileNudgesCollectionName

func (fr Repository) GetProfileNudgesCollectionName() string

GetProfileNudgesCollectionName return the storage location of profile nudges

func (*Repository) GetRoleByID

func (fr *Repository) GetRoleByID(ctx context.Context, roleID string) (*profileutils.Role, error)

GetRoleByID gets role with matching id

func (*Repository) GetRoleByName added in v0.0.2

func (fr *Repository) GetRoleByName(ctx context.Context, roleName string) (*profileutils.Role, error)

GetRoleByName retrieves a role using it's name

func (*Repository) GetRolesByIDs

func (fr *Repository) GetRolesByIDs(
	ctx context.Context,
	roleIDs []string,
) (*[]profileutils.Role, error)

GetRolesByIDs gets all roles matching provided roleIDs if specified otherwise all roles

func (Repository) GetRolesCollectionName

func (fr Repository) GetRolesCollectionName() string

GetRolesCollectionName ...

func (Repository) GetRolesRevocationCollectionName added in v0.0.2

func (fr Repository) GetRolesRevocationCollectionName() string

GetRolesRevocationCollectionName ...

func (Repository) GetSurveyCollectionName

func (fr Repository) GetSurveyCollectionName() string

GetSurveyCollectionName returns a well suffixed PINs collection name

func (*Repository) GetUserCommunicationsSettings

func (fr *Repository) GetUserCommunicationsSettings(
	ctx context.Context,
	profileID string,
) (*profileutils.UserCommunicationsSetting, error)

GetUserCommunicationsSettings fetches the communication settings of a specific user.

func (*Repository) GetUserProfileByID

func (fr *Repository) GetUserProfileByID(
	ctx context.Context,
	id string,
	suspended bool,
) (*profileutils.UserProfile, error)

GetUserProfileByID retrieves a user profile by ID

func (*Repository) GetUserProfileByPhoneNumber

func (fr *Repository) GetUserProfileByPhoneNumber(
	ctx context.Context,
	phoneNumber string,
	suspended bool,
) (*profileutils.UserProfile, error)

GetUserProfileByPhoneNumber fetches a user profile by phone number. This method traverses both PRIMARY PHONE numbers and SECONDARY PHONE numbers.

func (*Repository) GetUserProfileByPhoneOrEmail added in v0.0.2

func (fr *Repository) GetUserProfileByPhoneOrEmail(ctx context.Context, payload *dto.RetrieveUserProfileInput) (*profileutils.UserProfile, error)

GetUserProfileByPhoneOrEmail retrieves user profile by email adddress

func (*Repository) GetUserProfileByPrimaryPhoneNumber

func (fr *Repository) GetUserProfileByPrimaryPhoneNumber(
	ctx context.Context,
	phoneNumber string,
	suspended bool,
) (*profileutils.UserProfile, error)

GetUserProfileByPrimaryPhoneNumber fetches a user profile by primary phone number

func (*Repository) GetUserProfileByUID

func (fr *Repository) GetUserProfileByUID(
	ctx context.Context,
	uid string,
	suspended bool,
) (*profileutils.UserProfile, error)

GetUserProfileByUID retrieves the user profile by UID

func (Repository) GetUserProfileCollectionName

func (fr Repository) GetUserProfileCollectionName() string

GetUserProfileCollectionName ...

func (*Repository) GetUserProfilesByRoleID added in v0.0.2

func (fr *Repository) GetUserProfilesByRoleID(ctx context.Context, roleID string) ([]*profileutils.UserProfile, error)

GetUserProfilesByRoleID returns a list of user profiles with the role ID i.e users assigned a particular role

func (*Repository) HardResetSecondaryEmailAddress

func (fr *Repository) HardResetSecondaryEmailAddress(
	ctx context.Context,
	profile *profileutils.UserProfile,
	newSecondaryEmails []string,
) error

HardResetSecondaryEmailAddress does a hard reset of user secondary email addresses. This should be called when retiring specific secondary email addresses and passing in the new secondary email address as an argument.

func (*Repository) HardResetSecondaryPhoneNumbers

func (fr *Repository) HardResetSecondaryPhoneNumbers(
	ctx context.Context,
	profile *profileutils.UserProfile,
	newSecondaryPhoneNumbers []string,
) error

HardResetSecondaryPhoneNumbers does a hard reset of user secondary phone numbers. This should be called when retiring specific secondary phone number and passing in the new secondary phone numbers as an argument.

func (*Repository) ListUserProfiles

func (fr *Repository) ListUserProfiles(
	ctx context.Context,
	role profileutils.RoleType,
) ([]*profileutils.UserProfile, error)

ListUserProfiles fetches all users with the specified role from the database

func (*Repository) PurgeUserByPhoneNumber

func (fr *Repository) PurgeUserByPhoneNumber(ctx context.Context, phone string) error

PurgeUserByPhoneNumber removes the record of a user given a phone number.

func (*Repository) RecordPostVisitSurvey

func (fr *Repository) RecordPostVisitSurvey(
	ctx context.Context,
	input dto.PostVisitSurveyInput,
	UID string,
) error

RecordPostVisitSurvey records an end of visit survey

func (*Repository) RemoveUserAsExperimentParticipant

func (fr *Repository) RemoveUserAsExperimentParticipant(
	ctx context.Context,
	profile *profileutils.UserProfile,
) (bool, error)

RemoveUserAsExperimentParticipant removes the provide user profile as an experiment participant. This methold does not check for existence before deletion since non-existence is relatively equivalent to a removal

func (*Repository) SavePIN

func (fr *Repository) SavePIN(ctx context.Context, pin *domain.PIN) (bool, error)

SavePIN persist the data of the newly created PIN to a datastore

func (*Repository) SaveRoleRevocation added in v0.0.2

func (fr *Repository) SaveRoleRevocation(ctx context.Context, userID string, revocation dto.RoleRevocationInput) error

SaveRoleRevocation records a log for a role revocation

userId is the ID of the user removing a role from a user

func (*Repository) SetUserCommunicationsSettings

func (fr *Repository) SetUserCommunicationsSettings(
	ctx context.Context,
	profileID string,
	allowWhatsApp *bool,
	allowTextSms *bool,
	allowPush *bool,
	allowEmail *bool,
) (*profileutils.UserCommunicationsSetting, error)

SetUserCommunicationsSettings sets communication settings for a specific user

func (*Repository) StageProfileNudge

func (fr *Repository) StageProfileNudge(
	ctx context.Context,
	nudge *feedlib.Nudge,
) error

StageProfileNudge stages nudges published from this service.

func (*Repository) UpdateAddresses

func (fr *Repository) UpdateAddresses(
	ctx context.Context,
	id string,
	address profileutils.Address,
	addressType enumutils.AddressType,
) error

UpdateAddresses persists a user's home or work address information to the database

func (*Repository) UpdateBioData

func (fr *Repository) UpdateBioData(
	ctx context.Context,
	id string,
	data profileutils.BioData,
) error

UpdateBioData updates the biodate of the profile that matches the id

func (*Repository) UpdateFavNavActions

func (fr *Repository) UpdateFavNavActions(
	ctx context.Context,
	id string,
	favActions []string,
) error

UpdateFavNavActions update the permissions of the user profile

func (*Repository) UpdatePIN

func (fr *Repository) UpdatePIN(ctx context.Context, id string, pin *domain.PIN) (bool, error)

UpdatePIN persist the data of the updated PIN to a datastore

func (*Repository) UpdatePermissions

func (fr *Repository) UpdatePermissions(
	ctx context.Context,
	id string,
	perms []profileutils.PermissionType,
) error

UpdatePermissions update the permissions of the user profile

func (*Repository) UpdatePhotoUploadID

func (fr *Repository) UpdatePhotoUploadID(ctx context.Context, id string, uploadID string) error

UpdatePhotoUploadID updates the photoUploadID attribute of the profile that matches the id

func (*Repository) UpdatePrimaryEmailAddress

func (fr *Repository) UpdatePrimaryEmailAddress(
	ctx context.Context,
	id string,
	emailAddress string,
) error

UpdatePrimaryEmailAddress the primary email addresses of the profile that matches the id this method should be called after asserting the emailAddress is unique and not associated with another userProfile

func (*Repository) UpdatePrimaryPhoneNumber

func (fr *Repository) UpdatePrimaryPhoneNumber(
	ctx context.Context,
	id string,
	phoneNumber string,
) error

UpdatePrimaryPhoneNumber append a new primary phone number to the user profile this method should be called after asserting the phone number is unique and not associated with another userProfile

func (*Repository) UpdatePushTokens

func (fr *Repository) UpdatePushTokens(ctx context.Context, id string, pushTokens []string) error

UpdatePushTokens updates the pushTokens attribute of the profile that matches the id. This function does a hard reset instead of prior matching

func (*Repository) UpdateRole

func (fr *Repository) UpdateRole(ctx context.Context, id string, role profileutils.RoleType) error

UpdateRole update the permissions of the user profile

func (*Repository) UpdateRoleDetails

func (fr *Repository) UpdateRoleDetails(
	ctx context.Context,
	profileID string,
	role profileutils.Role,
) (*profileutils.Role, error)

UpdateRoleDetails updates the details of a role

func (*Repository) UpdateSecondaryEmailAddresses

func (fr *Repository) UpdateSecondaryEmailAddresses(
	ctx context.Context,
	id string,
	uniqueEmailAddresses []string,
) error

UpdateSecondaryEmailAddresses the secondary email addresses of the profile that matches the id this method should be called after asserting the emailAddresses as unique and not associated with another userProfile

func (*Repository) UpdateSecondaryPhoneNumbers

func (fr *Repository) UpdateSecondaryPhoneNumbers(
	ctx context.Context,
	id string,
	phoneNumbers []string,
) error

UpdateSecondaryPhoneNumbers updates the secondary phone numbers of the profile that matches the id this method should be called after asserting the phone numbers are unique and not associated with another userProfile

func (*Repository) UpdateSuspended

func (fr *Repository) UpdateSuspended(ctx context.Context, id string, status bool) error

UpdateSuspended updates the suspend attribute of the profile that matches the id

func (*Repository) UpdateUserName

func (fr *Repository) UpdateUserName(ctx context.Context, id string, userName string) error

UpdateUserName updates the username of a profile that matches the id this method should be called after asserting the username is unique and not associated with another userProfile

func (*Repository) UpdateUserProfileEmail added in v0.0.2

func (fr *Repository) UpdateUserProfileEmail(
	ctx context.Context,
	phone string,
	email string,
) error

UpdateUserProfileEmail updates user profile's email

func (Repository) UpdateUserRoleIDs added in v0.0.2

func (fr Repository) UpdateUserRoleIDs(ctx context.Context, id string, roleIDs []string) error

UpdateUserRoleIDs updates the roles for a user

func (*Repository) UpdateVerifiedIdentifiers

func (fr *Repository) UpdateVerifiedIdentifiers(
	ctx context.Context,
	id string,
	identifiers []profileutils.VerifiedIdentifier,
) error

UpdateVerifiedIdentifiers adds a UID to a user profile during login if it does not exist

func (*Repository) UpdateVerifiedUIDS

func (fr *Repository) UpdateVerifiedUIDS(ctx context.Context, id string, uids []string) error

UpdateVerifiedUIDS adds a UID to a user profile during login if it does not exist

type UpdateCommand

type UpdateCommand struct {
	CollectionName string
	Data           interface{}
	ID             string
}

UpdateCommand represent payload required to perform an update operaion in the database

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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