profileutils

package module
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: MIT Imports: 9 Imported by: 38

README

Build Status Maintained Linting and Tests Coverage Status

Profile Utils

profileutils is a utils package that contains common utilities used by other services that interact with profile

Installing it

profileutils is compatible with modern Go releases in module mode, with Go installed:

go get -u github.com/savannahghi/profileutils

will resolve and add the package to the current development module, along with its dependencies.

Alternatively the same can be achieved if you use import in a package:

import "github.com/savannahghi/profileutils"

and run go get without parameters.

The package name is profileutils

Developing

The default branch library is main

We try to follow semantic versioning ( https://semver.org/ ). For that reason, every major, minor and point release should be tagged.

git tag -m "v0.0.1" "v0.0.1"
git push --tags

Continuous integration tests must pass on Travis CI. Our coverage threshold is 90% i.e you must keep coverage above 90%.

Contributing

I would like to cover the entire GitHub API and contributions are of course always welcome. The calling pattern is pretty well established, so adding new methods is relatively straightforward. See CONTRIBUTING.md for details.

Versioning

In general, profileutils follows semver as closely as we can for tagging releases of the package. For self-contained libraries, the application of semantic versioning is relatively straightforward and generally understood. We've adopted the following versioning policy:

  • We increment the major version with any incompatible change to non-preview functionality, including changes to the exported Go API surface or behavior of the API.
  • We increment the minor version with any backwards-compatible changes to functionality, as well as any changes to preview functionality in the GitHub API. GitHub makes no guarantee about the stability of preview functionality, so neither do we consider it a stable part of the go-github API.
  • We increment the patch version with any backwards-compatible bug fixes.

License

This library is distributed under the MIT license found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CanViewRole = Permission{
		Group:       PermissionGroupRole.String(),
		Scope:       "role.view",
		Description: "Can view role",
	}

	CanCreateRole = Permission{
		Group:       PermissionGroupRole.String(),
		Scope:       "role.create",
		Description: "Can create role",
	}

	CanEditRole = Permission{
		Group:       PermissionGroupRole.String(),
		Scope:       "role.edit",
		Description: "Can edit role",
	}

	CanAssignRole = Permission{
		Group:       PermissionGroupRole.String(),
		Scope:       "role.assign",
		Description: "Can assign a role",
	}
)

role management permissions

View Source
var (
	CanViewEmployee = Permission{
		Group:       PermissionGroupEmployee.String(),
		Scope:       "employee.view",
		Description: "Can create employee",
	}

	CanCreateEmployee = Permission{
		Group:       PermissionGroupEmployee.String(),
		Scope:       "employee.create",
		Description: "Can create employee",
	}

	CanRemoveEmployee = Permission{
		Group:       PermissionGroupEmployee.String(),
		Scope:       "employee.remove",
		Description: "Can remove employee",
	}
)

employee management permissions

View Source
var (
	CanViewAgent = Permission{
		Group:       PermissionGroupAgent.String(),
		Scope:       "agent.view",
		Description: "Can view agents",
	}

	CanRegisterAgent = Permission{
		Group:       PermissionGroupAgent.String(),
		Scope:       "agent.register",
		Description: "Can register agent",
	}

	CanIdentifyAgent = Permission{
		Group:       PermissionGroupAgent.String(),
		Scope:       "agent.identify",
		Description: "Can identify agent",
	}

	CanSuspendAgent = Permission{
		Group:       PermissionGroupAgent.String(),
		Scope:       "agent.suspend",
		Description: "Can suspend agent",
	}

	CanUnsuspendAgent = Permission{
		Group:       PermissionGroupAgent.String(),
		Scope:       "agent.unsuspend",
		Description: "Can unsuspend agent",
	}
)

agent management permissions

View Source
var (
	CanViewPartner = Permission{
		Group:       PermissionGroupPartner.String(),
		Scope:       "partner.view",
		Description: "Can view partners",
	}

	CanCreatePartner = Permission{
		Group:       PermissionGroupPartner.String(),
		Scope:       "partner.create",
		Description: "Can create partner",
	}
)

partner management permissions

View Source
var (
	CanProcessKYC = Permission{
		Group:       PermissionGroupKYC.String(),
		Scope:       "kyc.process",
		Description: "Can process KYC",
	}
	CanViewKYC = Permission{
		Group:       PermissionGroupKYC.String(),
		Scope:       "kyc.view",
		Description: "Can process KYC",
	}
)

