Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion cmd/server/assets/realmadmin/_form_codes.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@
{{ .csrfField }}
<input type="hidden" name="codes" value="1" />

<div class="form-group">
<label>Bulk issue codes</label>
<div class="form-group">
<div class="form-check">
<input type="radio" name="allow_bulk" id="allow-bulk-true" class="form-check-input" value="true"{{if $realm.AllowBulkUpload }} checked{{end}}/>
<label for="allow-bulk-true" class="form-check-label">
Allow
<small class="form-text text-muted mb-3">
Allow users of this realm to bulk issue codes by uploading from a results file.
</small>
</label>
</div>

<div class="form-check mb-3">
<input type="radio" name="allow_bulk" id="allow-bulk-false" class="form-check-input" value="false"{{if not $realm.AllowBulkUpload }} checked{{end}} />
<label for="allow-bulk-false" class="form-check-label">
Disallow
<small class="form-text text-muted mb-3">
Users are only allowed to issue one code at a time. Upload from a results file is disallowed.
</small>
</label>
</div>
</div>
</div>

<div class="form-group">
<label>Allowed test types</label>
{{if not $realm.EnableENExpress}}
Expand Down Expand Up @@ -76,7 +101,7 @@
<small class="form-text text-muted">
<strong>Recommended:</strong> Require a symptom date or test date
when generating a verification code. Attempting to generate a verification
code without a date will return an error. <em>Exposure notifications are
code without a date will return an error. <em>Exposure notifications are
more accurate when a date is provided.</em>
</small>
</label>
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/realmadmin/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (c *Controller) HandleSettings() http.Handler {

Codes bool `form:"codes"`
AllowedTestTypes database.TestType `form:"allowed_test_types"`
AllowBulkUpload bool `form:"allow_bulk"`
RequireDate bool `form:"require_date"`
CodeLength uint `form:"code_length"`
CodeDurationMinutes int64 `form:"code_duration"`
Expand Down Expand Up @@ -151,6 +152,7 @@ func (c *Controller) HandleSettings() http.Handler {
if form.Codes {
realm.AllowedTestTypes = form.AllowedTestTypes
realm.RequireDate = form.RequireDate
realm.AllowBulkUpload = form.AllowBulkUpload
realm.SMSTextTemplate = form.SMSTextTemplate

// These fields can only be set if ENX is disabled
Expand Down
10 changes: 10 additions & 0 deletions pkg/database/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,16 @@ func (db *Database) getMigrations(ctx context.Context) *gormigrate.Gormigrate {
return nil
},
},
{
ID: "00067-AddRealmAllowBulkUpload",
Migrate: func(tx *gorm.DB) error {
logger.Debugw("db migrations: adding allow_bulk_upload to realms")
return tx.Exec("ALTER TABLE realms ADD COLUMN IF NOT EXISTS allow_bulk_upload bool DEFAULT false").Error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't set the NOT NULL constraint FWIW.

},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("ALTER TABLE realms DROP COLUMN IF EXISTS allow_bulk_upload").Error
},
},
})
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/database/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ type Realm struct {
WelcomeMessage string `gorm:"-"`
WelcomeMessagePtr *string `gorm:"column:welcome_message; type:text;"`

// AllowBulkUpload allows users to issue codes from a batch file of test results.
AllowBulkUpload bool `gorm:"type:boolean; not null; default:false"`

// Code configuration
CodeLength uint `gorm:"type:smallint; not null; default: 8"`
CodeDuration DurationSeconds `gorm:"type:bigint; not null; default: 900"` // default 15m (in seconds)
Expand Down