]> git.r.bdr.sh - rbdr/mobius/commitdiff
Implement "Can Send Messages" permission
authorJeff Halter <redacted>
Sun, 26 Jun 2022 04:44:14 +0000 (21:44 -0700)
committerJeff Halter <redacted>
Sun, 26 Jun 2022 04:44:14 +0000 (21:44 -0700)
hotline/transaction_handlers.go
hotline/transaction_handlers_test.go

index 412868c8d62242e0118cce93b797e91709ab6e8b..85879a4de1bc714c0a9d18e56e9e610bf0ad5f91 100644 (file)
@@ -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)
 
index f43d45f29ec6340c75597504ee3805a06ec1d4fa..c504bbe8f11d6e2eabb635c8caa03c91a4459331 100644 (file)
@@ -2287,10 +2287,49 @@ func TestHandleSendInstantMsg(t *testing.T) {
                wantRes []Transaction
                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{