feat: user migration
This commit is contained in:
@@ -19,6 +19,7 @@ type UserFlavorType string
|
||||
|
||||
const (
|
||||
UserFlavorAll UserFlavorType = "all"
|
||||
UserFlavorFlink UserFlavorType = "flink"
|
||||
UserFlavorFull UserFlavorType = "full"
|
||||
UserFlavorLight UserFlavorType = "light"
|
||||
UserFlavorHeartRate UserFlavorType = "heartrate"
|
||||
@@ -87,6 +88,9 @@ func (u *User) SupportsFlavor(flavor string) bool {
|
||||
if u.FlavorType == UserFlavorAll {
|
||||
return true
|
||||
}
|
||||
if u.FlavorType == UserFlavorFlink {
|
||||
return flavor == string(UserFlavorFlink) || flavor == string(UserFlavorFull) || flavor == string(UserFlavorLight)
|
||||
}
|
||||
return string(u.FlavorType) == flavor
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package models
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
func BackfillLegacyUserPermissions(db *gorm.DB) error {
|
||||
if err := db.Model(&User{}).
|
||||
Where("role IS NULL OR role = '' OR role = ?", UserRoleViewer).
|
||||
Update("role", UserRoleOperator).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := db.Model(&User{}).
|
||||
Where("flavor_type IS NULL OR flavor_type = '' OR flavor_type = ?", UserFlavorAll).
|
||||
Update("flavor_type", UserFlavorFlink).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := db.Model(&User{}).
|
||||
Where("is_active IS NULL").
|
||||
Update("is_active", true).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user