From 80aee6c26dac4bfd9dc67be17d110fcb21344aac Mon Sep 17 00:00:00 2001 From: gazillion101 Date: Fri, 7 Apr 2023 10:40:08 -0400 Subject: [PATCH 1/2] [#193] 193 workarounds --- DataTypes/Common.yaml | 5 ++ DbAnalyzer/go/types/Common.go | 6 +++ DbGuardian/go/types/Common.go | 6 +++ DbSync/go/types/Common.go | 6 +++ Tunnels/go/client/types/Common.go | 6 +++ Tunnels/go/meshconnector/types/Common.go | 6 +++ Tunnels/go/meshserver/types/Common.go | 6 +++ Tunnels/go/server/types/Common.go | 6 +++ web/go/src/authentication/authentication.go | 9 +++- web/go/src/dhandlers/customerhandlers.go | 8 ++-- web/go/src/types/Common.go | 6 +++ web/js/packages/common/Types/Common.ts | 52 +++++++++++++++++++++ web/js/packages/common/Types/Internal.tsx | 1 + web/js/packages/portal/src/App/Groups.tsx | 50 +++++++++++++++++--- 14 files changed, 161 insertions(+), 12 deletions(-) diff --git a/DataTypes/Common.yaml b/DataTypes/Common.yaml index abc3f532..75eaf9d2 100644 --- a/DataTypes/Common.yaml +++ b/DataTypes/Common.yaml @@ -107,6 +107,11 @@ AuthStatus: - errormessage: string - token: string +GroupStatus: + - status: string + - errormessage: string + - admincount: int + DatascopesStatus: - status: string - errormessage: string diff --git a/DbAnalyzer/go/types/Common.go b/DbAnalyzer/go/types/Common.go index 50cbce27..e59d345f 100644 --- a/DbAnalyzer/go/types/Common.go +++ b/DbAnalyzer/go/types/Common.go @@ -168,6 +168,12 @@ type GroupMappingStatus struct { Records []GroupMapping `json:"records"` } +type GroupStatus struct { + Status string `json:"status"` + Errormessage string `json:"errormessage"` + Admincount int `json:"admincount"` +} + type OperationStatus struct { Status string `json:"status"` Errormessage string `json:"errormessage"` diff --git a/DbGuardian/go/types/Common.go b/DbGuardian/go/types/Common.go index 50cbce27..e59d345f 100644 --- a/DbGuardian/go/types/Common.go +++ b/DbGuardian/go/types/Common.go @@ -168,6 +168,12 @@ type GroupMappingStatus struct { Records []GroupMapping `json:"records"` } +type GroupStatus struct { + Status string `json:"status"` + Errormessage string `json:"errormessage"` + Admincount int `json:"admincount"` +} + type OperationStatus struct { Status string `json:"status"` Errormessage string `json:"errormessage"` diff --git a/DbSync/go/types/Common.go b/DbSync/go/types/Common.go index 50cbce27..e59d345f 100644 --- a/DbSync/go/types/Common.go +++ b/DbSync/go/types/Common.go @@ -168,6 +168,12 @@ type GroupMappingStatus struct { Records []GroupMapping `json:"records"` } +type GroupStatus struct { + Status string `json:"status"` + Errormessage string `json:"errormessage"` + Admincount int `json:"admincount"` +} + type OperationStatus struct { Status string `json:"status"` Errormessage string `json:"errormessage"` diff --git a/Tunnels/go/client/types/Common.go b/Tunnels/go/client/types/Common.go index 50cbce27..e59d345f 100644 --- a/Tunnels/go/client/types/Common.go +++ b/Tunnels/go/client/types/Common.go @@ -168,6 +168,12 @@ type GroupMappingStatus struct { Records []GroupMapping `json:"records"` } +type GroupStatus struct { + Status string `json:"status"` + Errormessage string `json:"errormessage"` + Admincount int `json:"admincount"` +} + type OperationStatus struct { Status string `json:"status"` Errormessage string `json:"errormessage"` diff --git a/Tunnels/go/meshconnector/types/Common.go b/Tunnels/go/meshconnector/types/Common.go index 50cbce27..e59d345f 100644 --- a/Tunnels/go/meshconnector/types/Common.go +++ b/Tunnels/go/meshconnector/types/Common.go @@ -168,6 +168,12 @@ type GroupMappingStatus struct { Records []GroupMapping `json:"records"` } +type GroupStatus struct { + Status string `json:"status"` + Errormessage string `json:"errormessage"` + Admincount int `json:"admincount"` +} + type OperationStatus struct { Status string `json:"status"` Errormessage string `json:"errormessage"` diff --git a/Tunnels/go/meshserver/types/Common.go b/Tunnels/go/meshserver/types/Common.go index 50cbce27..e59d345f 100644 --- a/Tunnels/go/meshserver/types/Common.go +++ b/Tunnels/go/meshserver/types/Common.go @@ -168,6 +168,12 @@ type GroupMappingStatus struct { Records []GroupMapping `json:"records"` } +type GroupStatus struct { + Status string `json:"status"` + Errormessage string `json:"errormessage"` + Admincount int `json:"admincount"` +} + type OperationStatus struct { Status string `json:"status"` Errormessage string `json:"errormessage"` diff --git a/Tunnels/go/server/types/Common.go b/Tunnels/go/server/types/Common.go index 50cbce27..e59d345f 100644 --- a/Tunnels/go/server/types/Common.go +++ b/Tunnels/go/server/types/Common.go @@ -168,6 +168,12 @@ type GroupMappingStatus struct { Records []GroupMapping `json:"records"` } +type GroupStatus struct { + Status string `json:"status"` + Errormessage string `json:"errormessage"` + Admincount int `json:"admincount"` +} + type OperationStatus struct { Status string `json:"status"` Errormessage string `json:"errormessage"` diff --git a/web/go/src/authentication/authentication.go b/web/go/src/authentication/authentication.go index 37dabac1..3d372bbb 100644 --- a/web/go/src/authentication/authentication.go +++ b/web/go/src/authentication/authentication.go @@ -1679,14 +1679,19 @@ func CreateNewMapping(schema, dymiumgroup, directorygroup, comments string) erro return nil } -func UpdateMapping(schema, id, dymiumgroup, directorygroup, comments string, adminaccess bool) error { +func UpdateMapping(schema, id, dymiumgroup, directorygroup, comments string, adminaccess bool) (error, int) { sql := "update "+schema+".groupmapping set outergroup=$1, innergroup=$2, comment=$3, adminaccess=$4 where id=$5;" _, err := db.Exec(sql, directorygroup, dymiumgroup, comments, adminaccess, id) if(err != nil) { log.Errorf("UpdateMapping error %s", err.Error()) + return err, 0 } - return err + sql = "select count(*) "+schema+".groupmapping where adminaccess=true;" + row := db.QueryRow(sql) + var count int + row.Scan(&count) + return err, count } func DeleteMapping(schema, id string) error { diff --git a/web/go/src/dhandlers/customerhandlers.go b/web/go/src/dhandlers/customerhandlers.go index 0a40e575..2964f792 100644 --- a/web/go/src/dhandlers/customerhandlers.go +++ b/web/go/src/dhandlers/customerhandlers.go @@ -623,13 +623,13 @@ func UpdateMapping(w http.ResponseWriter, r *http.Request) { var t types.GroupMapping err := json.Unmarshal(body, &t) - error := authentication.UpdateMapping(schema, *t.Id, t.Dymiumgroup, t.Directorygroup, t.Comments, t.Adminaccess) - var status types.OperationStatus + error, admincount := authentication.UpdateMapping(schema, *t.Id, t.Dymiumgroup, t.Directorygroup, t.Comments, t.Adminaccess) + var status types.GroupStatus if(error == nil) { - status = types.OperationStatus{"OK", "Mapping updated"} + status = types.GroupStatus{"OK", "Mapping updated", admincount} } else { log.ErrorUserf(schema, session, email, groups, roles, "Api UpdateMapping, error: %s", error.Error()) - status = types.OperationStatus{"Error", error.Error()} + status = types.GroupStatus{"Error", error.Error(), 0} } js, err := json.Marshal(status) if err != nil { diff --git a/web/go/src/types/Common.go b/web/go/src/types/Common.go index 50cbce27..e59d345f 100644 --- a/web/go/src/types/Common.go +++ b/web/go/src/types/Common.go @@ -168,6 +168,12 @@ type GroupMappingStatus struct { Records []GroupMapping `json:"records"` } +type GroupStatus struct { + Status string `json:"status"` + Errormessage string `json:"errormessage"` + Admincount int `json:"admincount"` +} + type OperationStatus struct { Status string `json:"status"` Errormessage string `json:"errormessage"` diff --git a/web/js/packages/common/Types/Common.ts b/web/js/packages/common/Types/Common.ts index 7b97ab0a..4661d3b5 100644 --- a/web/js/packages/common/Types/Common.ts +++ b/web/js/packages/common/Types/Common.ts @@ -1371,6 +1371,58 @@ export class GroupMappingStatus { } } +export class GroupStatus { + private '_status': string + private '_errormessage': string + private '_admincount': number + + constructor() { + this['_status'] = '' + this['_errormessage'] = '' + this['_admincount'] = 0 + } + get status(): string { return this['_status'] } + set status(__a__: any) { + let __v__ = stringReader('')(__a__) + if(!_.isEqual(__v__,this['_status'])) { + setDirtyFlag() + this['_status'] = __v__ + } + } + get errormessage(): string { return this['_errormessage'] } + set errormessage(__a__: any) { + let __v__ = stringReader('')(__a__) + if(!_.isEqual(__v__,this['_errormessage'])) { + setDirtyFlag() + this['_errormessage'] = __v__ + } + } + get admincount(): number { return this['_admincount'] } + set admincount(__a__: any) { + let __v__ = intReader(0)(__a__) + if(!_.isEqual(__v__,this['_admincount'])) { + setDirtyFlag() + this['_admincount'] = __v__ + } + } + + toJson(): string { return JSON.stringify(this).split('"_').join('"') } + + static fromJson(__a__: any): GroupStatus { + disableDF() + let cls = new GroupStatus() + if(typeof __a__ === 'object' && __a__ != null) { + cls.status = __a__['status'] + cls.errormessage = __a__['errormessage'] + cls.admincount = __a__['admincount'] + } else { + doAlert(`GroupStatus: an attempt to initialize from ${__a__}`) + } + enableDF() + return cls + } +} + export class OperationStatus { private '_status': string private '_errormessage': string diff --git a/web/js/packages/common/Types/Internal.tsx b/web/js/packages/common/Types/Internal.tsx index 75b96f3f..af1c4215 100644 --- a/web/js/packages/common/Types/Internal.tsx +++ b/web/js/packages/common/Types/Internal.tsx @@ -77,4 +77,5 @@ export interface Mapping { dymiumgroup: string; directorygroup: string; comments: string; + adminaccess: boolean; } \ No newline at end of file diff --git a/web/js/packages/portal/src/App/Groups.tsx b/web/js/packages/portal/src/App/Groups.tsx index 09b4f6f1..3fcb857a 100644 --- a/web/js/packages/portal/src/App/Groups.tsx +++ b/web/js/packages/portal/src/App/Groups.tsx @@ -5,6 +5,8 @@ import Form from 'react-bootstrap/Form' import Button from 'react-bootstrap/Button' import Row from 'react-bootstrap/Row' import Col from 'react-bootstrap/Col' +import { useNavigate } from 'react-router-dom'; + import Card from 'react-bootstrap/Card' import Offcanvas from '@dymium/common/Components/Offcanvas' import { Typeahead } from 'react-bootstrap-typeahead'; @@ -44,6 +46,8 @@ function GroupMapping() { const [mappings, setMappings] = useState([]) const [showOffcanvas, setShowOffcanvas] = useState(com.isInstaller()) + let mappingsref = useRef(mappings) + mappingsref.current = mappings let AddMapping = () => { setShow(false) } @@ -53,8 +57,23 @@ function GroupMapping() { null, "", resp => { resp.json().then(js => { - - setMappings(js.records) + let admin = false + if (js.records.length > 0) { + for (let i = 0; i < js.records.length; i++) { + if (js.records[i].adminaccess === true) { + admin = true + break + } + } + if (!admin) { + setAlert( + setAlert(<>)} dismissible> + Your group set does not have a group marked as admin role. You might get locked out of the console. + + ) + } + } + setMappings(mappings => js.records) setSpinner(false) setShow(false) }).catch((error) => { @@ -74,10 +93,10 @@ function GroupMapping() { error => { console.log("on exception") setSpinner(false) - setAlert( - setAlert(<>)} dismissible> + setAlert( + setAlert(<>)} dismissible> Error retrieving mapping: {error.message} - + ) setShow(false) }) @@ -233,9 +252,24 @@ function GroupMapping() { ) }) } - + const navigate = useNavigate(); useEffect(() => { getMappings() + + return () => { + let m = mappingsref.current + let admin = false + for(let i = 0; i < m.length; i++) { + if( m[i].adminaccess) { + admin = true + break + } + } + if(!admin) { + window.alert("Please mark at least one group as admin!") + navigate("/app/groups") + } + } }, []) let handleSubmit = event => { @@ -526,6 +560,10 @@ function GroupMapping() { Date: Fri, 7 Apr 2023 10:47:29 -0400 Subject: [PATCH 2/2] [#193] Update GroupMapping.test.js.snap --- .../__snapshots__/GroupMapping.test.js.snap | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/web/js/packages/portal/src/tests/__snapshots__/GroupMapping.test.js.snap b/web/js/packages/portal/src/tests/__snapshots__/GroupMapping.test.js.snap index 85f4b29c..d3b08497 100644 --- a/web/js/packages/portal/src/tests/__snapshots__/GroupMapping.test.js.snap +++ b/web/js/packages/portal/src/tests/__snapshots__/GroupMapping.test.js.snap @@ -137,6 +137,28 @@ Array [
+
+ + Your group set does not have a group marked as admin role. You might get locked out of the console. +
@@ -201,7 +223,7 @@ Array [ Directory group: