Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Commit ddd634d

Browse files
authored
Add appstore url to mobile apps. (#738)
1 parent 0db80f9 commit ddd634d

File tree

7 files changed

+41
-0
lines changed

7 files changed

+41
-0
lines changed

cmd/server/assets/mobileapps/_app.html

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
{{template "errorable" $app.ErrorsFor "name"}}
1010
</div>
1111

12+
<div class="form-label-group">
13+
<input type="text" name="url" id="url" class="form-control{{if $app.ErrorsFor "url"}} is-invalid{{end}}" value="{{$app.URL}}"
14+
placeholder="AppStore URL" autofocus>
15+
<label for="name">AppStore URL</label>
16+
{{template "errorable" $app.ErrorsFor "url"}}
17+
</div>
18+
1219
<div class="form-group">
1320
<select name="os" id="os" class="form-control custom-select{{if $app.ErrorsFor "os"}} is-invalid{{end}}">
1421
<option selected disabled>Choose platform...</option>

cmd/server/assets/mobileapps/show.html

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ <h1>{{$app.Name}}</h1>
3030
<dt>App name</dt>
3131
<dd>{{$app.Name}}</dd>
3232

33+
<dt>AppStore link</dt>
34+
<dd><a href="{{$app.URL}}" target="_blank">{{$app.URL}}</a></dd>
35+
3336
<dt>OS</dt>
3437
<dd>
3538
{{if (eq $app.OS .iOS)}}

pkg/controller/mobileapps/create.go

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
func (c *Controller) HandleCreate() http.Handler {
2727
type FormData struct {
2828
Name string `form:"name"`
29+
URL string `form:"url"`
2930
OS database.OSType `form:"os"`
3031
AppID string `form:"app_id"`
3132
SHA string `form:"sha"`
@@ -64,6 +65,7 @@ func (c *Controller) HandleCreate() http.Handler {
6465
if err := controller.BindForm(w, r, &form); err != nil {
6566
app := &database.MobileApp{
6667
Name: form.Name,
68+
URL: form.URL,
6769
OS: form.OS,
6870
AppID: form.AppID,
6971
SHA: form.SHA,
@@ -78,6 +80,7 @@ func (c *Controller) HandleCreate() http.Handler {
7880
app := &database.MobileApp{
7981
Name: form.Name,
8082
RealmID: realm.ID,
83+
URL: form.URL,
8184
OS: form.OS,
8285
AppID: form.AppID,
8386
SHA: form.SHA,

pkg/controller/mobileapps/update.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
func (c *Controller) HandleUpdate() http.Handler {
2929
type FormData struct {
3030
Name string `form:"name"`
31+
URL string `form:"url"`
3132
OS database.OSType `form:"os"`
3233
AppID string `form:"app_id"`
3334
SHA string `form:"sha"`
@@ -89,6 +90,7 @@ func (c *Controller) HandleUpdate() http.Handler {
8990

9091
// Build the authorized app struct
9192
app.Name = form.Name
93+
app.URL = form.URL
9294
app.OS = form.OS
9395
app.AppID = form.AppID
9496
app.SHA = form.SHA

pkg/database/migrations.go

+9
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,15 @@ func (db *Database) getMigrations(ctx context.Context) *gormigrate.Gormigrate {
14271427
return tx.Exec("ALTER TABLE realms DROP COLUMN IF EXISTS mfa_required_grace_period").Error
14281428
},
14291429
},
1430+
{
1431+
ID: "00058-AddAppStoreLink",
1432+
Migrate: func(tx *gorm.DB) error {
1433+
return tx.Exec("ALTER TABLE mobile_apps ADD COLUMN IF NOT EXISTS url TEXT").Error
1434+
},
1435+
Rollback: func(tx *gorm.DB) error {
1436+
return tx.Exec("ALTER TABLE realms DROP COLUMN IF EXISTS url").Error
1437+
},
1438+
},
14301439
})
14311440
}
14321441

pkg/database/mobile_app.go

+15
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ type MobileApp struct {
5757
// RealmID is the id of the mobile app.
5858
RealmID uint `gorm:"column:realm_id;"`
5959

60+
// URL is the link to the app in it's appstore.
61+
URL string `gorm:"-"`
62+
URLPtr *string `gorm:"column:url; type:text"`
63+
6064
// OS is the type of the application we're using (eg, iOS, Android).
6165
OS OSType `gorm:"column:os; type:int;"`
6266

@@ -84,6 +88,12 @@ func (a *MobileApp) BeforeSave(tx *gorm.DB) error {
8488
a.AddError("app_id", "is required")
8589
}
8690

91+
a.URL = strings.TrimSpace(a.URL)
92+
a.URLPtr = stringPtr(a.URL)
93+
if a.URL == "" {
94+
a.AddError("url", "is required")
95+
}
96+
8797
// Ensure OS is valid
8898
if a.OS < OSTypeIOS || a.OS > OSTypeAndroid {
8999
a.AddError("os", "is invalid")
@@ -225,6 +235,11 @@ func (a *MobileApp) AuditDisplay() string {
225235
return fmt.Sprintf("%s (%s)", a.Name, a.OS.Display())
226236
}
227237

238+
func (a *MobileApp) AfterFind(tx *gorm.DB) error {
239+
a.URL = stringValue(a.URLPtr)
240+
return nil
241+
}
242+
228243
// PurgeMobileApps will delete mobile apps that have been deleted for more than
229244
// the specified time.
230245
func (db *Database) PurgeMobileApps(maxAge time.Duration) (int64, error) {

tools/seed/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,14 @@ func realMain(ctx context.Context) error {
172172
{
173173
Name: "Example iOS app",
174174
RealmID: realm1.ID,
175+
URL: "http://apple.com",
175176
OS: database.OSTypeIOS,
176177
AppID: "ios.example.app",
177178
},
178179
{
179180
Name: "Example Android app",
180181
RealmID: realm1.ID,
182+
URL: "http://google.com",
181183
OS: database.OSTypeAndroid,
182184
AppID: "android.example.app",
183185
SHA: "AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA",

0 commit comments

Comments
 (0)