Skip to content

Commit

Permalink
fix (admin): bug in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-kerjean committed Oct 9, 2023
1 parent ac0fdc7 commit 73d1a07
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion public/components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export function format(name) {
};

export function multicomplete(input, datalist) {
input = input.trim().replace(/,$/g, "");
input = (input || "").trim().replace(/,$/g, "");
const current = input.split(",").map((val) => val.trim()).filter((t) => !!t);
const diff = datalist.filter((x) => current.indexOf(x) === -1);
return diff.map((candidate) => input.length === 0 ? candidate : `${input}, ${candidate}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default async function(render) {
rxjs.first(),
rxjs.map((cfg) => ({
type: cfg?.middleware?.identity_provider?.type?.value,
params: JSON.parse(cfg?.middleware?.identity_provider?.params?.value),
params: JSON.parse(cfg?.middleware?.identity_provider?.params?.value || "{}"),
})),
)),
rxjs.concatMap(async ([availableSpecs, idpState = {}]) => {
Expand Down Expand Up @@ -175,7 +175,7 @@ export default async function(render) {
rxjs.map((e) => e.target.value),
),
)),
rxjs.map((value) => value.split(",").map((val) => val.trim()).filter((t) => !!t)),
rxjs.map((value) => value.split(",").map((val) => (val || "").trim()).filter((t) => !!t)),
rxjs.mergeMap((inputBackends) => getBackendEnabled().pipe(
rxjs.first(),
rxjs.map((enabledBackends) => inputBackends
Expand Down Expand Up @@ -206,7 +206,7 @@ export default async function(render) {
}),
rxjs.mergeMap((spec) => getAdminConfig().pipe(
rxjs.first(),
rxjs.map((cfg) => JSON.parse(cfg?.middleware?.attribute_mapping?.params?.value)),
rxjs.map((cfg) => JSON.parse(cfg?.middleware?.attribute_mapping?.params?.value || "{}")),
rxjs.map((cfg) => {
// transform the form state from legacy format (= an object struct which was replicating the spec object)
// to the new format which leverage the dom (= or the input name attribute to be precise) to store the entire schema
Expand Down
2 changes: 1 addition & 1 deletion public/pages/adminpage/ctrl_backend_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function getState() {
rxjs.map((config) => { // middleware
const authType = document
.querySelector(`[data-bind="authentication_middleware"] [is="box-item"].active`)
.getAttribute("data-label");
?.getAttribute("data-label");

const middleware = {
identity_provider: {},
Expand Down
20 changes: 12 additions & 8 deletions public/pages/adminpage/ctrl_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import bcrypt from "../../lib/vendor/bcrypt.js";
import { CSS } from "../../helpers/loader.js";
import modal from "../../components/modal.js";
import { get as getConfig } from "../../model/config.js";
import ctrlError from "../ctrl_error.js";

import { get as getAdminConfig, save as saveConfig } from "./model_config.js";
import ctrlError from "../ctrl_error.js";
import WithShell from "./decorator_sidemenu.js";
import { cssHideMenu } from "./animate.js";
import { formObjToJSON$ } from "./helper_form.js";
import { getDeps } from "./model_setup.js";
import { authenticate$ } from "./model_admin_session.js";

import "../../components/icon.js";

Expand Down Expand Up @@ -68,13 +69,16 @@ function componentStep1(render) {
preventDefault(),
rxjs.mapTo(["name", "loading"]), applyMutation(qs($page, "component-icon"), "setAttribute"),
rxjs.map(() => qs($page, "input").value),
rxjs.combineLatestWith(getAdminConfig().pipe(rxjs.first())),
rxjs.map(([pwd, config]) => {
config["auth"]["admin"]["value"] = bcrypt.hashSync(pwd);
return config;
}),
reshapeConfigBeforeSave,
saveConfig(),
rxjs.mergeMap((pwd) => getAdminConfig().pipe(
rxjs.first(),
rxjs.map((config) => {
config["auth"]["admin"]["value"] = bcrypt.hashSync(pwd);
return config;
}),
reshapeConfigBeforeSave,
saveConfig(),
rxjs.mergeMap(() => authenticate$({ password: pwd })),
)),
rxjs.tap(() => animate($page, { time: 200, keyframes: slideXOut(-30) })),
rxjs.delay(200),
rxjs.tap(() => stepper$.next(2))
Expand Down
9 changes: 4 additions & 5 deletions server/ctrl/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,11 @@ func LegacyServeFile(res http.ResponseWriter, req *http.Request, filePath string

func ServeBackofficeHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
url := req.URL.Path
if url != URL_SETUP && Config.Get("auth.admin").String() == "" {
http.Redirect(res, req, URL_SETUP, http.StatusTemporaryRedirect)
return
}

if filepath.Ext(filepath.Base(url)) == "" {
if url != URL_SETUP && Config.Get("auth.admin").String() == "" {
http.Redirect(res, req, URL_SETUP, http.StatusTemporaryRedirect)
return
}
ServeFile(res, req, WWWPublic, "index.backoffice.html")
return
}
Expand Down

0 comments on commit 73d1a07

Please sign in to comment.