mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 17:10:10 +00:00
delete ombi user when deleting jf user
also fix ombi defaults menu in ui. responds to #11.
This commit is contained in:
parent
8089187b3e
commit
a89dc40ff2
39
api.go
39
api.go
@ -385,10 +385,47 @@ func (app *appContext) DeleteUser(gc *gin.Context) {
|
||||
var req deleteUserDTO
|
||||
gc.BindJSON(&req)
|
||||
errors := map[string]string{}
|
||||
ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false)
|
||||
ombiUsers := []map[string]interface{}{}
|
||||
var code int
|
||||
var err error
|
||||
if ombiEnabled {
|
||||
ombiUsers, code, err = app.ombi.getUsers()
|
||||
if code != 200 || err != nil {
|
||||
respond(500, fmt.Sprintf("Couldn't get users: %s (%s)", code, err), gc)
|
||||
return
|
||||
}
|
||||
}
|
||||
for _, userID := range req.Users {
|
||||
if ombiEnabled {
|
||||
ombiID := ""
|
||||
user, status, err := app.jf.userById(userID, false)
|
||||
if err == nil && status == 200 {
|
||||
username := user["Name"].(string)
|
||||
email := app.storage.emails[userID].(string)
|
||||
for _, ombiUser := range ombiUsers {
|
||||
if ombiUser["userName"].(string) == username || (ombiUser["emailAddress"].(string) == email && email != "") {
|
||||
ombiID = ombiUser["id"].(string)
|
||||
break
|
||||
}
|
||||
}
|
||||
if ombiID != "" {
|
||||
status, err := app.ombi.deleteUser(ombiID)
|
||||
if err != nil || status != 200 {
|
||||
app.err.Printf("Failed to delete ombi user: %d %s", status, err)
|
||||
errors[userID] = fmt.Sprintf("Ombi: %d %s, ", status, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
status, err := app.jf.deleteUser(userID)
|
||||
if !(status == 200 || status == 204) || err != nil {
|
||||
errors[userID] = fmt.Sprintf("%d: %s", status, err)
|
||||
msg := fmt.Sprintf("%d: %s", status, err)
|
||||
if _, ok := errors[userID]; !ok {
|
||||
errors[userID] = msg
|
||||
} else {
|
||||
errors[userID] += msg
|
||||
}
|
||||
}
|
||||
if req.Notify {
|
||||
addr, ok := app.storage.emails[userID]
|
||||
|
@ -438,7 +438,7 @@
|
||||
User Profiles <i class="fa fa-user settingIcon"></i>
|
||||
</button>
|
||||
{{ if .ombiEnabled }}
|
||||
<button type="button" class="list-group-item list-group-item-action static" id="openOmbiDefaults">
|
||||
<button type="button" class="list-group-item list-group-item-action static" id="openOmbiDefaults" onclick="window.openOmbiDefaults()">
|
||||
Ombi User Defaults <i class="fa fa-chain-broken settingIcon"></i>
|
||||
</button>
|
||||
{{ end }}
|
||||
|
18
ombi.go
18
ombi.go
@ -33,7 +33,7 @@ func newOmbi(server, key string, noFail bool) *Ombi {
|
||||
}
|
||||
|
||||
// does a GET and returns the response as an io.reader.
|
||||
func (ombi *Ombi) _getReader(url string, params map[string]string) (string, int, error) {
|
||||
func (ombi *Ombi) _getJSON(url string, params map[string]string) (string, int, error) {
|
||||
if ombi.key == "" {
|
||||
return "", 401, fmt.Errorf("No API key provided")
|
||||
}
|
||||
@ -107,16 +107,28 @@ func (ombi *Ombi) _post(url string, data map[string]interface{}, response bool)
|
||||
return responseText, resp.StatusCode, nil
|
||||
}
|
||||
|
||||
func (ombi *Ombi) deleteUser(id string) (code int, err error) {
|
||||
url := fmt.Sprintf("%s/api/v1/Identity/%s", ombi.server, id)
|
||||
req, _ := http.NewRequest("DELETE", url, nil)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
for name, value := range ombi.header {
|
||||
req.Header.Add(name, value)
|
||||
}
|
||||
resp, err := ombi.httpClient.Do(req)
|
||||
defer timeoutHandler("Ombi", ombi.server, ombi.noFail)
|
||||
return resp.StatusCode, err
|
||||
}
|
||||
|
||||
// gets an ombi user by their ID.
|
||||
func (ombi *Ombi) userByID(id string) (result map[string]interface{}, code int, err error) {
|
||||
resp, code, err := ombi._getReader(fmt.Sprintf("%s/api/v1/Identity/User/%s", ombi.server, id), nil)
|
||||
resp, code, err := ombi._getJSON(fmt.Sprintf("%s/api/v1/Identity/User/%s", ombi.server, id), nil)
|
||||
json.Unmarshal([]byte(resp), &result)
|
||||
return
|
||||
}
|
||||
|
||||
// gets a list of all users.
|
||||
func (ombi *Ombi) getUsers() (result []map[string]interface{}, code int, err error) {
|
||||
resp, code, err := ombi._getReader(fmt.Sprintf("%s/api/v1/Identity/Users", ombi.server), nil)
|
||||
resp, code, err := ombi._getJSON(fmt.Sprintf("%s/api/v1/Identity/Users", ombi.server), nil)
|
||||
json.Unmarshal([]byte(resp), &result)
|
||||
return
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { _get, _post, _delete, rmAttr, addAttr } from "modules/common.js";
|
||||
import { _get, _post, _delete, rmAttr, addAttr } from "./modules/common.js";
|
||||
|
||||
const ombiDefaultsModal = window.BS.newModal('ombiDefaults');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user