kyc management permissions

View Source
var (
	CanViewConsumers = Permission{
		Group:       PermissionGroupConsumer.String(),
		Scope:       "consumer.view",
		Description: "Can view consumers",
	}

	CanCreateConsumer = Permission{
		Group:       PermissionGroupConsumer.String(),
		Scope:       "consumer.create",
		Description: "Can add consumer",
	}
)

consumer management permissions

View Source
var (
	CanViewCovers = Permission{
		Group:       PermissionGroupCovers.String(),
		Scope:       "covers.view",
		Description: "Can view covers",
	}

	CanSellCovers = Permission{
		Group:       PermissionGroupCovers.String(),
		Scope:       "covers.sell",
		Description: "Can sell covers",
	}
)

cover management permissions

View Source
var (
	CanViewPatient = Permission{
		Group:       PermissionGroupPatient.String(),
		Scope:       "patient.view",
		Description: "Can view patient",
	}

	CanCreatePatient = Permission{
		Group:       PermissionGroupPatient.String(),
		Scope:       "patient.create",
		Description: "Can add patient",
	}

	CanIdentifyPatient = Permission{
		Group:       PermissionGroupPatient.String(),
		Scope:       "patient.identify",
		Description: "Can identify patient",
	}
)

patient management permissions

AllAccountType is a slice that represents all the account types

AllPartnerType represents a list of the partner types we offer

View Source
var AuthorizedEmails = []string{"apa-dev@healthcloud.co.ke", "apa-prod@healthcloud.co.ke"}

AuthorizedEmails represent emails to check whether they have access to certain resources TODO: make these Env Vars

View Source
var AuthorizedPhones = []string{"+254700000000"}

AuthorizedPhones represent phonenumbers to check whether they have access to certain resources TODO: make these Env Vars

DefaultAdminPermissions generic permissions for admins. These permissions should be given to SIL customer happiness and relationship management staff.

DefaultAgentPermissions generic permissions for field agents. These permissions should be given to SIL field agents

DefaultEmployeePermissions generic permissions for field agents These permissions should be given to SIL field agents

DefaultSuperAdminPermissions generic permissions for super admins. These permissions should be given to the Be.Well dev team.

Functions

func UniquePermissions added in v0.0.11

func UniquePermissions(ctx context.Context, permissions []Permission) error

UniquePermissions validates that each permission has a unique code The validation has a test against the declared perms to ensure no permission duplication

Types

type AccountType

type AccountType string

AccountType defines the various supplier account types

const (
	AccountTypeIndividual   AccountType = "INDIVIDUAL"
	AccountTypeOrganisation AccountType = "ORGANISATION"
)

AccountTypeIndivdual is an example of a suppiler account type

func (AccountType) IsValid

func (e AccountType) IsValid() bool

IsValid checks if the account type is valid

func (AccountType) MarshalGQL

func (e AccountType) MarshalGQL(w io.Writer)

MarshalGQL converts AccountType into a valid JSON string

func (AccountType) String

func (e AccountType) String() string

func (*AccountType) UnmarshalGQL

func (e *AccountType) UnmarshalGQL(v interface{}) error

UnmarshalGQL converts the input, if valid, into a account type value

type Address

type Address struct {
	Latitude         string  `json:"latitude"`
	Longitude        string  `json:"longitude"`
	Locality         *string `json:"locality"`
	Name             *string `json:"name"`
	PlaceID          *string `json:"placeID"`
	FormattedAddress *string `json:"formattedAddress"`
}

Address holds Google Map's location data

type Assistant added in v0.0.18

type Assistant string

Assistant represents the user Assistant(BOWI/BEV)

const (
	//FemaleAssistant assists the user to navigate the CONSUMER app
	FemaleAssistant Assistant = "BEV"
	//MaleAssistant assists the user to navigate the CONSUMER app
	MaleAssistant Assistant = "BOWI"
)

type AuthCredentialResponse

type AuthCredentialResponse struct {
	CustomToken   *string `json:"customToken"`
	IDToken       *string `json:"id_token"`
	ExpiresIn     string  `json:"expires_in"`
	RefreshToken  string  `json:"refresh_token"`
	UID           string  `json:"uid"`
	IsAdmin       bool    `json:"is_admin"`
	IsAnonymous   bool    `json:"is_anonymous"`
	CanExperiment bool    `json:"can_experiment"`
	ChangePIN     bool    `json:"change_pin"`
	// Scopes are the permissions that a user has
	Scopes []string `json:"scopes"`
}

AuthCredentialResponse represents a user login response

type BioData

type BioData struct {
	FirstName   *string           `json:"firstName" firestore:"firstName"`
	LastName    *string           `json:"lastName" firestore:"lastName"`
	DateOfBirth *scalarutils.Date `json:"dateOfBirth" firestore:"dateOfBirth"`
	Gender      enumutils.Gender  `json:"gender" firestore:"gender"`
}

BioData structure of bio data information for a user

type Cover

type Cover struct {
	IdentifierHash        *string     `json:"identifier_hash" firestore:"identifierHash"`
	PayerName             string      `json:"payer_name,omitempty" firestore:"payerName"`
	PayerSladeCode        int         `json:"payer_slade_code,omitempty" firestore:"payerSladeCode"`
	MemberNumber          string      `json:"member_number,omitempty" firestore:"memberNumber"`
	MemberName            string      `json:"member_name,omitempty" firestore:"memberName"`
	BeneficiaryID         int         `json:"beneficiary_id,omitempty" firestore:"beneficiaryID"`
	EffectivePolicyNumber string      `json:"effective_policy_number,omitempty" firestore:"effectivePolicyNumber"`
	ValidFrom             time.Time   `json:"valid_from,omitempty" firestore:"validFrom"`
	ValidTo               time.Time   `json:"valid_to,omitempty" firestore:"validTo"`
	HasHistoricalClaims   bool        `json:"hasHistoricalClaims" firestore:"hasHistoricalClaims"`
	RawEligibility        interface{} `json:"rawEligibility" firestore:"rawEligibility"`
}

Cover is used to save a user's insurance details.

func (Cover) IsEntity

func (c Cover) IsEntity()

IsEntity marks this struct as a GraphQL entity

type Customer

type Customer struct {
	ID                 string             `json:"customerID" firestore:"id"`
	ProfileID          *string            `json:"profileID,omitempty" firestore:"profileID"`
	CustomerID         string             `json:"id,omitempty" firestore:"erpCustomerID"`
	ReceivablesAccount ReceivablesAccount `json:"receivables_account" firestore:"receivablesAccount"`
	Active             bool               `json:"active" firestore:"active"`
}

Customer used to create a customer request payload

type EDIUserProfile

type EDIUserProfile struct {
	ID              int      `json:"id"`
	GUID            string   `json:"guid"`
	Email           string   `json:"email"`
	FirstName       string   `json:"first_name"`
	LastName        string   `json:"last_name"`
	OtherNames      string   `json:"other_names"`
	IsStaff         bool     `json:"is_staff"`
	IsActive        bool     `json:"is_active"`
	Organisation    int      `json:"organisation"`
	BusinessPartner string   `json:"business_partner"`
	Roles           []string `json:"roles"`
	BPType          string   `json:"bp_type"`
}

EDIUserProfile is used to (de)serialialize the auth server profile of the logged in user.

func (EDIUserProfile) IsEntity

func (e EDIUserProfile) IsEntity()

IsEntity ...

type Feature added in v0.0.24

type Feature struct {
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	DefaultStatus bool      `json:"defaultStatus"`
	CreatedAt     time.Time `json:"createdAt"`
	// Keeps track of the timestamps a feature is updated
	// ie default status transitioned, added to a user or payer
	UpdatedAt time.Time `json:"updatedAt"`
}

Feature defines the output of a feature as defined by the datastore.

type Location

type Location struct {
	ID              string  `json:"id"`
	Name            string  `json:"name"`
	BranchSladeCode *string `json:"branchSladeCode"`
}

Location is used to store a user's branch or organisation

type LoginProviderType

type LoginProviderType string

LoginProviderType defines the method of used to login to bewell

const (
	LoginProviderTypePhone          LoginProviderType = "PHONE"
	LoginProviderTypeSocialGoogle   LoginProviderType = "SOCIAL_GOOGLE"
	LoginProviderTypeSocialFacebook LoginProviderType = "SOCIAL_FACEBOOK"
	LoginProviderTypeAppleFacebook  LoginProviderType = "SOCIAL_APPLE"
)

methods used to login

