telepathy-idle: muc-channel: track op-ness in the channel to mark config properties {, im}mutable

Jonny Lamb jonny at kemper.freedesktop.org
Wed May 16 10:45:09 PDT 2012


Module: telepathy-idle
Branch: master
Commit: 0ca501e59fcff2279a927535708bf2143169d7fe
URL:    http://cgit.freedesktop.org/telepathy/telepathy-idle/commit/?id=0ca501e59fcff2279a927535708bf2143169d7fe

Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date:   Wed May 16 17:01:34 2012 +0100

muc-channel: track op-ness in the channel to mark config properties {,im}mutable

I must admit I misunderstood what was going on with this earlier when
I removed it. I was just being an idiot. I've brought it back now and
it's even tested!

Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>

---

 src/idle-muc-channel.c                |   48 +++++++++++++++++---------------
 tests/twisted/messages/room-config.py |   34 ++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 25 deletions(-)

diff --git a/src/idle-muc-channel.c b/src/idle-muc-channel.c
index b3d68a8..5d90df5 100644
--- a/src/idle-muc-channel.c
+++ b/src/idle-muc-channel.c
@@ -241,29 +241,13 @@ idle_muc_channel_constructed (GObject *obj)
 		tp_intset_destroy (remote);
 	}
 
-        {
-          TpBaseRoomConfigProperty mutable_properties[] = {
-            TP_BASE_ROOM_CONFIG_INVITE_ONLY,
-            TP_BASE_ROOM_CONFIG_MODERATED,
-            TP_BASE_ROOM_CONFIG_LIMIT,
-            TP_BASE_ROOM_CONFIG_PRIVATE,
-            TP_BASE_ROOM_CONFIG_PASSWORD_PROTECTED,
-            TP_BASE_ROOM_CONFIG_PASSWORD,
-          };
-          guint i;
-
-          priv->room_config =
-            (TpBaseRoomConfig *) idle_room_config_new ((TpBaseChannel *) self);
-          for (i = 0; i < G_N_ELEMENTS (mutable_properties); i++)
-            tp_base_room_config_set_property_mutable (priv->room_config,
-                mutable_properties[i], TRUE);
-
-          tp_base_room_config_set_can_update_configuration (
-              priv->room_config, TRUE);
-
-          /* Just to get those mutable properties out there. */
-          tp_base_room_config_emit_properties_changed (priv->room_config);
-        }
+        priv->room_config =
+          (TpBaseRoomConfig *) idle_room_config_new ((TpBaseChannel *) self);
+
+        tp_base_room_config_set_can_update_configuration (
+            priv->room_config, TRUE);
+        /* Just to get CanUpdateConfiguration out there. */
+        tp_base_room_config_emit_properties_changed (priv->room_config);
 }
 
 static void
