mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(upgrade): show subtle banner [EE-5017] (#8489)
This commit is contained in:
parent
631503fc1b
commit
9a8e95d017
21 changed files with 217 additions and 90 deletions
|
@ -6,11 +6,15 @@ import (
|
|||
portainerDsErrors "github.com/portainer/portainer/api/dataservices/errors"
|
||||
)
|
||||
|
||||
func (m *Migrator) migrateDBVersionToDB81() error {
|
||||
return m.updateEdgeStackStatusForDB81()
|
||||
func (m *Migrator) migrateDBVersionToDB90() error {
|
||||
if err := m.updateUserThemForDB90(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return m.updateEdgeStackStatusForDB90()
|
||||
}
|
||||
|
||||
func (m *Migrator) updateEdgeStackStatusForDB81() error {
|
||||
func (m *Migrator) updateEdgeStackStatusForDB90() error {
|
||||
log.Info().Msg("clean up deleted endpoints from edge jobs")
|
||||
|
||||
edgeJobs, err := m.edgeJobService.EdgeJobs()
|
||||
|
@ -34,3 +38,25 @@ func (m *Migrator) updateEdgeStackStatusForDB81() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Migrator) updateUserThemForDB90() error {
|
||||
log.Info().Msg("updating existing user theme settings")
|
||||
|
||||
users, err := m.userService.Users()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range users {
|
||||
user := &users[i]
|
||||
if user.UserTheme != "" {
|
||||
user.ThemeSettings.Color = user.UserTheme
|
||||
}
|
||||
|
||||
if err := m.userService.UpdateUser(user.ID, user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -209,7 +209,7 @@ func (m *Migrator) initMigrations() {
|
|||
m.addMigrations("2.16", m.migrateDBVersionToDB70)
|
||||
m.addMigrations("2.16.1", m.migrateDBVersionToDB71)
|
||||
m.addMigrations("2.17", m.migrateDBVersionToDB80)
|
||||
m.addMigrations("2.18", m.migrateDBVersionToDB81)
|
||||
m.addMigrations("2.18", m.migrateDBVersionToDB90)
|
||||
|
||||
// Add new migrations below...
|
||||
// One function per migration, each versions migration funcs in the same file.
|
||||
|
|
|
@ -902,6 +902,10 @@
|
|||
"PortainerUserRevokeToken": true
|
||||
},
|
||||
"Role": 1,
|
||||
"ThemeSettings": {
|
||||
"color": "",
|
||||
"subtleUpgradeButton": false
|
||||
},
|
||||
"TokenIssueAt": 0,
|
||||
"UserTheme": "",
|
||||
"Username": "admin"
|
||||
|
@ -929,6 +933,10 @@
|
|||
"PortainerUserRevokeToken": true
|
||||
},
|
||||
"Role": 1,
|
||||
"ThemeSettings": {
|
||||
"color": "",
|
||||
"subtleUpgradeButton": false
|
||||
},
|
||||
"TokenIssueAt": 0,
|
||||
"UserTheme": "",
|
||||
"Username": "prabhat"
|
||||
|
|
|
@ -15,10 +15,18 @@ import (
|
|||
"github.com/asaskevich/govalidator"
|
||||
)
|
||||
|
||||
type themePayload struct {
|
||||
// Color represents the color theme of the UI
|
||||
Color *string `json:"color" example:"dark" enums:"dark,light,highcontrast,auto"`
|
||||
// SubtleUpgradeButton indicates if the upgrade banner should be displayed in a subtle way
|
||||
SubtleUpgradeButton *bool `json:"subtleUpgradeButton" example:"false"`
|
||||
}
|
||||
|
||||
type userUpdatePayload struct {
|
||||
Username string `validate:"required" example:"bob"`
|
||||
Password string `validate:"required" example:"cg9Wgky3"`
|
||||
UserTheme string `example:"dark"`
|
||||
Username string `validate:"required" example:"bob"`
|
||||
Password string `validate:"required" example:"cg9Wgky3"`
|
||||
Theme *themePayload
|
||||
|
||||
// User role (1 for administrator account and 2 for regular account)
|
||||
Role int `validate:"required" enums:"1,2" example:"2"`
|
||||
}
|
||||
|
@ -108,8 +116,14 @@ func (handler *Handler) userUpdate(w http.ResponseWriter, r *http.Request) *http
|
|||
user.TokenIssueAt = time.Now().Unix()
|
||||
}
|
||||
|
||||
if payload.UserTheme != "" {
|
||||
user.UserTheme = payload.UserTheme
|
||||
if payload.Theme != nil {
|
||||
if payload.Theme.Color != nil {
|
||||
user.ThemeSettings.Color = *payload.Theme.Color
|
||||
}
|
||||
|
||||
if payload.Theme.SubtleUpgradeButton != nil {
|
||||
user.ThemeSettings.SubtleUpgradeButton = *payload.Theme.SubtleUpgradeButton
|
||||
}
|
||||
}
|
||||
|
||||
if payload.Role != 0 {
|
||||
|
|
|
@ -1235,16 +1235,19 @@ type (
|
|||
ID UserID `json:"Id" example:"1"`
|
||||
Username string `json:"Username" example:"bob"`
|
||||
Password string `json:"Password,omitempty" swaggerignore:"true"`
|
||||
// User Theme
|
||||
UserTheme string `example:"dark"`
|
||||
// User role (1 for administrator account and 2 for regular account)
|
||||
Role UserRole `json:"Role" example:"1"`
|
||||
TokenIssueAt int64 `json:"TokenIssueAt" example:"1"`
|
||||
Role UserRole `json:"Role" example:"1"`
|
||||
TokenIssueAt int64 `json:"TokenIssueAt" example:"1"`
|
||||
ThemeSettings UserThemeSettings
|
||||
|
||||
// Deprecated fields
|
||||
|
||||
// Deprecated
|
||||
UserTheme string `example:"dark"`
|
||||
// Deprecated in DBVersion == 25
|
||||
PortainerAuthorizations Authorizations `json:"PortainerAuthorizations"`
|
||||
EndpointAuthorizations EndpointAuthorizations `json:"EndpointAuthorizations"`
|
||||
PortainerAuthorizations Authorizations
|
||||
// Deprecated in DBVersion == 25
|
||||
EndpointAuthorizations EndpointAuthorizations
|
||||
}
|
||||
|
||||
// UserAccessPolicies represent the association of an access policy and a user
|
||||
|
@ -1263,6 +1266,14 @@ type (
|
|||
// or a regular user
|
||||
UserRole int
|
||||
|
||||
// UserThemeSettings represents the theme settings for a user
|
||||
UserThemeSettings struct {
|
||||
// Color represents the color theme of the UI
|
||||
Color string `json:"color" example:"dark" enums:"dark,light,highcontrast,auto"`
|
||||
// SubtleUpgradeButton indicates if the upgrade banner should be displayed in a subtle way
|
||||
SubtleUpgradeButton bool `json:"subtleUpgradeButton"`
|
||||
}
|
||||
|
||||
// Webhook represents a url webhook that can be used to update a service
|
||||
Webhook struct {
|
||||
// Webhook Identifier
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue