From 2997384c726755894030745082599094efdaadb5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Jul 2022 04:17:31 +0000 Subject: [PATCH 01/12] Bump terser from 5.10.0 to 5.14.2 in /web/frontend Bumps [terser](https://github.com/terser/terser) from 5.10.0 to 5.14.2. - [Release notes](https://github.com/terser/terser/releases) - [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md) - [Commits](https://github.com/terser/terser/compare/v5.10.0...v5.14.2) --- updated-dependencies: - dependency-name: terser dependency-type: indirect ... Signed-off-by: dependabot[bot] --- web/frontend/yarn.lock | 59 +++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/web/frontend/yarn.lock b/web/frontend/yarn.lock index f80e078..50ad50e 100644 --- a/web/frontend/yarn.lock +++ b/web/frontend/yarn.lock @@ -28,6 +28,46 @@ resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.1.tgz#076d78ce99822258cf813ecc1e7fa460fa74d052" integrity sha512-NQ17ii0rK1b34VZonlmT2QMJFI70m0TRwbknO/ihlbatXyaktDhN/98vBiUU6kNBPljqGqyIrl2T4nY2RpFANg== +"@jridgewell/gen-mapping@^0.3.0": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz#c1aedc61e853f2bb9f5dfe6d4442d3b565b253b9" + integrity sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A== + dependencies: + "@jridgewell/set-array" "^1.0.1" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@jridgewell/trace-mapping" "^0.3.9" + +"@jridgewell/resolve-uri@^3.0.3": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" + integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== + +"@jridgewell/set-array@^1.0.1": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" + integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== + +"@jridgewell/source-map@^0.3.2": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.2.tgz#f45351aaed4527a298512ec72f81040c998580fb" + integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw== + dependencies: + "@jridgewell/gen-mapping" "^0.3.0" + "@jridgewell/trace-mapping" "^0.3.9" + +"@jridgewell/sourcemap-codec@^1.4.10": + version "1.4.14" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" + integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== + +"@jridgewell/trace-mapping@^0.3.9": + version "0.3.14" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.14.tgz#b231a081d8f66796e475ad588a1ef473112701ed" + integrity sha512-bJWEfQ9lPTvm3SneWwRFVLzrh6nhjwqw7TUFFBEMzwvg7t7PCDenf2lDwqo4NQXzdpgBXyFgDWnQA+2vkruksQ== + dependencies: + "@jridgewell/resolve-uri" "^3.0.3" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@popperjs/core@^2.9.2": version "2.11.0" resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.0.tgz#6734f8ebc106a0860dff7f92bf90df193f0935d7" @@ -121,6 +161,11 @@ "@urql/core" "^2.3.4" wonka "^4.0.14" +acorn@^8.5.0: + version "8.8.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8" + integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w== + ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" @@ -432,11 +477,6 @@ source-map@^0.6.0: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@~0.7.2: - version "0.7.3" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" - integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== - sourcemap-codec@^1.4.4: version "1.4.8" resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" @@ -469,12 +509,13 @@ sveltestrap@^5.6.1: "@popperjs/core" "^2.9.2" terser@^5.0.0: - version "5.10.0" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.10.0.tgz#b86390809c0389105eb0a0b62397563096ddafcc" - integrity sha512-AMmF99DMfEDiRJfxfY5jj5wNH/bYO09cniSqhfoyxc8sFoYIgkJy86G04UoZU5VjlpnplVu0K6Tx6E9b5+DlHA== + version "5.14.2" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.14.2.tgz#9ac9f22b06994d736174f4091aa368db896f1c10" + integrity sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA== dependencies: + "@jridgewell/source-map" "^0.3.2" + acorn "^8.5.0" commander "^2.20.0" - source-map "~0.7.2" source-map-support "~0.5.20" uplot@^1.6.7: From 2611000cb71f7c664a9023b053ac5d31faab3c2a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Jul 2022 04:32:33 +0000 Subject: [PATCH 02/12] Bump svelte from 3.44.2 to 3.49.0 in /web/frontend Bumps [svelte](https://github.com/sveltejs/svelte) from 3.44.2 to 3.49.0. - [Release notes](https://github.com/sveltejs/svelte/releases) - [Changelog](https://github.com/sveltejs/svelte/blob/master/CHANGELOG.md) - [Commits](https://github.com/sveltejs/svelte/compare/v3.44.2...v3.49.0) --- updated-dependencies: - dependency-name: svelte dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- web/frontend/package.json | 2 +- web/frontend/yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/web/frontend/package.json b/web/frontend/package.json index 2f2ab55..75d6111 100644 --- a/web/frontend/package.json +++ b/web/frontend/package.json @@ -12,7 +12,7 @@ "rollup-plugin-css-only": "^3.1.0", "rollup-plugin-svelte": "^7.0.0", "rollup-plugin-terser": "^7.0.0", - "svelte": "^3.42.6" + "svelte": "^3.49.0" }, "dependencies": { "@rollup/plugin-replace": "^2.4.1", diff --git a/web/frontend/yarn.lock b/web/frontend/yarn.lock index 50ad50e..7113711 100644 --- a/web/frontend/yarn.lock +++ b/web/frontend/yarn.lock @@ -496,10 +496,10 @@ supports-color@^7.0.0: dependencies: has-flag "^4.0.0" -svelte@^3.42.6: - version "3.44.2" - resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.44.2.tgz#3e69be2598308dfc8354ba584cec54e648a50f7f" - integrity sha512-jrZhZtmH3ZMweXg1Q15onb8QlWD+a5T5Oca4C1jYvSURp2oD35h4A5TV6t6MEa93K4LlX6BkafZPdQoFjw/ylA== +svelte@^3.49.0: + version "3.49.0" + resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.49.0.tgz#5baee3c672306de1070c3b7888fc2204e36a4029" + integrity sha512-+lmjic1pApJWDfPCpUUTc1m8azDqYCG1JN9YEngrx/hUyIcFJo6VZhj0A1Ai0wqoHcEIuQy+e9tk+4uDgdtsFA== sveltestrap@^5.6.1: version "5.6.3" From 84484babc10754ac94ecc5fd2600c82396303343 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 29 Jul 2022 06:46:07 +0200 Subject: [PATCH 03/12] Add license and set name --- web/frontend/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/frontend/package.json b/web/frontend/package.json index 75d6111..174fa5f 100644 --- a/web/frontend/package.json +++ b/web/frontend/package.json @@ -1,6 +1,7 @@ { - "name": "svelte-app", + "name": "cc-frontend", "version": "1.0.0", + "license": "MIT", "scripts": { "build": "rollup -c", "dev": "rollup -c -w" From a0dafbac9985049fa0b84ea751db34eed6140aa5 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 29 Jul 2022 10:41:21 +0200 Subject: [PATCH 04/12] Add copyright header to lruchache --- pkg/lrucache/README.md | 2 -- pkg/lrucache/cache.go | 4 ++++ pkg/lrucache/cache_test.go | 4 ++++ pkg/lrucache/handler.go | 4 ++++ pkg/lrucache/handler_test.go | 4 ++++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/lrucache/README.md b/pkg/lrucache/README.md index 8cd2751..a2b2f45 100644 --- a/pkg/lrucache/README.md +++ b/pkg/lrucache/README.md @@ -1,7 +1,5 @@ # In-Memory LRU Cache for Golang Applications -[![](https://pkg.go.dev/badge/github.com/iamlouk/lrucache?utm_source=godoc)](https://pkg.go.dev/github.com/iamlouk/lrucache) - This library can be embedded into your existing go applications and play the role *Memcached* or *Redis* might play for others. It is inspired by [PHP Symfony's Cache Components](https://symfony.com/doc/current/components/cache/adapters/array_cache_adapter.html), diff --git a/pkg/lrucache/cache.go b/pkg/lrucache/cache.go index aedfd5c..679bd2e 100644 --- a/pkg/lrucache/cache.go +++ b/pkg/lrucache/cache.go @@ -1,3 +1,7 @@ +// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. +// All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. package lrucache import ( diff --git a/pkg/lrucache/cache_test.go b/pkg/lrucache/cache_test.go index bfab653..7ba5504 100644 --- a/pkg/lrucache/cache_test.go +++ b/pkg/lrucache/cache_test.go @@ -1,3 +1,7 @@ +// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. +// All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. package lrucache import ( diff --git a/pkg/lrucache/handler.go b/pkg/lrucache/handler.go index e83ba10..db6687f 100644 --- a/pkg/lrucache/handler.go +++ b/pkg/lrucache/handler.go @@ -1,3 +1,7 @@ +// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. +// All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. package lrucache import ( diff --git a/pkg/lrucache/handler_test.go b/pkg/lrucache/handler_test.go index cb05f31..4013c63 100644 --- a/pkg/lrucache/handler_test.go +++ b/pkg/lrucache/handler_test.go @@ -1,3 +1,7 @@ +// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. +// All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. package lrucache import ( From 84bac7e52028e7bb2f9ca8efe2d6fcbb27b39f5d Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Tue, 23 Aug 2022 13:33:25 +0200 Subject: [PATCH 05/12] Add new role support. This enables designated users to see all jobs. --- cmd/cc-backend/main.go | 2 +- internal/auth/auth.go | 7 ++++--- internal/auth/users.go | 4 ++-- internal/graph/schema.resolvers.go | 2 +- internal/repository/job.go | 4 ++-- internal/repository/query.go | 2 +- internal/routerConfig/routes.go | 6 ++++-- web/templates/config.tmpl | 5 +++++ web/web.go | 1 + 9 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cmd/cc-backend/main.go b/cmd/cc-backend/main.go index 19c9830..b6a6280 100644 --- a/cmd/cc-backend/main.go +++ b/cmd/cc-backend/main.go @@ -142,7 +142,7 @@ func main() { flag.BoolVar(&flagStopImmediately, "no-server", false, "Do not start a server, stop right after initialization and argument handling") flag.BoolVar(&flagGops, "gops", false, "Listen via github.com/google/gops/agent (for debugging)") flag.StringVar(&flagConfigFile, "config", "./config.json", "Overwrite the global config options by those specified in `config.json`") - flag.StringVar(&flagNewUser, "add-user", "", "Add a new user. Argument format: `:[admin,api,user]:`") + flag.StringVar(&flagNewUser, "add-user", "", "Add a new user. Argument format: `:[admin,support,api,user]:`") flag.StringVar(&flagDelUser, "del-user", "", "Remove user by `username`") flag.StringVar(&flagGenJWT, "jwt", "", "Generate and print a JWT for the user specified by its `username`") flag.StringVar(&flagImportJob, "import-job", "", "Import a job. Argument format: `:,...`") diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 3f2c359..73c6917 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -19,9 +19,10 @@ import ( ) const ( - RoleAdmin string = "admin" - RoleApi string = "api" - RoleUser string = "user" + RoleAdmin string = "admin" + RoleSupport string = "support" + RoleApi string = "api" + RoleUser string = "user" ) const ( diff --git a/internal/auth/users.go b/internal/auth/users.go index 63f18c2..4d3a658 100644 --- a/internal/auth/users.go +++ b/internal/auth/users.go @@ -112,7 +112,7 @@ func (auth *Authentication) AddRole(ctx context.Context, username string, role s return err } - if role != RoleAdmin && role != RoleApi && role != RoleUser { + if role != RoleAdmin && role != RoleApi && role != RoleUser && role != RoleSupport { return fmt.Errorf("invalid user role: %#v", role) } @@ -131,7 +131,7 @@ func (auth *Authentication) AddRole(ctx context.Context, username string, role s func FetchUser(ctx context.Context, db *sqlx.DB, username string) (*model.User, error) { me := GetUser(ctx) - if me != nil && !me.HasRole(RoleAdmin) && me.Username != username { + if me != nil && !me.HasRole(RoleAdmin) && !me.HasRole(RoleSupport) && me.Username != username { return nil, errors.New("forbidden") } diff --git a/internal/graph/schema.resolvers.go b/internal/graph/schema.resolvers.go index 7fe30aa..b8b3bcb 100644 --- a/internal/graph/schema.resolvers.go +++ b/internal/graph/schema.resolvers.go @@ -142,7 +142,7 @@ func (r *queryResolver) Job(ctx context.Context, id string) (*schema.Job, error) return nil, err } - if user := auth.GetUser(ctx); user != nil && !user.HasRole(auth.RoleAdmin) && job.User != user.Username { + if user := auth.GetUser(ctx); user != nil && !user.HasRole(auth.RoleAdmin) && !user.HasRole(auth.RoleSupport) && job.User != user.Username { return nil, errors.New("you are not allowed to see this job") } diff --git a/internal/repository/job.go b/internal/repository/job.go index 6417efd..7a8ce8e 100644 --- a/internal/repository/job.go +++ b/internal/repository/job.go @@ -309,7 +309,7 @@ func (r *JobRepository) FindJobOrUser(ctx context.Context, searchterm string) (j user := auth.GetUser(ctx) if id, err := strconv.Atoi(searchterm); err == nil { qb := sq.Select("job.id").From("job").Where("job.job_id = ?", id) - if user != nil && !user.HasRole(auth.RoleAdmin) { + if user != nil && !user.HasRole(auth.RoleAdmin) && !user.HasRole(auth.RoleSupport) { qb = qb.Where("job.user = ?", user.Username) } @@ -321,7 +321,7 @@ func (r *JobRepository) FindJobOrUser(ctx context.Context, searchterm string) (j } } - if user == nil || user.HasRole(auth.RoleAdmin) { + if user == nil || user.HasRole(auth.RoleAdmin) || user.HasRole(auth.RoleSupport) { err := sq.Select("job.user").Distinct().From("job"). Where("job.user = ?", searchterm). RunWith(r.stmtCache).QueryRow().Scan(&username) diff --git a/internal/repository/query.go b/internal/repository/query.go index beed7bc..e207aed 100644 --- a/internal/repository/query.go +++ b/internal/repository/query.go @@ -94,7 +94,7 @@ func (r *JobRepository) CountJobs( func SecurityCheck(ctx context.Context, query sq.SelectBuilder) sq.SelectBuilder { user := auth.GetUser(ctx) - if user == nil || user.HasRole(auth.RoleAdmin) || user.HasRole(auth.RoleApi) { + if user == nil || user.HasRole(auth.RoleAdmin) || user.HasRole(auth.RoleApi) || user.HasRole(auth.RoleSupport) { return query } diff --git a/internal/routerConfig/routes.go b/internal/routerConfig/routes.go index ad3a103..dbd3d01 100644 --- a/internal/routerConfig/routes.go +++ b/internal/routerConfig/routes.go @@ -269,15 +269,17 @@ func SetupRoutes(router *mux.Router) { title = strings.Replace(route.Title, "", id.(string), 1) } - username, isAdmin := "", true + username, isAdmin, isSupporter := "", true, true + if user := auth.GetUser(r.Context()); user != nil { username = user.Username isAdmin = user.HasRole(auth.RoleAdmin) + isSupporter = user.HasRole(auth.RoleSupport) } page := web.Page{ Title: title, - User: web.User{Username: username, IsAdmin: isAdmin}, + User: web.User{Username: username, IsAdmin: isAdmin, IsSupporter: isSupporter}, Config: conf, Infos: infos, } diff --git a/web/templates/config.tmpl b/web/templates/config.tmpl index deccf92..bacf8b8 100644 --- a/web/templates/config.tmpl +++ b/web/templates/config.tmpl @@ -38,6 +38,10 @@ +
+ + +

@@ -131,6 +135,7 @@ + diff --git a/web/web.go b/web/web.go index 9d0ea6d..7435b9f 100644 --- a/web/web.go +++ b/web/web.go @@ -55,6 +55,7 @@ func init() { type User struct { Username string // Username of the currently logged in user IsAdmin bool + IsSupporter bool } type Page struct { From 7bfdc83779dd7b4da4326d01e89eb05d7576290e Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Fri, 26 Aug 2022 11:45:14 +0200 Subject: [PATCH 06/12] Initial commit on branch: Rewrite config.tmpl as svelte component(s) --- internal/routerConfig/routes.go | 1 + web/frontend/rollup.config.js | 4 +- web/frontend/src/Configsvelte.root.svelte | 31 ++++ web/frontend/src/config/AdminSettings.svelte | 36 ++++ web/frontend/src/config/PlotSettings.svelte | 170 ++++++++++++++++++ web/frontend/src/config/admin/AddRole.svelte | 70 ++++++++ web/frontend/src/config/admin/AddUser.svelte | 85 +++++++++ web/frontend/src/config/admin/Options.svelte | 29 +++ .../src/config/admin/ShowUsers.svelte | 67 +++++++ .../src/config/admin/ShowUsersRow.svelte | 27 +++ web/frontend/src/configsvelte.entrypoint.js | 12 ++ web/templates/config.tmpl | 4 +- web/templates/configsvelte.tmpl | 15 ++ 13 files changed, 547 insertions(+), 4 deletions(-) create mode 100644 web/frontend/src/Configsvelte.root.svelte create mode 100644 web/frontend/src/config/AdminSettings.svelte create mode 100644 web/frontend/src/config/PlotSettings.svelte create mode 100644 web/frontend/src/config/admin/AddRole.svelte create mode 100644 web/frontend/src/config/admin/AddUser.svelte create mode 100644 web/frontend/src/config/admin/Options.svelte create mode 100644 web/frontend/src/config/admin/ShowUsers.svelte create mode 100644 web/frontend/src/config/admin/ShowUsersRow.svelte create mode 100644 web/frontend/src/configsvelte.entrypoint.js create mode 100644 web/templates/configsvelte.tmpl diff --git a/internal/routerConfig/routes.go b/internal/routerConfig/routes.go index ad3a103..068709f 100644 --- a/internal/routerConfig/routes.go +++ b/internal/routerConfig/routes.go @@ -36,6 +36,7 @@ type Route struct { var routes []Route = []Route{ {"/", "home.tmpl", "ClusterCockpit", false, setupHomeRoute}, {"/config", "config.tmpl", "Settings", false, func(i InfoType, r *http.Request) InfoType { return i }}, + {"/configsvelte", "configsvelte.tmpl", "Settings as Svelte", false, func(i InfoType, r *http.Request) InfoType { return i }}, {"/monitoring/jobs/", "monitoring/jobs.tmpl", "Jobs - ClusterCockpit", true, func(i InfoType, r *http.Request) InfoType { return i }}, {"/monitoring/job/{id:[0-9]+}", "monitoring/job.tmpl", "Job - ClusterCockpit", false, setupJobRoute}, {"/monitoring/users/", "monitoring/list.tmpl", "Users - ClusterCockpit", true, func(i InfoType, r *http.Request) InfoType { i["listType"] = "USER"; return i }}, diff --git a/web/frontend/rollup.config.js b/web/frontend/rollup.config.js index 13d988a..199a157 100644 --- a/web/frontend/rollup.config.js +++ b/web/frontend/rollup.config.js @@ -65,6 +65,6 @@ export default [ entrypoint('systems', 'src/systems.entrypoint.js'), entrypoint('node', 'src/node.entrypoint.js'), entrypoint('analysis', 'src/analysis.entrypoint.js'), - entrypoint('status', 'src/status.entrypoint.js') + entrypoint('status', 'src/status.entrypoint.js'), + entrypoint('configsvelte', 'src/configsvelte.entrypoint.js') ]; - diff --git a/web/frontend/src/Configsvelte.root.svelte b/web/frontend/src/Configsvelte.root.svelte new file mode 100644 index 0000000..6b1eb40 --- /dev/null +++ b/web/frontend/src/Configsvelte.root.svelte @@ -0,0 +1,31 @@ + + +{#if user.IsAdmin} + + + Admin Options + + + +{/if} + + + + Plotting Options + + + diff --git a/web/frontend/src/config/AdminSettings.svelte b/web/frontend/src/config/AdminSettings.svelte new file mode 100644 index 0000000..3564865 --- /dev/null +++ b/web/frontend/src/config/AdminSettings.svelte @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/web/frontend/src/config/PlotSettings.svelte b/web/frontend/src/config/PlotSettings.svelte new file mode 100644 index 0000000..1b7542d --- /dev/null +++ b/web/frontend/src/config/PlotSettings.svelte @@ -0,0 +1,170 @@ + + + + + + +

handleSettingSubmit('#line-width-form', 'lw')}> + + +
Line Width
+ + {#if displayMessage && message.target == 'lw'} +
+ + Update: {message.msg} + +
+ {/if} +
+ +
+ + +
Width of the lines in the timeseries plots.
+
+ +
+ + + + +
handleSettingSubmit('#plots-per-row-form', 'ppr')}> + + +
Plots per Row
+ {#if displayMessage && message.target == 'ppr'}
Update: {message.msg}
{/if} +
+ +
+ + +
How many plots to show next to each other on pages such as /monitoring/job/, /monitoring/system/...
+
+ +
+
+ + + +
handleSettingSubmit('#backgrounds-form', 'bg')}> + + +
Colored Backgrounds
+ {#if displayMessage && message.target == 'bg'}
Update: {message.msg}
{/if} +
+ +
+
+ {#if config.plot_general_colorBackground} + + {:else} + + {/if} + +
+
+ {#if config.plot_general_colorBackground} + + {:else} + + {/if} + +
+
+ +
+
+ + + + + +
handleSettingSubmit("#colorscheme-form", "cs")}> + + +
Color Scheme for Timeseries Plots
+ {#if displayMessage && message.target == 'cs'}
Update: {message.msg}
{/if} +
+ + + + {#each Object.entries(colorschemes) as [name, rgbrow]} + + + + + + {/each} + +
{name} + {#if rgbrow.join(',') == config.plot_general_colorscheme} + + {:else} + + {/if} + + {#each rgbrow as rgb} + + {/each} +
+ +
+
+
+ + diff --git a/web/frontend/src/config/admin/AddRole.svelte b/web/frontend/src/config/admin/AddRole.svelte new file mode 100644 index 0000000..dcd4cef --- /dev/null +++ b/web/frontend/src/config/admin/AddRole.svelte @@ -0,0 +1,70 @@ + + + + + Add Role to User +
+ + + + + +
+

+ {#if displayMessage}Update: {message.msg}{/if} +

+
+
diff --git a/web/frontend/src/config/admin/AddUser.svelte b/web/frontend/src/config/admin/AddUser.svelte new file mode 100644 index 0000000..bca89f0 --- /dev/null +++ b/web/frontend/src/config/admin/AddUser.svelte @@ -0,0 +1,85 @@ + + + +
+ Create User +
+ + +
Optional, can be blank.
+
+
+ + +
Optional, can be blank.
+
+
+ + +
Must be unique.
+
+
+ + +
Only API users are allowed to have a blank password. Users with a blank password can only authenticate via Tokens.
+
+
+

Role:

+
+ + +
+
+ + +
+
+ + +
+
+

+ + {#if displayMessage}

{message.msg}
{/if} +

+
+
diff --git a/web/frontend/src/config/admin/Options.svelte b/web/frontend/src/config/admin/Options.svelte new file mode 100644 index 0000000..44f9650 --- /dev/null +++ b/web/frontend/src/config/admin/Options.svelte @@ -0,0 +1,29 @@ + + + + + Scramble Names / Presentation Mode + + Active? + + diff --git a/web/frontend/src/config/admin/ShowUsers.svelte b/web/frontend/src/config/admin/ShowUsers.svelte new file mode 100644 index 0000000..5726fc4 --- /dev/null +++ b/web/frontend/src/config/admin/ShowUsers.svelte @@ -0,0 +1,67 @@ + + + + + Special Users +

+ Not created by an LDAP sync and/or having a role other than user + +

+
+ + + + + + + + + + + + + {#each userList as user} + + + + + {:else} + + + + {/each} + +
UsernameNameEmailRolesJWTDelete
+
Loading...
+
+
+
+
diff --git a/web/frontend/src/config/admin/ShowUsersRow.svelte b/web/frontend/src/config/admin/ShowUsersRow.svelte new file mode 100644 index 0000000..64b5dd4 --- /dev/null +++ b/web/frontend/src/config/admin/ShowUsersRow.svelte @@ -0,0 +1,27 @@ + + +{user.username} +{user.name} +{user.email} +{user.roles.join(', ')} + + {#if ! jwt} + + {:else} + + {/if} + diff --git a/web/frontend/src/configsvelte.entrypoint.js b/web/frontend/src/configsvelte.entrypoint.js new file mode 100644 index 0000000..43e3434 --- /dev/null +++ b/web/frontend/src/configsvelte.entrypoint.js @@ -0,0 +1,12 @@ +import {} from './header.entrypoint.js' +import Configsvelte from './Configsvelte.root.svelte' + +new Configsvelte({ + target: document.getElementById('svelte-app'), + props: { + user: user + }, + context: new Map([ + ['cc-config', clusterCockpitConfig] + ]) +}) diff --git a/web/templates/config.tmpl b/web/templates/config.tmpl index deccf92..b8a3027 100644 --- a/web/templates/config.tmpl +++ b/web/templates/config.tmpl @@ -247,7 +247,7 @@ 'BlueWaves': ['rgb(83,0,215)','rgb(43,6,108)','rgb(9,16,16)','rgb(8,32,25)','rgb(0,50,8)','rgb(27,64,66)','rgb(69,67,178)','rgb(115,62,210)','rgb(155,50,104)','rgb(178,43,41)','rgb(180,51,34)','rgb(161,78,87)','rgb(124,117,187)','rgb(78,155,203)','rgb(34,178,85)','rgb(4,176,2)','rgb(9,152,27)','rgb(4,118,2)','rgb(34,92,85)','rgb(78,92,203)','rgb(124,127,187)','rgb(161,187,87)','rgb(180,248,34)','rgb(178,220,41)','rgb(155,217,104)','rgb(115,254,210)'], 'BlueGreenRedYellow': ['rgb(0,0,0)','rgb(0,0,20)','rgb(0,0,41)','rgb(0,0,62)','rgb(0,25,83)','rgb(0,57,101)','rgb(0,87,101)','rgb(0,118,101)','rgb(0,150,101)','rgb(0,150,69)','rgb(0,148,37)','rgb(0,141,6)','rgb(60,120,0)','rgb(131,87,0)','rgb(180,25,0)','rgb(203,13,0)','rgb(208,36,0)','rgb(213,60,0)','rgb(219,83,0)','rgb(224,106,0)','rgb(229,129,0)','rgb(233,152,0)','rgb(238,176,0)','rgb(243,199,0)','rgb(248,222,0)','rgb(254,245,0)'] }; - + for (const name in colorschemes) { const colorscheme = colorschemes[name] const json = JSON.stringify(colorscheme) @@ -292,4 +292,4 @@ handleSubmit('#backgrounds-form') handleSubmit('#colorscheme-form') -{{end}} \ No newline at end of file +{{end}} diff --git a/web/templates/configsvelte.tmpl b/web/templates/configsvelte.tmpl new file mode 100644 index 0000000..ab188b1 --- /dev/null +++ b/web/templates/configsvelte.tmpl @@ -0,0 +1,15 @@ +{{define "content"}} +
+{{end}} + +{{define "stylesheets"}} + +{{end}} +{{define "javascript"}} + + +{{end}} From 0186e886e4bff5be062b9dba595df69dff39c270 Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Fri, 26 Aug 2022 13:52:45 +0200 Subject: [PATCH 07/12] Display go-set error messages, move html error text to log (commented) --- web/frontend/src/config/PlotSettings.svelte | 4 +++- web/frontend/src/config/admin/AddRole.svelte | 4 +++- web/frontend/src/config/admin/AddUser.svelte | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/web/frontend/src/config/PlotSettings.svelte b/web/frontend/src/config/PlotSettings.svelte index 1b7542d..76bc43c 100644 --- a/web/frontend/src/config/PlotSettings.svelte +++ b/web/frontend/src/config/PlotSettings.svelte @@ -28,7 +28,9 @@ let text = await res.text() popMessage(text, target, '#048109') } else { - throw new Error('Response Code ' + res.status + '-> ' + res.statusText); + let text = await res.text() + // console.log(res.statusText) + throw new Error('Response Code ' + res.status + '-> ' + text) } } catch (err) { popMessage(err, target, '#d63384') diff --git a/web/frontend/src/config/admin/AddRole.svelte b/web/frontend/src/config/admin/AddRole.svelte index dcd4cef..bdb0eba 100644 --- a/web/frontend/src/config/admin/AddRole.svelte +++ b/web/frontend/src/config/admin/AddRole.svelte @@ -28,7 +28,9 @@ popMessage(text, '#048109') reloadUserList() } else { - throw new Error('Response Code ' + res.status + '-> ' + res.statusText) + let text = await res.text() + // console.log(res.statusText) + throw new Error('Response Code ' + res.status + '-> ' + text) } } catch (err) { popMessage(err, '#d63384') diff --git a/web/frontend/src/config/admin/AddUser.svelte b/web/frontend/src/config/admin/AddUser.svelte index bca89f0..64d3519 100644 --- a/web/frontend/src/config/admin/AddUser.svelte +++ b/web/frontend/src/config/admin/AddUser.svelte @@ -19,7 +19,9 @@ popMessage(text, '#048109') reloadUserList() } else { - throw new Error('Response Code ' + res.status + '-> ' + res.statusText); + let text = await res.text() + // console.log(res.statusText) + throw new Error('Response Code ' + res.status + '-> ' + text) } } catch (err) { popMessage(err, '#d63384') From c9954787c158691a22f4db3dd034f0509651cd8a Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Fri, 26 Aug 2022 15:15:36 +0200 Subject: [PATCH 08/12] Add admin function to remove roles, rename addroles to editroles --- internal/api/rest.go | 24 +++++++++--- internal/auth/users.go | 31 +++++++++++++++ web/frontend/src/config/AdminSettings.svelte | 4 +- .../admin/{AddRole.svelte => EditRole.svelte} | 38 +++++++++++++++++-- 4 files changed, 85 insertions(+), 12 deletions(-) rename web/frontend/src/config/admin/{AddRole.svelte => EditRole.svelte} (63%) diff --git a/internal/api/rest.go b/internal/api/rest.go index 801cbc3..adeafeb 100644 --- a/internal/api/rest.go +++ b/internal/api/rest.go @@ -580,14 +580,26 @@ func (api *RestApi) updateUser(rw http.ResponseWriter, r *http.Request) { return } - // TODO: Handle anything but roles... + // Get Values newrole := r.FormValue("add-role") - if err := api.Authentication.AddRole(r.Context(), mux.Vars(r)["id"], newrole); err != nil { - http.Error(rw, err.Error(), http.StatusUnprocessableEntity) - return - } + delrole := r.FormValue("remove-role") - rw.Write([]byte("success")) + // TODO: Handle anything but roles... + if (newrole != "") { + if err := api.Authentication.AddRole(r.Context(), mux.Vars(r)["id"], newrole); err != nil { + http.Error(rw, err.Error(), http.StatusUnprocessableEntity) + return + } + rw.Write([]byte("Add Role Success")) + } else if (delrole != "") { + if err := api.Authentication.RemoveRole(r.Context(), mux.Vars(r)["id"], delrole); err != nil { + http.Error(rw, err.Error(), http.StatusUnprocessableEntity) + return + } + rw.Write([]byte("Remove Role Success")) + } else { + http.Error(rw, "Not Add or Del?", http.StatusInternalServerError) + } } func (api *RestApi) updateConfiguration(rw http.ResponseWriter, r *http.Request) { diff --git a/internal/auth/users.go b/internal/auth/users.go index 63f18c2..c2d9fdd 100644 --- a/internal/auth/users.go +++ b/internal/auth/users.go @@ -129,6 +129,37 @@ func (auth *Authentication) AddRole(ctx context.Context, username string, role s return nil } +func (auth *Authentication) RemoveRole(ctx context.Context, username string, role string) error { + user, err := auth.GetUser(username) + if err != nil { + return err + } + + if role != RoleAdmin && role != RoleApi && role != RoleUser { + return fmt.Errorf("invalid user role: %#v", role) + } + + var exists bool + var newroles []string + for _, r := range user.Roles { + if r != role { + newroles = append(newroles, r) // Append all roles not matching requested delete role + } else { + exists = true + } + } + + if (exists == true) { + var mroles, _ = json.Marshal(newroles) + if _, err := sq.Update("user").Set("roles", mroles).Where("user.username = ?", username).RunWith(auth.db).Exec(); err != nil { + return err + } + return nil + } else { + return fmt.Errorf("user %#v already does not have role %#v", username, role) + } +} + func FetchUser(ctx context.Context, db *sqlx.DB, username string) (*model.User, error) { me := GetUser(ctx) if me != nil && !me.HasRole(RoleAdmin) && me.Username != username { diff --git a/web/frontend/src/config/AdminSettings.svelte b/web/frontend/src/config/AdminSettings.svelte index 3564865..d1ce542 100644 --- a/web/frontend/src/config/AdminSettings.svelte +++ b/web/frontend/src/config/AdminSettings.svelte @@ -1,7 +1,7 @@ - - - -
-
-
-
Add Role to User
-
- - - -
- -
-
-
-
-
Scramble Names / Presentation Mode
- - -
-
-
+
{{end}} -
-
-
-
Line Width
- -
- - -
Width of the lines in the timeseries plots.
-
-

- -

- -
-
-
-
-
Plots per Row
- -
- - -
How many plots to show next to each other on pages such as /monitoring/job/, /monitoring/system/...
-
-

- -

- -
-
-
-
-
Colored Backgrounds
- -
-
- - -
-
- - -
-
-

- -

- -
-
-
-
-
-
-
Colorscheme for Timeseries Plots
- - - - -
-

- -

- -
-
-
- +{{define "stylesheets"}} + +{{end}} +{{define "javascript"}} + + {{end}} diff --git a/web/templates/configsvelte.tmpl b/web/templates/configsvelte.tmpl deleted file mode 100644 index ab188b1..0000000 --- a/web/templates/configsvelte.tmpl +++ /dev/null @@ -1,15 +0,0 @@ -{{define "content"}} -
-{{end}} - -{{define "stylesheets"}} - -{{end}} -{{define "javascript"}} - - -{{end}} From 0170e19363ade8e5328a338f9a05b18fa006f172 Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Mon, 12 Sep 2022 18:05:43 +0200 Subject: [PATCH 12/12] Added options for "support" role on user create, role add, role edit --- web/frontend/src/config/admin/AddUser.svelte | 4 ++++ web/frontend/src/config/admin/EditRole.svelte | 1 + 2 files changed, 5 insertions(+) diff --git a/web/frontend/src/config/admin/AddUser.svelte b/web/frontend/src/config/admin/AddUser.svelte index 64d3519..bcbd240 100644 --- a/web/frontend/src/config/admin/AddUser.svelte +++ b/web/frontend/src/config/admin/AddUser.svelte @@ -74,6 +74,10 @@ +
+ + +
diff --git a/web/frontend/src/config/admin/EditRole.svelte b/web/frontend/src/config/admin/EditRole.svelte index 4cb6f06..4615c0a 100644 --- a/web/frontend/src/config/admin/EditRole.svelte +++ b/web/frontend/src/config/admin/EditRole.svelte @@ -87,6 +87,7 @@