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
4 changes: 4 additions & 0 deletions cmd/server/assets/admin/_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<a class="nav-link{{if .currentPath.IsDir "/admin/users"}} active{{end}}" href="/admin/users">System admins</a>
</li>

<li class="nav-item">
<a class="nav-link{{if .currentPath.IsDir "/admin/mobileapps"}} active{{end}}" href="/admin/mobileapps">Mobile apps</a>
</li>

<li class="nav-item">
<a class="nav-link{{if .currentPath.IsDir "/admin/sms"}} active{{end}}" href="/admin/sms">SMS</a>
</li>
Expand Down
60 changes: 60 additions & 0 deletions cmd/server/assets/admin/mobileapps/show.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{define "admin/mobileapps/show"}}

{{$apps := .apps}}

<!doctype html>
<html lang="en">
<head>
{{template "head" .}}
</head>

<body class="tab-content">
{{template "admin/navbar" .}}

<main role="main" class="container">
{{template "flash" .}}

<div class="card mb-3 shadow-sm">
<div class="card-header">Mobile apps</div>
<div class="card-body">

{{if .apps}}
<div class="table-responsive">
<table class="table table-bordered table-striped bg-white">
<thead>
<tr>
<th scope="col">App</th>
<th scope="col" width="95">Enabled</th>
</tr>
</thead>
<tbody>
{{range .apps}}
<tr>

<td>
<a href="/mobile-apps/{{.ID}}" class="text-truncate">{{.Name}}</a>
</td>

<td>
{{if .DeletedAt}}
<span class="badge badge-pill badge-danger">Deleted</span>
{{else}}
<span class="badge badge-pill badge-success">Enabled</span>
{{end}}
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{else}}
<p class="text-center">
<em>There are no mobile apps.</em>
</p>
{{end}}
</div>
</div>
</main>
</body>
</html>
{{end}}
7 changes: 4 additions & 3 deletions internal/routes/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,15 @@ func Server(
adminSub.Handle("/realms/{id:[0-9]+}/leave", adminController.HandleRealmsLeave()).Methods("PATCH")
adminSub.Handle("/realms/{id:[0-9]+}", adminController.HandleRealmsUpdate()).Methods("PATCH")

adminSub.Handle("/sms", adminController.HandleSMSUpdate()).Methods("GET", "POST")
adminSub.Handle("/email", adminController.HandleEmailUpdate()).Methods("GET", "POST")

adminSub.Handle("/users", adminController.HandleUsersIndex()).Methods("GET")
adminSub.Handle("/users", adminController.HandleUsersCreate()).Methods("POST")
adminSub.Handle("/users/new", adminController.HandleUsersCreate()).Methods("GET")
adminSub.Handle("/users/{id:[0-9]+}", adminController.HandleUsersDelete()).Methods("DELETE")

adminSub.Handle("/mobileapps", adminController.HandleMobileAppsShow()).Methods("GET")
adminSub.Handle("/sms", adminController.HandleSMSUpdate()).Methods("GET", "POST")
adminSub.Handle("/email", adminController.HandleEmailUpdate()).Methods("GET", "POST")

adminSub.Handle("/caches", adminController.HandleCachesIndex()).Methods("GET")
adminSub.Handle("/caches/clear/{id}", adminController.HandleCachesClear()).Methods("POST")

Expand Down
44 changes: 44 additions & 0 deletions pkg/controller/admin/mobile_apps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 admin

import (
"context"
"net/http"

"github.com/google/exposure-notifications-verification-server/pkg/controller"
"github.com/google/exposure-notifications-verification-server/pkg/database"
)

// HandleMobileAppsShow shows the configured mobile apps.
func (c *Controller) HandleMobileAppsShow() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

apps, err := c.db.ListActiveApps()
if err != nil {
controller.InternalError(w, r, c.h, err)
return
}

c.renderShowMobileApps(ctx, w, apps)
})
}

func (c *Controller) renderShowMobileApps(ctx context.Context, w http.ResponseWriter, apps []*database.MobileApp) {
m := controller.TemplateMapFromContext(ctx)
m["apps"] = apps
c.h.RenderHTML(w, "admin/mobileapps/show", m)
}
17 changes: 17 additions & 0 deletions pkg/database/mobile_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ func (a *MobileApp) BeforeSave(tx *gorm.DB) error {
return nil
}

// ListActiveApps finds all active mobile apps.
func (db *Database) ListActiveApps() ([]*MobileApp, error) {
// Find the apps.
var apps []*MobileApp
if err := db.db.
Model(&MobileApp{}).
Find(&apps).
Order("mobile_apps.deleted_at DESC, LOWER(mobile_apps.name)").
Error; err != nil {
if IsNotFound(err) {
return apps, nil
}
return nil, err
}
return apps, nil
}

// ListActiveAppsByOS finds mobile apps by their realm and OS.
func (db *Database) ListActiveAppsByOS(realmID uint, os OSType) ([]*MobileApp, error) {
// Find the apps.
Expand Down