type NavAction struct {
	//  The name of the action
	Title string `json:"title"`

	// How the action is handled when tapped
	OnTapRoute string `json:"onTapRoute"`

	// A link to a PNG image that would serve as an avatar
	Icon feedlib.Link `json:"icon"`

	// Whether the user has marked the action as a favourite
	Favourite bool `json:"favourite"`

	// Sub menus in a navigation action
	Nested []NestedNavAction `json:"nested"`
}

NavAction is a Navigation Action that a user can perform on the app

type NavigationActions struct {
	// The primary actions the user can perform
	Primary []NavAction `json:"primary"`

	// The secondary action the user can perform
	Secondary []NavAction `json:"secondary"`
}

NavigationActions are Role based Navigation Actions for a User

type NestedNavAction

type NestedNavAction struct {
	//  The name of the action
	Title string `json:"title"`

	// How the action is handled when tapped
	OnTapRoute string `json:"onTapRoute"`
}

NestedNavAction is a nested navigation action which is a sub menu

type OtpResponse

type OtpResponse struct {
	OTP string `json:"otp"`
}

OtpResponse returns an otp

type PartnerType

type PartnerType string

PartnerType defines the different partner types we have in Be.Well

const (
	PartnerTypeRider          PartnerType = "RIDER"
	PartnerTypePractitioner   PartnerType = "PRACTITIONER"
	PartnerTypeProvider       PartnerType = "PROVIDER"
	PartnerTypePharmaceutical PartnerType = "PHARMACEUTICAL"
	PartnerTypeCoach          PartnerType = "COACH"
	PartnerTypeNutrition      PartnerType = "NUTRITION"
	PartnerTypeConsumer       PartnerType = "CONSUMER"
)

PartnerTypeRider is an example of a partner type who is involved in delivery of goods

func (PartnerType) IsValid

func (e PartnerType) IsValid() bool

IsValid checks if a partner type is valid or not

func (PartnerType) MarshalGQL

func (e PartnerType) MarshalGQL(w io.Writer)

MarshalGQL converts partner type into a valid JSON string

func (PartnerType) String

func (e PartnerType) String() string

func (*PartnerType) UnmarshalGQL

func (e *PartnerType) UnmarshalGQL(v interface{}) error

UnmarshalGQL converts the input, if valid, into an correct partner type value

type PayablesAccount

type PayablesAccount struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	IsActive    bool   `json:"is_active"`
	Number      string `json:"number"`
	Tag         string `json:"tag"`
	Description string `json:"description"`
}

PayablesAccount stores a supplier's payables account info

type Permission added in v0.0.8

type Permission struct {
	// Scope is the resource and action
	//
	// It should be in the form "<resource>.<action>"
	// Example: "user.create"
	Scope string `json:"scope"`

	// Description is used to keep details for a particular permission
	Description string `json:"description"`

	Group string `json:"group"`

	Allowed bool `json:"allowed"`
}

Permission defines an approval of a mode of access to a resource

func AllPermissions added in v0.0.11

func AllPermissions(ctx context.Context) ([]Permission, error)

AllPermissions returns all the defined permissions

func GetPermissionByScope added in v0.0.11

func GetPermissionByScope(ctx context.Context, scope string) (*Permission, error)

GetPermissionByScope retrieves a single permission using its scope

func GetUniquePermissions added in v0.0.11

func GetUniquePermissions(ctx context.Context, permissions []Permission) []Permission

GetUniquePermissions return s a list of unique permissions from list given

type PermissionGroup added in v0.0.8

type PermissionGroup string

PermissionGroup used to group permissions that have related resources

const (
	PermissionGroupRole PermissionGroup = "Roles"

	PermissionGroupEmployee PermissionGroup = "Employees"

	PermissionGroupAgent PermissionGroup = "Agents"

	PermissionGroupPartner PermissionGroup = "Partners"

	PermissionGroupKYC PermissionGroup = "KYC"

	PermissionGroupCovers PermissionGroup = "Covers"

	PermissionGroupConsumer PermissionGroup = "Consumers"

	PermissionGroupPatient PermissionGroup = "Patients"
)

PermissionGroups for the various resources

func (PermissionGroup) IsValid added in v0.0.12

func (p PermissionGroup) IsValid() bool

IsValid ..

func (PermissionGroup) MarshalGQL added in v0.0.12

func (p PermissionGroup) MarshalGQL(w io.Writer)

