mirror of
https://github.com/aunefyren/wrapperr
synced 2025-01-22 14:05:00 +00:00
Tautulli users from every server
This commit is contained in:
parent
adcea09ff7
commit
2ec6d68c86
5 changed files with 57 additions and 33 deletions
|
@ -115,6 +115,11 @@ type TautulliUser struct {
|
|||
FilterPhotos interface{} `json:"filter_photos"`
|
||||
}
|
||||
|
||||
type TautulliUserGroup struct {
|
||||
TautulliUser TautulliUser `json:"tautulli_user"`
|
||||
TautulliServer string `json:"tautulli_server"`
|
||||
}
|
||||
|
||||
type TautulliStatusReply struct {
|
||||
Response struct {
|
||||
Result string `json:"result"`
|
||||
|
|
|
@ -3,12 +3,13 @@ package models
|
|||
import "time"
|
||||
|
||||
type WrapperrUser struct {
|
||||
FriendlyName string `json:"user_friendly_name"`
|
||||
User string `json:"user_name"`
|
||||
UserID int `json:"user_id"`
|
||||
Email string `json:"user_email"`
|
||||
Active bool `json:"user_active"`
|
||||
Wrappings []WrapperrHistoryEntry `json:"wrappings"`
|
||||
FriendlyName string `json:"user_friendly_name"`
|
||||
User string `json:"user_name"`
|
||||
UserID int `json:"user_id"`
|
||||
Email string `json:"user_email"`
|
||||
Active bool `json:"user_active"`
|
||||
TautulliServers []string `json:"user_tautulli_servers"`
|
||||
Wrappings []WrapperrHistoryEntry `json:"wrappings"`
|
||||
}
|
||||
|
||||
type WrapperrHistoryEntry struct {
|
||||
|
|
|
@ -224,9 +224,9 @@ func TautulliTestEveryServer() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func TautulliGetUsersFromEveryServer() (tautulliUsers []models.TautulliUser, err error) {
|
||||
func TautulliGetUsersFromEveryServer() (tautulliUsers []models.TautulliUserGroup, err error) {
|
||||
err = nil
|
||||
tautulliUsers = []models.TautulliUser{}
|
||||
tautulliUsers = []models.TautulliUserGroup{}
|
||||
|
||||
config, err := files.GetConfig()
|
||||
if err != nil {
|
||||
|
@ -243,7 +243,11 @@ func TautulliGetUsersFromEveryServer() (tautulliUsers []models.TautulliUser, err
|
|||
}
|
||||
|
||||
for _, user := range tautulliReply.Response.Data {
|
||||
tautulliUsers = append(tautulliUsers, user)
|
||||
tautulliUserGroup := models.TautulliUserGroup{
|
||||
TautulliUser: user,
|
||||
TautulliServer: config.TautulliConfig[i].TautulliName,
|
||||
}
|
||||
tautulliUsers = append(tautulliUsers, tautulliUserGroup)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,17 +59,8 @@ func UsersGetUser(userID int) (user models.WrapperrUser, err error) {
|
|||
return user, errors.New("User not found.")
|
||||
}
|
||||
|
||||
func UsersUpdateUser(userID int, FriendlyName string, userName string, Email string, ActiveInt int) (err error) {
|
||||
func UsersUpdateUser(userID int, FriendlyName string, userName string, Email string, Active bool, TautulliServers []string) (err error) {
|
||||
err = nil
|
||||
Active := false
|
||||
|
||||
if ActiveInt == 1 {
|
||||
Active = true
|
||||
} else if ActiveInt == 0 {
|
||||
Active = false
|
||||
} else {
|
||||
return errors.New("Invalid active state found.")
|
||||
}
|
||||
|
||||
users, err := files.GetUsers()
|
||||
if err != nil {
|
||||
|
@ -94,6 +85,7 @@ func UsersUpdateUser(userID int, FriendlyName string, userName string, Email str
|
|||
users[userIndex].Email = Email
|
||||
users[userIndex].FriendlyName = FriendlyName
|
||||
users[userIndex].User = userName
|
||||
users[userIndex].TautulliServers = TautulliServers
|
||||
|
||||
err = files.SaveUsers(users)
|
||||
if err != nil {
|
||||
|
|
|
@ -441,13 +441,22 @@ func ApiSyncTautulliUsers(context *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
wrapperrUser, err := modules.UsersGetUser(user.UserID)
|
||||
if err != nil {
|
||||
newUserArray := []models.WrapperrUser{}
|
||||
for _, userGroup := range users {
|
||||
var userMatch bool = false
|
||||
var userIndex int = 0
|
||||
for index, wrapperrUser := range newUserArray {
|
||||
if userGroup.TautulliUser.UserID == wrapperrUser.UserID {
|
||||
userMatch = true
|
||||
userIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
if !userMatch {
|
||||
var Active = false
|
||||
if user.IsActive == 1 {
|
||||
if userGroup.TautulliUser.IsActive == 1 {
|
||||
Active = true
|
||||
} else if user.IsActive == 0 {
|
||||
} else if userGroup.TautulliUser.IsActive == 0 {
|
||||
Active = false
|
||||
} else {
|
||||
log.Println("Failed to convert integer to bool. Error: " + err.Error())
|
||||
|
@ -456,16 +465,29 @@ func ApiSyncTautulliUsers(context *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
wrapperrUser = models.WrapperrUser{
|
||||
FriendlyName: user.FriendlyName,
|
||||
User: user.Username,
|
||||
UserID: user.UserID,
|
||||
Email: user.Email,
|
||||
Active: Active,
|
||||
Wrappings: []models.WrapperrHistoryEntry{},
|
||||
wrapperrUser := models.WrapperrUser{
|
||||
FriendlyName: userGroup.TautulliUser.FriendlyName,
|
||||
User: userGroup.TautulliUser.Username,
|
||||
UserID: userGroup.TautulliUser.UserID,
|
||||
Email: userGroup.TautulliUser.Email,
|
||||
TautulliServers: []string{userGroup.TautulliServer},
|
||||
Active: Active,
|
||||
Wrappings: []models.WrapperrHistoryEntry{},
|
||||
}
|
||||
|
||||
err = modules.UsersSaveUserEntry(wrapperrUser)
|
||||
newUserArray = append(newUserArray, wrapperrUser)
|
||||
} else {
|
||||
if !newUserArray[userIndex].Active && userGroup.TautulliUser.IsActive == 1 {
|
||||
newUserArray[userIndex].Active = true
|
||||
}
|
||||
newUserArray[userIndex].TautulliServers = append(newUserArray[userIndex].TautulliServers, userGroup.TautulliServer)
|
||||
}
|
||||
}
|
||||
|
||||
for _, user := range newUserArray {
|
||||
_, err := modules.UsersGetUser(user.UserID)
|
||||
if err != nil {
|
||||
err = modules.UsersSaveUserEntry(user)
|
||||
if err != nil {
|
||||
log.Println("Failed to save new user. Error: " + err.Error())
|
||||
context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save new user."})
|
||||
|
@ -473,7 +495,7 @@ func ApiSyncTautulliUsers(context *gin.Context) {
|
|||
return
|
||||
}
|
||||
} else {
|
||||
err = modules.UsersUpdateUser(user.UserID, user.FriendlyName, user.Username, user.Email, user.IsActive)
|
||||
err = modules.UsersUpdateUser(user.UserID, user.FriendlyName, user.User, user.Email, user.Active, user.TautulliServers)
|
||||
if err != nil {
|
||||
log.Println("Failed to update user. Error: " + err.Error())
|
||||
context.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update user."})
|
||||
|
|
Loading…
Reference in a new issue