diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-25 21:44:14 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-25 21:44:14 -0700 |
| commit | 69c2fb504953cf8de3730b2f64cfa8d7b6b13859 (patch) | |
| tree | b5c831e1f0e3cb09c20086cfa7ed8818cad61a4c | |
| parent | 889a8f76762b2cb924e74a6b18f1283afcceaa93 (diff) | |
Implement "Can Send Messages" permission
| -rw-r--r-- | hotline/transaction_handlers.go | 5 | ||||
| -rw-r--r-- | hotline/transaction_handlers_test.go | 47 |
2 files changed, 52 insertions, 0 deletions
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index 412868c..85879a4 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -299,6 +299,11 @@ func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err erro // Fields used in the reply: // None func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, err error) { + if !cc.Authorize(accessSendPrivMsg) { + res = append(res, cc.NewErrReply(t, "You are not allowed to send private messages.")) + return res, err + } + msg := t.GetField(fieldData) ID := t.GetField(fieldUserID) diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index f43d45f..c504bbe 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -2288,9 +2288,48 @@ func TestHandleSendInstantMsg(t *testing.T) { wantErr assert.ErrorAssertionFunc }{ { + name: "without required permission", + args: args{ + cc: &ClientConn{ + Account: &Account{ + Access: func() *[]byte { + var bits accessBitmap + access := bits[:] + return &access + }(), + }, + }, + t: NewTransaction( + tranDelNewsArt, + &[]byte{0, 0}, + ), + }, + wantRes: []Transaction{ + { + Flags: 0x00, + IsReply: 0x01, + Type: []byte{0, 0x00}, + ID: []byte{0, 0, 0, 0}, + ErrorCode: []byte{0, 0, 0, 1}, + Fields: []Field{ + NewField(fieldError, []byte("You are not allowed to send private messages.")), + }, + }, + }, + wantErr: assert.NoError, + }, + { name: "when client 1 sends a message to client 2", args: args{ cc: &ClientConn{ + Account: &Account{ + Access: func() *[]byte { + var bits accessBitmap + bits.Set(accessSendPrivMsg) + access := bits[:] + return &access + }(), + }, ID: &[]byte{0, 1}, UserName: []byte("User1"), Server: &Server{ @@ -2333,6 +2372,14 @@ func TestHandleSendInstantMsg(t *testing.T) { name: "when client 2 has autoreply enabled", args: args{ cc: &ClientConn{ + Account: &Account{ + Access: func() *[]byte { + var bits accessBitmap + bits.Set(accessSendPrivMsg) + access := bits[:] + return &access + }(), + }, ID: &[]byte{0, 1}, UserName: []byte("User1"), Server: &Server{ |