MarshalGQL ..

func (PermissionGroup) String added in v0.0.12

func (p PermissionGroup) String() string

String ...

func (*PermissionGroup) UnmarshalGQL added in v0.0.12

func (p *PermissionGroup) UnmarshalGQL(v interface{}) error

UnmarshalGQL ..

type PermissionInput

type PermissionInput struct {
	Action   string
	Resource string
}

PermissionInput input required to create a permission

type PermissionType

type PermissionType string

PermissionType defines the type of a permission

const (
	PermissionTypeSuperAdmin  PermissionType = "SUPER_ADMIN"
	PermissionTypeAdmin       PermissionType = "ADMIN"
	PermissionTypeCreateAdmin PermissionType = "CREATE_ADMIN"
	PermissionTypeRemoveAdmin PermissionType = "REMOVE_ADMIN"
	PermissionTypeAddSupplier PermissionType = "ADD_SUPPLIER"
	// whether an admin can add a supplier
	PermissionTypeRemoveSupplier PermissionType = "REMOVE_SUPPLIER"
	// whether an admin can suspend a supplier
	PermissionTypeSuspendSupplier PermissionType = "SUSPEND_SUPPLIER"
	// whether an admin can unsuspend a supplier
	PermissionTypeUnSuspendSupplier PermissionType = "UNSUSPEND_SUPPLIER"
	// whether an admin can view and process(approve/reject) kyc requests
	PermissionTypeProcessKYC PermissionType = "PROCESS_KYC"

	// agent management permissions
	PermissionTypeRegisterAgent  PermissionType = "REGISTER_AGENT"
	PermissionTypeSuspendAgent   PermissionType = "SUSPEND_AGENT"
	PermissionTypeUnsuspendAgent PermissionType = "UNSUSPEND_AGENT"

	// partner management permissions
	PermissionTypeCreatePartner PermissionType = "CREATE_PARTNER"
	PermissionTypeUpdatePartner PermissionType = "UPDATE_PARTNER"
	PermissionTypeDeletePartner PermissionType = "DELETE_PARTNER"

	// consumer management permissions
	PermissionTypeCreateConsumer PermissionType = "CREATE_CONSUMER"
	PermissionTypeUpdateConsumer PermissionType = "UPDATE_CONSUMER"
	PermissionTypeDeleteConsumer PermissionType = "DELETE_CONSUMER"

	// patient management permissions
	PermissionTypeCreatePatient   PermissionType = "CREATE_PATIENT"
	PermissionTypeUpdatePatient   PermissionType = "UPDATE_PATIENT"
	PermissionTypeDeletePatient   PermissionType = "DELETE_PATIENT"
	PermissionTypeIdentifyPatient PermissionType = "IDENTIFY_PATIENT"
)

bewell admin permissions. this is not exhausive. More will be added on a need by need basis after analysis of the application and assert what actions need to the admin-permissioned

type ReceivablesAccount

type ReceivablesAccount struct {
	ID          string `json:"id" firestore:"id"`
	Name        string `json:"name" firestore:"name"`
	IsActive    bool   `json:"is_active" firestore:"isActive"`
	Number      string `json:"number" firestore:"number"`
	Tag         string `json:"tag" firestore:"tag"`
	Description string `json:"description" firestore:"description"`
}

ReceivablesAccount stores a customer's receivables account info

type Role added in v0.0.8

type Role struct {
	// Unique identifier for a role
	ID string `json:"id" firestore:"id"`

	// Organization ID for which the role is created and used
	OrganizationID string `json:"organizationID,omitempty" firestore:"organizationID"`

	// Name given to the role
	Name string `json:"name" firestore:"name"`

	// Description is used to keep details for a particular role
	Description string `json:"description" firestore:"description"`

	// Active indicates whether the role is operational
	Active bool `json:"active" firestore:"active"`

	// List of allowed permission scopes for a role
	Scopes []string `json:"scopes" firestore:"scopes"`

	// CreatedBy is the Profile ID of the user creating the role.
	CreatedBy string `json:"createdBy,omitempty" firestore:"createdBy"`

	// Created is the timestamp indicating when the role was created
	Created time.Time `json:"created" firestore:"created"`

	// UpdatedBy is the Profile ID of the user who last updated the role.
	UpdatedBy string `json:"updatedBy,omitempty" firestore:"updatedBy"`

	// Updated is the timestamp indicating when the role was last updated
	Updated time.Time `json:"updated" firestore:"updated"`
}

