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
|
||||
|
||||
const (
|
||||
PermissionLevelDefault PermissionLevel = 0
|
||||
PermissionLevelRelaybot PermissionLevel = 5
|
||||
PermissionLevelUser PermissionLevel = 10
|
||||
PermissionLevelAdmin PermissionLevel = 100
|
||||
PermissionLevelDefault PermissionLevel = 0
|
||||
PermissionLevelRelay PermissionLevel = 5
|
||||
PermissionLevelUser PermissionLevel = 10
|
||||
PermissionLevelAdmin PermissionLevel = 100
|
||||
)
|
||||
|
||||
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 {
|
||||
switch strings.ToLower(value) {
|
||||
case "relaybot":
|
||||
(*pc)[key] = PermissionLevelRelaybot
|
||||
case "relaybot", "relay":
|
||||
(*pc)[key] = PermissionLevelRelay
|
||||
case "user":
|
||||
(*pc)[key] = PermissionLevelUser
|
||||
case "admin":
|
||||
|
@ -236,8 +236,8 @@ func (pc *PermissionConfig) MarshalYAML() (interface{}, error) {
|
|||
rawPC := make(map[string]string)
|
||||
for key, value := range *pc {
|
||||
switch value {
|
||||
case PermissionLevelRelaybot:
|
||||
rawPC[key] = "relaybot"
|
||||
case PermissionLevelRelay:
|
||||
rawPC[key] = "relay"
|
||||
case PermissionLevelUser:
|
||||
rawPC[key] = "user"
|
||||
case PermissionLevelAdmin:
|
||||
|
@ -249,8 +249,8 @@ func (pc *PermissionConfig) MarshalYAML() (interface{}, error) {
|
|||
return rawPC, nil
|
||||
}
|
||||
|
||||
func (pc PermissionConfig) IsRelaybotWhitelisted(userID id.UserID) bool {
|
||||
return pc.GetPermissionLevel(userID) >= PermissionLevelRelaybot
|
||||
func (pc PermissionConfig) IsRelayWhitelisted(userID id.UserID) bool {
|
||||
return pc.GetPermissionLevel(userID) >= PermissionLevelRelay
|
||||
}
|
||||
|
||||
func (pc PermissionConfig) IsWhitelisted(userID id.UserID) bool {
|
||||
|
|
|
@ -204,7 +204,7 @@ bridge:
|
|||
|
||||
# Permissions for using the bridge.
|
||||
# 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.
|
||||
# admin - User level and some additional administration tools
|
||||
# Permitted keys:
|
||||
|
@ -212,7 +212,7 @@ bridge:
|
|||
# domain - All users on that homeserver
|
||||
# mxid - Specific user
|
||||
permissions:
|
||||
"*": relaybot
|
||||
"*": relay
|
||||
"example.com": user
|
||||
"@admin:example.com": admin
|
||||
|
||||
|
|
|
@ -320,7 +320,7 @@ func (mx *MatrixHandler) shouldIgnoreEvent(evt *event.Event) bool {
|
|||
return true
|
||||
}
|
||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
||||
if !user.RelaybotWhitelisted {
|
||||
if !user.RelayWhitelisted {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
|
@ -185,11 +185,11 @@ func (prov *ProvisioningAPI) Ping(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
resp := map[string]interface{}{
|
||||
"mxid": user.MXID,
|
||||
"admin": user.Admin,
|
||||
"whitelisted": user.Whitelisted,
|
||||
"relaybot_whitelisted": user.RelaybotWhitelisted,
|
||||
"whatsapp": wa,
|
||||
"mxid": user.MXID,
|
||||
"admin": user.Admin,
|
||||
"whitelisted": user.Whitelisted,
|
||||
"relay_whitelisted": user.RelayWhitelisted,
|
||||
"whatsapp": wa,
|
||||
}
|
||||
jsonResponse(w, http.StatusOK, resp)
|
||||
}
|
||||
|
|
8
user.go
8
user.go
|
@ -54,9 +54,9 @@ type User struct {
|
|||
bridge *Bridge
|
||||
log log.Logger
|
||||
|
||||
Admin bool
|
||||
Whitelisted bool
|
||||
RelaybotWhitelisted bool
|
||||
Admin bool
|
||||
Whitelisted bool
|
||||
RelayWhitelisted bool
|
||||
|
||||
mgmtCreateLock sync.Mutex
|
||||
connLock sync.Mutex
|
||||
|
@ -178,7 +178,7 @@ func (bridge *Bridge) NewUser(dbUser *database.User) *User {
|
|||
|
||||
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.Admin = user.bridge.Config.Bridge.Permissions.IsAdmin(user.MXID)
|
||||
go func() {
|
||||
|
|
Loading…
Reference in a new issue