forked from MirrorHub/mautrix-whatsapp
Rename relay permission level
This commit is contained in:
parent
56004031df
commit
b1baa0a0a1
5 changed files with 22 additions and 22 deletions
|
@ -193,10 +193,10 @@ type PermissionConfig map[string]PermissionLevel
|
||||||
type PermissionLevel int
|
type PermissionLevel int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PermissionLevelDefault PermissionLevel = 0
|
PermissionLevelDefault PermissionLevel = 0
|
||||||
PermissionLevelRelaybot PermissionLevel = 5
|
PermissionLevelRelay PermissionLevel = 5
|
||||||
PermissionLevelUser PermissionLevel = 10
|
PermissionLevelUser PermissionLevel = 10
|
||||||
PermissionLevelAdmin PermissionLevel = 100
|
PermissionLevelAdmin PermissionLevel = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
func (pc *PermissionConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (pc *PermissionConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
@ -211,8 +211,8 @@ func (pc *PermissionConfig) UnmarshalYAML(unmarshal func(interface{}) error) err
|
||||||
}
|
}
|
||||||
for key, value := range rawPC {
|
for key, value := range rawPC {
|
||||||
switch strings.ToLower(value) {
|
switch strings.ToLower(value) {
|
||||||
case "relaybot":
|
case "relaybot", "relay":
|
||||||
(*pc)[key] = PermissionLevelRelaybot
|
(*pc)[key] = PermissionLevelRelay
|
||||||
case "user":
|
case "user":
|
||||||
(*pc)[key] = PermissionLevelUser
|
(*pc)[key] = PermissionLevelUser
|
||||||
case "admin":
|
case "admin":
|
||||||
|
@ -236,8 +236,8 @@ func (pc *PermissionConfig) MarshalYAML() (interface{}, error) {
|
||||||
rawPC := make(map[string]string)
|
rawPC := make(map[string]string)
|
||||||
for key, value := range *pc {
|
for key, value := range *pc {
|
||||||
switch value {
|
switch value {
|
||||||
case PermissionLevelRelaybot:
|
case PermissionLevelRelay:
|
||||||
rawPC[key] = "relaybot"
|
rawPC[key] = "relay"
|
||||||
case PermissionLevelUser:
|
case PermissionLevelUser:
|
||||||
rawPC[key] = "user"
|
rawPC[key] = "user"
|
||||||
case PermissionLevelAdmin:
|
case PermissionLevelAdmin:
|
||||||
|
@ -249,8 +249,8 @@ func (pc *PermissionConfig) MarshalYAML() (interface{}, error) {
|
||||||
return rawPC, nil
|
return rawPC, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc PermissionConfig) IsRelaybotWhitelisted(userID id.UserID) bool {
|
func (pc PermissionConfig) IsRelayWhitelisted(userID id.UserID) bool {
|
||||||
return pc.GetPermissionLevel(userID) >= PermissionLevelRelaybot
|
return pc.GetPermissionLevel(userID) >= PermissionLevelRelay
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc PermissionConfig) IsWhitelisted(userID id.UserID) bool {
|
func (pc PermissionConfig) IsWhitelisted(userID id.UserID) bool {
|
||||||
|
|
|
@ -204,7 +204,7 @@ bridge:
|
||||||
|
|
||||||
# Permissions for using the bridge.
|
# Permissions for using the bridge.
|
||||||
# Permitted values:
|
# Permitted values:
|
||||||
# relaybot - Talk through the relaybot (if enabled), no access otherwise
|
# relay - Talk through the relaybot (if enabled), no access otherwise
|
||||||
# user - Access to use the bridge to chat with a WhatsApp account.
|
# user - Access to use the bridge to chat with a WhatsApp account.
|
||||||
# admin - User level and some additional administration tools
|
# admin - User level and some additional administration tools
|
||||||
# Permitted keys:
|
# Permitted keys:
|
||||||
|
@ -212,7 +212,7 @@ bridge:
|
||||||
# domain - All users on that homeserver
|
# domain - All users on that homeserver
|
||||||
# mxid - Specific user
|
# mxid - Specific user
|
||||||
permissions:
|
permissions:
|
||||||
"*": relaybot
|
"*": relay
|
||||||
"example.com": user
|
"example.com": user
|
||||||
"@admin:example.com": admin
|
"@admin:example.com": admin
|
||||||
|
|
||||||
|
|
|
@ -320,7 +320,7 @@ func (mx *MatrixHandler) shouldIgnoreEvent(evt *event.Event) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
user := mx.bridge.GetUserByMXID(evt.Sender)
|
||||||
if !user.RelaybotWhitelisted {
|
if !user.RelayWhitelisted {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -185,11 +185,11 @@ func (prov *ProvisioningAPI) Ping(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp := map[string]interface{}{
|
resp := map[string]interface{}{
|
||||||
"mxid": user.MXID,
|
"mxid": user.MXID,
|
||||||
"admin": user.Admin,
|
"admin": user.Admin,
|
||||||
"whitelisted": user.Whitelisted,
|
"whitelisted": user.Whitelisted,
|
||||||
"relaybot_whitelisted": user.RelaybotWhitelisted,
|
"relay_whitelisted": user.RelayWhitelisted,
|
||||||
"whatsapp": wa,
|
"whatsapp": wa,
|
||||||
}
|
}
|
||||||
jsonResponse(w, http.StatusOK, resp)
|
jsonResponse(w, http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
8
user.go
8
user.go
|
@ -54,9 +54,9 @@ type User struct {
|
||||||
bridge *Bridge
|
bridge *Bridge
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
Admin bool
|
Admin bool
|
||||||
Whitelisted bool
|
Whitelisted bool
|
||||||
RelaybotWhitelisted bool
|
RelayWhitelisted bool
|
||||||
|
|
||||||
mgmtCreateLock sync.Mutex
|
mgmtCreateLock sync.Mutex
|
||||||
connLock sync.Mutex
|
connLock sync.Mutex
|
||||||
|
@ -178,7 +178,7 @@ func (bridge *Bridge) NewUser(dbUser *database.User) *User {
|
||||||
|
|
||||||
historySyncs: make(chan *events.HistorySync, 32),
|
historySyncs: make(chan *events.HistorySync, 32),
|
||||||
}
|
}
|
||||||
user.RelaybotWhitelisted = user.bridge.Config.Bridge.Permissions.IsRelaybotWhitelisted(user.MXID)
|
user.RelayWhitelisted = user.bridge.Config.Bridge.Permissions.IsRelayWhitelisted(user.MXID)
|
||||||
user.Whitelisted = user.bridge.Config.Bridge.Permissions.IsWhitelisted(user.MXID)
|
user.Whitelisted = user.bridge.Config.Bridge.Permissions.IsWhitelisted(user.MXID)
|
||||||
user.Admin = user.bridge.Config.Bridge.Permissions.IsAdmin(user.MXID)
|
user.Admin = user.bridge.Config.Bridge.Permissions.IsAdmin(user.MXID)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
Loading…
Reference in a new issue