Role is the user group defining permissions

func (Role) HasPermission added in v0.0.11

func (r Role) HasPermission(ctx context.Context, scope string) bool

HasPermission checks if a role has the permission defined

func (Role) Permissions added in v0.0.11

func (r Role) Permissions(ctx context.Context) ([]Permission, error)

Permissions returns all permissions with role scoped marked as allowed

type RoleType

type RoleType string

RoleType defines the type of role a subject has and the associated permissions

const (
	RoleTypeEmployee RoleType = "EMPLOYEE"
	RoleTypeAgent    RoleType = "AGENT"
)

Various roles in bewell

func (RoleType) IsValid

func (r RoleType) IsValid() bool

IsValid checks if the role type is valid

func (RoleType) Permissions

func (r RoleType) Permissions() []PermissionType

Permissions returns permissions for a certain role

type Supplier

type Supplier struct {
	ID                     string                 `json:"supplierID" firestore:"id"`
	ProfileID              *string                `json:"profileID" firestore:"profileID"`
	SupplierID             string                 `json:"id" firestore:"erpSupplierID"`
	SupplierName           string                 `json:"supplierName" firestore:"supplierName"`
	PayablesAccount        *PayablesAccount       `json:"payables_account" firestore:"payablesAccount"`
	SupplierKYC            map[string]interface{} `json:"supplierKYC" firestore:"supplierKYC"`
	Active                 bool                   `json:"active" firestore:"active"`
	AccountType            *AccountType           `json:"accountType" firestore:"accountType"`
	UnderOrganization      bool                   `json:"underOrganization" firestore:"underOrganization"`
	IsOrganizationVerified bool                   `json:"isOrganizationVerified" firestore:"isOrganizationVerified"`
	SladeCode              string                 `json:"sladeCode" firestore:"sladeCode"`
	ParentOrganizationID   string                 `json:"parentOrganizationID" firestore:"parentOrganizationID"`
	OrganizationName       string                 `json:"organizationName" firestore:"organizationName"`
	HasBranches            bool                   `json:"hasBranches,omitempty" firestore:"hasBranches"`
	Location               *Location              `json:"location,omitempty" firestore:"location"`
	PartnerType            PartnerType            `json:"partnerType" firestore:"partnerType"`
	EDIUserProfile         *EDIUserProfile        `json:"ediuserprofile" firestore:"ediserprofile"`
	PartnerSetupComplete   bool                   `json:"partnerSetupComplete" firestore:"partnerSetupComplete"`
	KYCSubmitted           bool                   `json:"kycSubmitted" firestore:"kycSubmitted"`
}

Supplier used to create a supplier request payload You can add more or remove fields to suit your organization/project needs

type Upload

type Upload struct {
	ID          string    `json:"id" firestore:"id"`
	URL         string    `json:"url" firestore:"url"`
	Size        int       `json:"size" firestore:"size"`
	Hash        string    `json:"hash" firestore:"hash"`
	Creation    time.Time `json:"creation" firestore:"creation"`
	Title       string    `json:"title" firestore:"title"`
	ContentType string    `json:"contentType" firestore:"contentType"`
	Language    string    `json:"language" firestore:"language"`
	Base64data  string    `json:"base64data" firestore:"base64data"`
}

Upload represents a file uploaded to cloud storage

func (Upload) GetID

func (u Upload) GetID() firebasetools.ID

GetID marks upload as a relay node

func (Upload) IsEntity

func (u Upload) IsEntity()

IsEntity marks upload as an apollo federation entity

func (Upload) IsNode

func (u Upload) IsNode()

IsNode marks upload as a relay node

func (Upload) SetID

func (u Upload) SetID(id string)

SetID marks upload as a relay node

type UploadInput

type UploadInput struct {
	Title       string `json:"title"`
	ContentType string `json:"contentType"`
	Language    string `json:"language"`
	Base64data  string `json:"base64data"`
	Filename    string `json:"filename"`
}

UploadInput is used to send data for new uploads

type UserCommunicationsSetting

