Move SignedInUser to user service and RoleType and Roles to org (#53445)

* Move SignedInUser to user service and RoleType and Roles to org

* Use go naming convention for roles

* Fix some imports and leftovers

* Fix ldap debug test

* Fix lint

* Fix lint 2

* Fix lint 3

* Fix type and not needed conversion

* Clean up messages in api tests

* Clean up api tests 2
This commit is contained in:
idafurjes
2022-08-10 11:56:48 +02:00
committed by GitHub
parent 46004037e2
commit 6afad51761
278 changed files with 1758 additions and 1543 deletions

View File

@@ -2,6 +2,8 @@ package org
import (
"errors"
"fmt"
"strings"
"time"
)
@@ -39,9 +41,9 @@ type OrgUser struct {
type RoleType string
const (
ROLE_VIEWER RoleType = "Viewer"
ROLE_EDITOR RoleType = "Editor"
ROLE_ADMIN RoleType = "Admin"
RoleViewer RoleType = "Viewer"
RoleEditor RoleType = "Editor"
RoleAdmin RoleType = "Admin"
)
type CreateOrgCommand struct {
@@ -58,3 +60,57 @@ type GetOrgIDForNewUserCommand struct {
OrgName string
SkipOrgSetup bool
}
func (r RoleType) IsValid() bool {
return r == RoleViewer || r == RoleAdmin || r == RoleEditor
}
func (r RoleType) Includes(other RoleType) bool {
if r == RoleAdmin {
return true
}
if r == RoleEditor {
return other != RoleAdmin
}
return r == other
}
func (r RoleType) Children() []RoleType {
switch r {
case RoleAdmin:
return []RoleType{RoleEditor, RoleViewer}
case RoleEditor:
return []RoleType{RoleViewer}
default:
return nil
}
}
func (r RoleType) Parents() []RoleType {
switch r {
case RoleEditor:
return []RoleType{RoleAdmin}
case RoleViewer:
return []RoleType{RoleEditor, RoleAdmin}
default:
return nil
}
}
func (r *RoleType) UnmarshalText(data []byte) error {
// make sure "viewer" and "Viewer" are both correct
str := strings.Title(string(data))
*r = RoleType(str)
if !r.IsValid() {
if (*r) != "" {
return fmt.Errorf("invalid role value: %s", *r)
}
*r = RoleViewer
}
return nil
}