This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24662c4
commit bb06ef2
Showing
7 changed files
with
306 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package realmadmin | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/google/exposure-notifications-verification-server/pkg/controller" | ||
"github.com/google/exposure-notifications-verification-server/pkg/database" | ||
) | ||
|
||
func (c *Controller) HandleDisableExpress() http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
|
||
session := controller.SessionFromContext(ctx) | ||
if session == nil { | ||
controller.MissingSession(w, r, c.h) | ||
return | ||
} | ||
flash := controller.Flash(session) | ||
|
||
realm := controller.RealmFromContext(ctx) | ||
if realm == nil { | ||
controller.MissingRealm(w, r, c.h) | ||
return | ||
} | ||
|
||
if !realm.EnableENExpress { | ||
flash.Error("Realm is not currently enrolled in EN Express.") | ||
c.renderShow(ctx, w, r, realm, nil) | ||
return | ||
} | ||
|
||
defaultSettings := database.NewRealmWithDefaults("--") | ||
realm.EnableENExpress = false | ||
realm.SMSTextTemplate = defaultSettings.SMSTextTemplate | ||
if err := c.db.SaveRealm(realm); err != nil { | ||
flash.Error("Failed to disable EN Express: %v", err) | ||
|
||
c.renderShow(ctx, w, r, realm, nil) | ||
return | ||
} | ||
|
||
flash.Alert("Successfully disabled EN Express") | ||
http.Redirect(w, r, "/realm/settings", http.StatusSeeOther) | ||
}) | ||
} | ||
|
||
func (c *Controller) HandleEnableExpress() http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
|
||
session := controller.SessionFromContext(ctx) | ||
if session == nil { | ||
controller.MissingSession(w, r, c.h) | ||
return | ||
} | ||
flash := controller.Flash(session) | ||
|
||
realm := controller.RealmFromContext(ctx) | ||
if realm == nil { | ||
controller.MissingRealm(w, r, c.h) | ||
return | ||
} | ||
|
||
if realm.EnableENExpress { | ||
flash.Error("Realm already has EN Express Enabled.") | ||
c.renderShow(ctx, w, r, realm, nil) | ||
return | ||
} | ||
|
||
// Enable EN Express by setting default settings. | ||
enxSettings := database.NewRealmWithDefaults("--") | ||
realm.EnableENExpress = true | ||
realm.CodeLength = enxSettings.CodeLength | ||
realm.CodeDuration = enxSettings.CodeDuration | ||
realm.LongCodeLength = enxSettings.LongCodeLength | ||
realm.LongCodeDuration = enxSettings.LongCodeDuration | ||
realm.SMSTextTemplate = "This is your Exposure Notifications Verification code: [enslink] Expires in [longexpires] hours" | ||
// Confirmed is the only allowed test type for EN Express. | ||
realm.AllowedTestTypes = database.TestTypeConfirmed | ||
|
||
if err := c.db.SaveRealm(realm); err != nil { | ||
flash.Error("Failed to enable EN Express: %v", err) | ||
// This will allow the user to correct other validation errors and then click "uprade" again. | ||
realm.EnableENExpress = false | ||
realm.SMSTextTemplate = enxSettings.SMSTextTemplate | ||
c.renderShow(ctx, w, r, realm, nil) | ||
return | ||
} | ||
|
||
flash.Alert("Successfully enabled EN Express!") | ||
http.Redirect(w, r, "/realm/settings", http.StatusSeeOther) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.