type UserCommunicationsSetting struct {
	ID            string `json:"id" firestore:"id"`
	ProfileID     string `json:"profileID" firestore:"profileID"`
	AllowWhatsApp bool   `json:"allowWhatsApp" firestore:"allowWhatsApp"`
	AllowTextSMS  bool   `json:"allowTextSMS" firestore:"allowTextSMS"`
	AllowPush     bool   `json:"allowPush" firestore:"allowPush"`
	AllowEmail    bool   `json:"allowEmail" firestore:"allowEmail"`
}

UserCommunicationsSetting hold information about the user communication's channels. if a channel is true, we will be able to send them marketing or promotional messages

type UserInfo added in v0.0.5

type UserInfo struct {
	DisplayName string `json:"displayName,omitempty"`
	Email       string `json:"email,omitempty"`
	PhoneNumber string `json:"phoneNumber,omitempty"`
	PhotoURL    string `json:"photoUrl,omitempty"`
	// In the ProviderUserInfo[] ProviderID can be a short domain name (e.g. google.com),
	// or the identity of an OpenID identity provider.
	// In UserRecord.UserInfo it will return the constant string "firebase".
	ProviderID   string  `json:"providerId,omitempty"`
	UID          string  `json:"rawId,omitempty"`
	ReferralLink *string `json:"referral_link,omitempty"`
}

UserInfo is a collection of standard profile information for a user.

func GetLoggedInUser added in v0.0.7

func GetLoggedInUser(ctx context.Context) (*UserInfo, error)

GetLoggedInUser retrieves logged in user information

type UserProfile

type UserProfile struct {
	// globally unique identifier for a profile
	ID string `json:"id" firestore:"id"`

	// unique user name. Synonymous to a handle
	// e.g @juliusowino
	// this will be auto-generated on first login, meaning a user must have a username
	UserName *string `json:"userName" firestore:"userName"`

	// VerifiedIdentifiers represent various ways the user has been able to login
	// and these providers point to the same user
	VerifiedIdentifiers []VerifiedIdentifier `json:"verifiedIdentifiers" firestore:"verifiedIdentifiers"`

	// uids associated with a profile. Theses UIDS should match those in the verfiedIdentifiers.
	// the purpose of having verifiedUIDS is enbale ease querying of the profile using firebase query constructs.
	// when we migrate to postgres, this will be retired
	// the length of verfiedIdentifiers and verifiedUIDS should match
	VerifiedUIDS []string `json:"verifiedUIDS" firestore:"verifiedUIDS"`

	// this is the first class unique attribute of a user profile.  A user profile MUST HAVE A PRIMARY PHONE NUMBER
	PrimaryPhone *string `json:"primaryPhone" firestore:"primaryPhone"`

	// this is the second class unique attribute of a user profile. This can be updated as the user desires
	PrimaryEmailAddress *string `json:"primaryEmailAddress" firestore:"primaryEmailAddress"`

	// these are all phone numbers associated with a user. These phone numbers can be promoted to PRIMARY PHONE NUMBER
	// and/or used for account recovery
	SecondaryPhoneNumbers []string `json:"secondaryPhoneNumbers" firestore:"secondaryPhoneNumbers"`

	SecondaryEmailAddresses []string `json:"secondaryEmailAddresses" firestore:"secondaryEmailAddresses"`

	PushTokens []string `json:"pushTokens,omitempty" firestore:"pushTokens"`

	// Role of the user in the system. Valid for Suppliers, SIL employees and Agents
	Role RoleType `json:"role,omitempty" firestore:"role"`

	//  Roles is a list of Role IDs assigned to user
	Roles []string `json:"roles,omitempty" firestore:"roles"`

	// what the user is allowed to do. Only valid for admins
	Permissions []PermissionType `json:"permissions,omitempty" firestore:"permissions"`

	// favorite navactions are titles of the navactions that the user has bookmarked
	FavNavActions []string `json:"favNavActions,omitempty" firestore:"favNavActions"`

	// we determine if a user is "live" by examining fields on their profile
	TermsAccepted bool `json:"terms_accepted,omitempty" firestore:"termsAccepted"`

	// determines whether a specific will be visible in query results. If the `true`, means the profile in not
	// in active state and the user should not be allowed to login
	Suspended bool `json:"suspended" firestore:"suspended"`

	// a user's profile photo can be stored as base 64 encoded PNG
	PhotoUploadID string `json:"photoUploadID,omitempty" firestore:"photoUploadID"`

	// a user can have zero or more insurance covers
	Covers []Cover `json:"covers,omitempty" firestore:"covers"`

	// a user's biodata is stored on the profile
	UserBioData BioData `json:"userBioData,omitempty" firestore:"userBioData"`

	// this is the user's home geo location
	HomeAddress *Address `json:"homeAddress,omitempty" firestore:"homeAddress"`

	// this is the user's work geo location
	WorkAddress *Address `json:"workAddress,omitempty" firestore:"workAddress"`

	// this is the profile ID of the logged in user creating this user.
	CreatedByID *string `json:"cratedByID,omitempty" firestore:"createdByID"`

	// Timestamp indicating when the user was created
	Created *time.Time `json:"created,omitempty" firestore:"created"`

	// this is the version of the app that the user is currently using : CONSUMER
	ConsumerAppVersion *string `json:"consumerAppVersion,omitempty" firestore:"consumerAppVersion"`

	// this is the version of the app that the user is currently using : PRO
	PROAppVersion *string `json:"proAppVersion,omitempty" firestore:"proAppVersion"`

	//Assistant indicates the user assistant
	Assistant Assistant `json:"assistant,omitempty" firestore:"assistant"`

	// ReferralLink is the user's app download referral link
	ReferralLink *string `json:"referral_link,omitempty" firestore:"referralLink"`

	// FeaturesAccess gives us information on the features that a user profile can or can't access
	FeaturesAccess []*Feature `json:"features,omitempty" firestore:"featureAccess"`
}