@@ -588,14 +572,32 @@ static void change_mode_state(IdleMUCChannel *obj, guint add, guint remove) {
 	}
 
 	if (combined & (MODE_FLAG_OPERATOR_PRIVILEGE | MODE_FLAG_HALFOP_PRIVILEGE)) {
+		static const TpBaseRoomConfigProperty prop_helper[] = {
+			TP_BASE_ROOM_CONFIG_INVITE_ONLY,
+			TP_BASE_ROOM_CONFIG_LIMIT,
+			TP_BASE_ROOM_CONFIG_MODERATED,
+			TP_BASE_ROOM_CONFIG_PASSWORD,
+			TP_BASE_ROOM_CONFIG_PASSWORD_PROTECTED,
+			TP_BASE_ROOM_CONFIG_PRIVATE,
+			TP_NUM_BASE_ROOM_CONFIG_PROPERTIES
+		};
+
 		if (add & (MODE_FLAG_OPERATOR_PRIVILEGE | MODE_FLAG_HALFOP_PRIVILEGE)) {
 			group_add |= TP_CHANNEL_GROUP_FLAG_CAN_ADD | TP_CHANNEL_GROUP_FLAG_CAN_REMOVE | TP_CHANNEL_GROUP_FLAG_MESSAGE_REMOVE;
 
+			for (int i = 0; prop_helper[i] != TP_NUM_BASE_ROOM_CONFIG_PROPERTIES; ++i) {
+				tp_base_room_config_set_property_mutable (priv->room_config, prop_helper[i], TRUE);
+			}
+
 			if (flags & MODE_FLAG_TOPIC_ONLY_SETTABLE_BY_OPS)
 				idle_muc_channel_update_can_set_topic (obj, TRUE);
 		} else if (remove & (MODE_FLAG_OPERATOR_PRIVILEGE | MODE_FLAG_HALFOP_PRIVILEGE)) {
 			group_remove |= TP_CHANNEL_GROUP_FLAG_CAN_REMOVE | TP_CHANNEL_GROUP_FLAG_MESSAGE_REMOVE;
 
+			for (int i = 0; prop_helper[i] != TP_NUM_BASE_ROOM_CONFIG_PROPERTIES; ++i) {
+				tp_base_room_config_set_property_mutable (priv->room_config, prop_helper[i], FALSE);
+			}
+
 			if (flags & MODE_FLAG_INVITE_ONLY)
 				group_remove |= TP_CHANNEL_GROUP_FLAG_CAN_ADD;
 
diff --git a/tests/twisted/messages/room-config.py b/tests/twisted/messages/room-config.py
index 0b8043a..d8e5bdf 100644
--- a/tests/twisted/messages/room-config.py
+++ b/tests/twisted/messages/room-config.py
@@ -12,7 +12,7 @@ def change_channel_mode(stream, mode_change):
     stream.sendMessage('324', stream.nick, '#test', mode_change,
                        prefix='idle.test.server')
 
-def setup(q, bus, conn, stream):
+def setup(q, bus, conn, stream, op_user=True):
     conn.Connect()
     q.expect('dbus-signal', signal='StatusChanged',
         args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
@@ -36,7 +36,20 @@ def setup(q, bus, conn, stream):
              args=[cs.CHANNEL_IFACE_ROOM_CONFIG,
                    {'ConfigurationRetrieved': True}, []])
 
-    sync_stream(q, stream)
+    if op_user:
+        change_channel_mode(stream, '+o test')
+
+        q.expect_many(EventPattern('dbus-signal', signal='GroupFlagsChanged',
+                                   args=[cs.GF_MESSAGE_REMOVE | cs.GF_CAN_REMOVE, 0]),
+                      EventPattern('dbus-signal', signal='PropertiesChanged',
+                                   args=[cs.CHANNEL_IFACE_ROOM_CONFIG,
+                                         {'MutableProperties': ['InviteOnly',
+                                                                'Limit',
+                                                                'Moderated',
+                                                                'Private',
+                                                                'PasswordProtected',
+                                                                'Password']},
+                                         []]))
 
     return chan
 
@@ -286,9 +299,26 @@ def test_modechanges(q, bus, conn, stream):
                     'Password': 'holly'},
                    []])
 
+def test_mode_no_op(q, bus, conn, stream):
+    chan = setup(q, bus, conn, stream, op_user=False)
+
+    # we haven't been opped, so we can't be allowed to change these
+    # values
+    for key, val in [('InviteOnly', True),
+                     ('Moderated', True),
+                     ('Private', True),
+                     ('Password', True),
+                     ('Limit', 99)]:
+        call_async(q, chan.RoomConfig1, 'UpdateConfiguration',
+                   {key: val})
+
+        q.expect('dbus-error', method='UpdateConfiguration',
+                 name=cs.NOT_IMPLEMENTED)
+
 if __name__ == '__main__':
     exec_test(test_props_present)
     exec_test(test_simple_bools)
     exec_test(test_limit)
     exec_test(test_password)
     exec_test(test_modechanges)
+    exec_test(test_mode_no_op)



More information about the telepathy-commits mailing list