ability to transfer vehicle and disable users
This commit is contained in:
@@ -17,6 +17,7 @@ type User struct {
|
||||
Role Role `json:"role"`
|
||||
Name string `json:"name"`
|
||||
Vehicles []Vehicle `gorm:"many2many:user_vehicles;" json:"vehicles"`
|
||||
IsDisabled bool `json:"isDisabled"`
|
||||
}
|
||||
|
||||
func (b *User) MarshalJSON() ([]byte, error) {
|
||||
|
||||
@@ -33,6 +33,11 @@ func FindOneUser(condition interface{}) (User, error) {
|
||||
err := DB.Where(condition).First(&model).Error
|
||||
return model, err
|
||||
}
|
||||
func SetDisabledStatusForUser(userId string, isDisabled bool) error {
|
||||
//Cannot do this for admin
|
||||
tx := DB.Debug().Model(&User{}).Where("id= ? and role=?", userId, USER).Update("is_disabled", isDisabled)
|
||||
return tx.Error
|
||||
}
|
||||
func GetAllUsers() (*[]User, error) {
|
||||
|
||||
sorting := "created_at desc"
|
||||
@@ -92,6 +97,16 @@ func ShareVehicle(vehicleId, userId string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func TransferVehicle(vehicleId, ownerId, newUserID string) error {
|
||||
|
||||
tx := DB.Model(&UserVehicle{}).Where("vehicle_id = ? AND user_id = ?", vehicleId, ownerId).Update("is_owner", false)
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
tx = DB.Model(&UserVehicle{}).Where("vehicle_id = ? AND user_id = ?", vehicleId, newUserID).Update("is_owner", true)
|
||||
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
func UnshareVehicle(vehicleId, userId string) error {
|
||||
var mapping UserVehicle
|
||||
|
||||
@@ -14,10 +14,10 @@ type localMigration struct {
|
||||
}
|
||||
|
||||
var migrations = []localMigration{
|
||||
// {
|
||||
// Name: "2020_11_03_04_42_SetDefaultDownloadStatus",
|
||||
// Query: "update podcast_items set download_status=2 where download_path!='' and download_status=0",
|
||||
// },
|
||||
{
|
||||
Name: "2021_06_24_04_42_SetUserDisabledFalse",
|
||||
Query: "update users set is_disabled=0",
|
||||
},
|
||||
}
|
||||
|
||||
func RunMigrations() {
|
||||
|
||||
Reference in New Issue
Block a user