1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-29 12:30:11 +00:00

Compare commits

..

No commits in common. "9bd7fca95ed4401252474665e9048c8724c2286f" and "903a61d0f2866ba2e024364662c41c7d97e27459" have entirely different histories.

7 changed files with 25 additions and 93 deletions

51
api.go
View File

@ -271,9 +271,8 @@ func (app *appContext) NewUser(gc *gin.Context) {
respond(401, "Unknown error", gc)
return
}
app.storage.loadProfiles()
invite := app.storage.invites[req.Code]
app.checkInvite(req.Code, true, req.Username)
invite := app.storage.invites[req.Code]
if app.config.Section("notifications").Key("enabled").MustBool(false) {
for address, settings := range invite.Notify {
if settings["notify-creation"] {
@ -297,7 +296,6 @@ func (app *appContext) NewUser(gc *gin.Context) {
id = user["Id"].(string)
}
if invite.Profile != "" {
app.debug.Printf("Applying settings from profile \"%s\"", invite.Profile)
profile, ok := app.storage.profiles[invite.Profile]
if !ok {
profile = app.storage.profiles["Default"]
@ -474,9 +472,7 @@ func (app *appContext) SetProfile(gc *gin.Context) {
func (app *appContext) GetProfiles(gc *gin.Context) {
app.storage.loadProfiles()
app.debug.Println("Profiles requested")
out := map[string]interface{}{
"default_profile": app.storage.defaultProfile,
}
out := map[string]map[string]interface{}{}
for name, p := range app.storage.profiles {
out[name] = map[string]interface{}{
"admin": p.Admin,
@ -488,27 +484,6 @@ func (app *appContext) GetProfiles(gc *gin.Context) {
gc.JSON(200, out)
}
func (app *appContext) SetDefaultProfile(gc *gin.Context) {
req := map[string]string{}
gc.BindJSON(&req)
app.info.Printf("Setting default profile to \"%s\"", req["name"])
if _, ok := app.storage.profiles[req["name"]]; !ok {
app.err.Printf("Profile not found: \"%s\"", req["name"])
respond(500, "Profile not found", gc)
return
}
for name, profile := range app.storage.profiles {
if name == req["name"] {
profile.Admin = true
app.storage.profiles[name] = profile
} else {
profile.Admin = false
}
}
app.storage.defaultProfile = req["name"]
gc.JSON(200, map[string]bool{"success": true})
}
type newProfileReq struct {
Name string `json:"name"`
ID string `json:"id"`
@ -609,17 +584,10 @@ func (app *appContext) GetInvites(gc *gin.Context) {
invites = append(invites, invite)
}
profiles := make([]string, len(app.storage.profiles))
if len(app.storage.profiles) != 0 {
profiles[0] = app.storage.defaultProfile
i := 1
if len(app.storage.profiles) > 1 {
for p := range app.storage.profiles {
if p != app.storage.defaultProfile {
profiles[i] = p
i++
}
}
}
i := 0
for p := range app.storage.profiles {
profiles[i] = p
i++
}
resp := map[string]interface{}{
"profiles": profiles,
@ -982,11 +950,8 @@ func (app *appContext) ModifyConfig(gc *gin.Context) {
gc.BindJSON(&req)
tempConfig, _ := ini.Load(app.config_path)
for section, settings := range req {
if section != "restart-program" {
_, err := tempConfig.GetSection(section)
if err != nil {
tempConfig.NewSection(section)
}
_, err := tempConfig.GetSection(section)
if section != "restart-program" && err == nil {
for setting, value := range settings.(map[string]interface{}) {
tempConfig.Section(section).Key(setting).SetValue(value.(string))
}

View File

@ -177,7 +177,7 @@
"bs5": {
"name": "Use Bootstrap 5",
"required": false,
"requires_restart": true,
"requires_restart": false,
"type": "bool",
"value": false,
"description": "Use Bootstrap 5 (currently in alpha). This also removes the need for jQuery, so the page should load faster."
@ -608,7 +608,7 @@
"requires_restart": true,
"type": "text",
"value": "",
"description": "Deprecated. Location of stored user policy template (json)."
"description": "Location of stored user policy template (json)."
},
"user_configuration": {
"name": "userConfiguration",
@ -616,7 +616,7 @@
"requires_restart": true,
"type": "text",
"value": "",
"description": "Deprecated. Location of stored user configuration template (used for setting homescreen layout) (json)"
"description": "Location of stored user configuration template (used for setting homescreen layout) (json)"
},
"user_displayprefs": {
"name": "displayPreferences",
@ -624,7 +624,7 @@
"requires_restart": true,
"type": "text",
"value": "",
"description": "Deprecated. Location of stored displayPreferences template (also used for homescreen layout) (json)"
"description": "Location of stored displayPreferences template (also used for homescreen layout) (json)"
},
"user_profiles": {
"name": "User Profiles",
@ -632,7 +632,7 @@
"requires_restart": true,
"type": "text",
"value": "",
"description": "Location of stored user profiles (encompasses template and configuration and displayprefs) (json)"
"description": "Location of stored user profiles (encompasses template and homescreen) (json)"
},
"custom_css": {
"name": "Custom CSS",

View File

@ -216,7 +216,7 @@
"bs5": {
"name": "Use Bootstrap 5",
"required": false,
"requires_restart": true,
"requires_restart": false,
"type": "bool",
"value": false,
"description": "Use Bootstrap 5 (currently in alpha). This also removes the need for jQuery, so the page should load faster."
@ -678,7 +678,6 @@
"user_template",
"user_configuration",
"user_displayprefs",
"user_profiles",
"custom_css"
],
"meta": {
@ -715,7 +714,7 @@
"requires_restart": true,
"type": "text",
"value": "",
"description": "Deprecated. Location of stored user policy template (json)."
"description": "Location of stored user policy template (json)."
},
"user_configuration": {
"name": "userConfiguration",
@ -723,7 +722,7 @@
"requires_restart": true,
"type": "text",
"value": "",
"description": "Deprecated. Location of stored user configuration template (used for setting homescreen layout) (json)"
"description": "Location of stored user configuration template (used for setting homescreen layout) (json)"
},
"user_displayprefs": {
"name": "displayPreferences",
@ -731,15 +730,7 @@
"requires_restart": true,
"type": "text",
"value": "",
"description": "Deprecated. Location of stored displayPreferences template (also used for homescreen layout) (json)"
},
"user_profiles": {
"name": "User Profiles",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"description": "Location of stored user profiles (encompasses template and configuration and displayprefs) (json)"
"description": "Location of stored displayPreferences template (also used for homescreen layout) (json)"
},
"custom_css": {
"name": "Custom CSS",

View File

@ -437,11 +437,10 @@
<div id="profiles" class="unfocused">
<div class="card card-body">
<p>Profiles are applied to users when they create an account. They include things like access rights and homescreen layout. You can create them here.</p>
<table class="table table-sm table-striped table-borderless">
<table class="table table-striped table-borderless">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Default</th>
<th scope="col">From</th>
<th scope="col">Admin?</th>
<th scope="col">Libraries</th>

View File

@ -460,7 +460,6 @@ func start(asDaemon, firstCall bool) {
api.GET("/getInvites", app.GetInvites)
api.GET("/getProfiles", app.GetProfiles)
api.POST("/setProfile", app.SetProfile)
api.POST("/setDefaultProfile", app.SetDefaultProfile)
api.POST("/createProfile", app.CreateProfile)
api.POST("/deleteProfile", app.DeleteProfile)
api.POST("/setNotify", app.SetNotify)

View File

@ -12,7 +12,6 @@ type Storage struct {
invite_path, emails_path, policy_path, configuration_path, displayprefs_path, ombi_path, profiles_path string
invites Invites
profiles map[string]Profile
defaultProfile string
emails, policy, configuration, displayprefs, ombi_template map[string]interface{}
}
@ -25,7 +24,6 @@ type Profile struct {
Policy map[string]interface{} `json:"policy,omitempty"`
Configuration map[string]interface{} `json:"configuration,omitempty"`
Displayprefs map[string]interface{} `json:"displayprefs,omitempty"`
Default bool `json:"default,omitempty"`
}
type Invite struct {
@ -92,9 +90,6 @@ func (st *Storage) storeOmbiTemplate() error {
func (st *Storage) loadProfiles() error {
err := loadJSON(st.profiles_path, &st.profiles)
for name, profile := range st.profiles {
if profile.Default {
st.defaultProfile = name
}
change := false
if profile.Policy["IsAdministrator"] != nil {
profile.Admin = profile.Policy["IsAdministrator"].(bool)
@ -117,10 +112,8 @@ func (st *Storage) loadProfiles() error {
st.profiles[name] = profile
}
}
if st.defaultProfile == "" {
for n := range st.profiles {
st.defaultProfile = n
}
if err != nil {
panic(err)
}
return err
}

View File

@ -143,12 +143,10 @@ const populateProfiles = (noTable?: boolean): void => _get("/getProfiles", null,
if (this.readyState == 4 && this.status == 200) {
const profileList = document.getElementById('profileList');
profileList.textContent = '';
availableProfiles = [this.response["default_profile"]];
availableProfiles = [];
for (let name in this.response) {
if (name != availableProfiles[0]) {
availableProfiles.push(name);
}
if (!noTable && name != "default_profile") {
availableProfiles.push(name);
if (!noTable) {
const profile: Profile = {
Admin: this.response[name]["admin"],
LibraryAccess: this.response[name]["libraries"],
@ -156,28 +154,16 @@ const populateProfiles = (noTable?: boolean): void => _get("/getProfiles", null,
};
profileList.innerHTML += `
<td nowrap="nowrap" class="align-middle"><strong>${name}</strong></td>
<td nowrap="nowrap" class="align-middle"><input class="${(bsVersion == 5) ? "form-check-input" : ""}" type="radio" name="defaultProfile" onclick="setDefaultProfile('${name}')" ${(name == availableProfiles[0]) ? "checked" : ""}></td>
<td nowrap="nowrap" class="align-middle">${profile.FromUser}</td>
<td nowrap="nowrap" class="align-middle">${profile.Admin ? "Yes" : "No"}</td>
<td nowrap="nowrap" class="align-middle">${profile.LibraryAccess}</td>
<td nowrap="nowrap" class="align-middle"><button class="btn btn-outline-danger" id="defaultProfile_${name}" onclick="deleteProfile('${name}')">Delete</button></td>
<td nowrap="nowrap" class="align-middle"><button class="btn btn-outline-danger" onclick="deleteProfile('${name}')">Delete</button></td>
`;
}
}
}
});
const setDefaultProfile = (name: string): void => _post("/setDefaultProfile", { "name": name }, function (): void {
if (this.readyState == 4) {
if (this.status != 200) {
(document.getElementById(`defaultProfile_${availableProfiles[0]}`) as HTMLInputElement).checked = true;
(document.getElementById(`defaultProfile_${name}`) as HTMLInputElement).checked = false;
} else {
generateInvites();
}
}
});
const deleteProfile = (name: string): void => _post("/deleteProfile", { "name": name }, function (): void {
if (this.readyState == 4 && this.status == 200) {
populateProfiles();
@ -238,11 +224,10 @@ function storeProfile(): void {
addAttr(button, "btn-primary");
rmAttr(button, "btn-success");
button.disabled = false;
populateProfiles();
userDefaultsModal.hide();
}, 1000);
populateProfiles();
generateInvites();
} else {
if ("error" in this.response) {
button.textContent = this.response["error"];