Skip to content

Commit

Permalink
[supabase#230] Merge branch 'main' into supabase#230
Browse files Browse the repository at this point in the history
  • Loading branch information
gazillion101 committed Apr 8, 2023
2 parents 4c28f51 + 7169b82 commit 21ff05e
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 14 deletions.
5 changes: 5 additions & 0 deletions DataTypes/Common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ AuthStatus:
- errormessage: string
- token: string

GroupStatus:
- status: string
- errormessage: string
- admincount: int

DatascopesStatus:
- status: string
- errormessage: string
Expand Down
6 changes: 6 additions & 0 deletions DbAnalyzer/go/types/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions DbGuardian/go/types/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions DbSync/go/types/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions Tunnels/go/client/types/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions Tunnels/go/meshconnector/types/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions Tunnels/go/meshserver/types/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions Tunnels/go/server/types/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
9 changes: 7 additions & 2 deletions web/go/src/authentication/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
8 changes: 4 additions & 4 deletions web/go/src/dhandlers/customerhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions web/go/src/types/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
52 changes: 52 additions & 0 deletions web/js/packages/common/Types/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions web/js/packages/common/Types/Internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ export interface Mapping {
dymiumgroup: string;
directorygroup: string;
comments: string;
adminaccess: boolean;
}
50 changes: 44 additions & 6 deletions web/js/packages/portal/src/App/Groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,6 +46,8 @@ function GroupMapping() {
const [mappings, setMappings] = useState<types.Mapping[]>([])
const [showOffcanvas, setShowOffcanvas] = useState(com.isInstaller())

let mappingsref = useRef(mappings)
mappingsref.current = mappings
let AddMapping = () => {
setShow(false)
}
Expand All @@ -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(
<Alert variant="warning" onClose={() => setAlert(<></>)} dismissible>
Your group set does not have a group marked as admin role. You might get locked out of the console.
</Alert>
)
}
}
setMappings(mappings => js.records)
setSpinner(false)
setShow(false)
}).catch((error) => {
Expand All @@ -74,10 +93,10 @@ function GroupMapping() {
error => {
console.log("on exception")
setSpinner(false)
setAlert(
<Alert variant="danger" onClose={() => setAlert(<></>)} dismissible>
setAlert(
<Alert variant="danger" onClose={() => setAlert(<></>)} dismissible>
Error retrieving mapping: {error.message}
</Alert>
</Alert>
)
setShow(false)
})
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -526,6 +560,10 @@ function GroupMapping() {
<BootstrapTable id="scaledtable"
size="sm"
condensed
defaultSorted={[{
dataField: 'directorygroup',
order: 'asc'
}]}
striped bootstrap4 bordered={false}
pagination={paginationFactory()}
{...props.baseProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ Array [
<div
className="text-left mt-0 pt-0"
>
<div
className="fade alert alert-warning alert-dismissible show"
role="alert"
>
<button
className="close"
onClick={[Function]}
type="button"
>
<span
aria-hidden="true"
>
×
</span>
<span
className="sr-only"
>
Close alert
</span>
</button>
Your group set does not have a group marked as admin role. You might get locked out of the console.
</div>
<div
className="d-flex"
>
Expand Down Expand Up @@ -201,15 +223,15 @@ Array [
<thead>
<tr>
<th
aria-label="Directory group: sortable"
aria-label="Directory group: sort asc"
className="sortable"
onClick={[Function]}
onKeyUp={[Function]}
tabIndex={0}
>
Directory group:
<span
className="order-4"
className="caret-4-asc"
/>
</th>
<th
Expand Down

0 comments on commit 21ff05e

Please sign in to comment.