Rename relay permission level

This commit is contained in:
Tulir Asokan 2021-10-28 14:03:55 +03:00
parent 56004031df
commit b1baa0a0a1
5 changed files with 22 additions and 22 deletions

View file

@ -194,7 +194,7 @@ type PermissionLevel int
const (
PermissionLevelDefault PermissionLevel = 0
PermissionLevelRelaybot PermissionLevel = 5
PermissionLevelRelay PermissionLevel = 5
PermissionLevelUser PermissionLevel = 10
PermissionLevelAdmin PermissionLevel = 100
)
@ -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 {

View file

@ -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

View file

@ -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

View file

@ -188,7 +188,7 @@ func (prov *ProvisioningAPI) Ping(w http.ResponseWriter, r *http.Request) {
"mxid": user.MXID,
"admin": user.Admin,
"whitelisted": user.Whitelisted,
"relaybot_whitelisted": user.RelaybotWhitelisted,
"relay_whitelisted": user.RelayWhitelisted,
"whatsapp": wa,
}
jsonResponse(w, http.StatusOK, resp)

View file

@ -56,7 +56,7 @@ type User struct {
Admin bool
Whitelisted bool
RelaybotWhitelisted 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() {