Skip to content

Commit

Permalink
Add new fields to Org model
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jun 17, 2020
1 parent 39b0289 commit e3e25e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Binary file modified mailroom_test.dump
Binary file not shown.
14 changes: 12 additions & 2 deletions models/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,23 @@ const (
// Org is mailroom's type for RapidPro orgs. It also implements the envs.Environment interface for GoFlow
type Org struct {
o struct {
ID OrgID `json:"id"`
Config null.Map `json:"config"`
ID OrgID `json:"id"`
Suspended bool `json:"is_suspended"`
UsesTopups bool `json:"uses_topups"`
Config null.Map `json:"config"`
}
env envs.Environment
}

// ID returns the id of the org
func (o *Org) ID() OrgID { return o.o.ID }

// Suspended returns whether the org has been suspended
func (o *Org) Suspended() bool { return o.o.Suspended }

// UsesTopups returns whether the org uses topups
func (o *Org) UsesTopups() bool { return o.o.UsesTopups }

// DateFormat returns the date format for this org
func (o *Org) DateFormat() envs.DateFormat { return o.env.DateFormat() }

Expand Down Expand Up @@ -185,6 +193,8 @@ func loadOrg(ctx context.Context, db sqlx.Queryer, orgID OrgID) (*Org, error) {
const selectOrgByID = `
SELECT ROW_TO_JSON(o) FROM (SELECT
id,
is_suspended,
uses_topups,
COALESCE(o.config::json,'{}'::json) AS config,
(SELECT CASE date_format WHEN 'D' THEN 'DD-MM-YYYY' WHEN 'M' THEN 'MM-DD-YYYY' END) AS date_format,
'tt:mm' AS time_format,
Expand Down
2 changes: 2 additions & 0 deletions models/env_test.go → models/orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func TestOrgs(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, OrgID(1), org.ID())
assert.False(t, org.Suspended())
assert.True(t, org.UsesTopups())
assert.Equal(t, envs.DateFormatDayMonthYear, org.DateFormat())
assert.Equal(t, envs.TimeFormatHourMinute, org.TimeFormat())
assert.Equal(t, envs.RedactionPolicyNone, org.RedactionPolicy())
Expand Down

0 comments on commit e3e25e5

Please sign in to comment.