UserProfile serializes the profile of the logged in user.

func (UserProfile) HasPermission added in v0.0.6

func (u UserProfile) HasPermission(perm PermissionType) bool

HasPermission checks if user has specific permission

func (UserProfile) HasRole added in v0.0.10

func (u UserProfile) HasRole(roleID string) bool

HasRole checks if user has role

func (UserProfile) IsEntity

func (u UserProfile) IsEntity()

IsEntity marks a profile as a GraphQL entity

type UserProfileRepository

type UserProfileRepository interface {
	UpdateUserName(ctx context.Context, id string, userName string) error
	UpdatePrimaryPhoneNumber(ctx context.Context, id string, phoneNumber string) error
	UpdatePrimaryEmailAddress(ctx context.Context, id string, emailAddress string) error
	UpdateSecondaryPhoneNumbers(ctx context.Context, id string, phoneNumbers []string) error
	UpdateSecondaryEmailAddresses(ctx context.Context, id string, emailAddresses []string) error
	UpdateVerifiedIdentifiers(ctx context.Context, id string, identifiers []VerifiedIdentifier) error
	UpdateVerifiedUIDS(ctx context.Context, id string, uids []string) error
	UpdateSuspended(ctx context.Context, id string, status bool) error
	UpdatePhotoUploadID(ctx context.Context, id string, uploadID string) error
	UpdateCovers(ctx context.Context, id string, covers []Cover) error
	UpdatePushTokens(ctx context.Context, id string, pushToken []string) error
	UpdatePermissions(ctx context.Context, id string, perms []PermissionType) error
	UpdateBioData(ctx context.Context, id string, data BioData) error
	UpdateAddresses(ctx context.Context, id string, address Address, addressType enumutils.AddressType) error
	UpdateAppVersion(ctx context.Context, id string, appVersion string, flavour feedlib.Flavour) error
	UpdateRole(ctx context.Context, id string, role RoleType) error
}

UserProfileRepository defines signatures that a repeository that acts on the userprofile should implement. Repository heres means a storage unit like firebase or mongodb or pg.

type UserResponse

type UserResponse struct {
	Profile               *UserProfile               `json:"profile"`
	SupplierProfile       *Supplier                  `json:"supplierProfile"`
	CustomerProfile       *Customer                  `json:"customerProfile"`
	CommunicationSettings *UserCommunicationsSetting `json:"communicationSettings"`
	Auth                  AuthCredentialResponse     `json:"auth"`
	NavActions            *NavigationActions         `json:"navigationActions"`
}

UserResponse returns a user's sign up/in response

type VerifiedIdentifier

type VerifiedIdentifier struct {
	UID           string            `json:"uid" firestore:"uid"`
	Timestamp     time.Time         `json:"timeStamp" firestore:"timeStamp"`
	LoginProvider LoginProviderType `json:"loginProvider" firestore:"loginProvider"`
}

VerifiedIdentifier metadata of how the user has logged in to bewell

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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