From a6cff4a96923f99b132d700e9525097e3bbad994 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 10:18:31 +0100 Subject: [PATCH 01/10] Show server bans in the timeline --- src/TextForEvent.js | 62 +++++++++++++++++++++++++ src/components/views/rooms/EventTile.js | 1 + 2 files changed, 63 insertions(+) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 712150af4d..9a7c1b58ff 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -129,6 +129,67 @@ function textForRoomNameEvent(ev) { }); } +function textForServerACLEvent(ev) { + var senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); + let prev = ev.getPrevContent(); + let current = ev.getContent(); + let text = ""; + let changes = []; + if (prev == undefined) { + text = `${senderDisplayName} set server ACLs for this room:`; + prev = { + deny: [], + allow: [], + allow_ip_literals: true + } + } else { + text = `${senderDisplayName} changed the server ACLs for this room:` + if (!Array.isArray(prev.allow)){ + prev.allow = [] + } + + if (!Array.isArray(prev.deny)){ + prev.deny = [] + } + } + + if (!Array.isArray(current.allow)){ + current.allow = [] + } + + if (!Array.isArray(current.deny)){ + current.deny = [] + } + + const bannedServers = current.deny.filter((bannedSrv) => !prev.deny.includes(bannedSrv)); + const unbannedServers = prev.deny.filter((bannedSrv) => !current.deny.includes(bannedSrv)); + const allowedServers = current.allow.filter((bannedSrv) => !prev.allow.includes(bannedSrv)); + const unallowedServers = prev.allow.filter((bannedSrv) => !current.allow.includes(bannedSrv)); + + if (bannedServers.length > 0) { + changes.push(`servers matching ${bannedServers.join(",")} are now banned`); + } + + if (unbannedServers.length > 0) { + changes.push(`servers matching ${unbannedServers.join(",")} are no longer banned`); + } + + if (allowedServers.length > 0) { + changes.push(`servers matching ${allowedServers.join(",")} are now allowed`); + } + + if (unallowedServers.length > 0) { + changes.push(`servers matching ${unallowedServers.join(",")} are no longer allowed`); + } + + if (prev.allow_ip_literals !== current.allow_ip_literals) { + const allowban = current.allow_ip_literals ? "allowed" : "banned"; + changes.push(`Participating from a server using ip literals is now ${allowban}`); + } + + return text + changes.join("\n"); +} + function textForMessageEvent(ev) { const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); let message = senderDisplayName + ': ' + ev.getContent().body; @@ -309,6 +370,7 @@ const stateHandlers = { 'm.room.encryption': textForEncryptionEvent, 'm.room.power_levels': textForPowerEvent, 'm.room.pinned_events': textForPinnedEvent, + 'm.room.server_acl': textForServerACLEvent, 'im.vector.modular.widgets': textForWidgetEvent, }; diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index 7f376502d7..9ed73c39b1 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -56,6 +56,7 @@ const stateEventTileTypes = { 'm.room.topic': 'messages.TextualEvent', 'm.room.power_levels': 'messages.TextualEvent', 'm.room.pinned_events': 'messages.TextualEvent', + 'm.room.server_acl' : 'messages.TextualEvent', 'im.vector.modular.widgets': 'messages.TextualEvent', }; From 526459a9e06ce4e9beb90c1a4cd5489115ad627f Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 10:19:11 +0100 Subject: [PATCH 02/10] Capitalise --- src/TextForEvent.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 9a7c1b58ff..42e065be1c 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -167,19 +167,19 @@ function textForServerACLEvent(ev) { const unallowedServers = prev.allow.filter((bannedSrv) => !current.allow.includes(bannedSrv)); if (bannedServers.length > 0) { - changes.push(`servers matching ${bannedServers.join(",")} are now banned`); + changes.push(`Servers matching ${bannedServers.join(",")} are now banned`); } if (unbannedServers.length > 0) { - changes.push(`servers matching ${unbannedServers.join(",")} are no longer banned`); + changes.push(`Servers matching ${unbannedServers.join(",")} are no longer banned`); } if (allowedServers.length > 0) { - changes.push(`servers matching ${allowedServers.join(",")} are now allowed`); + changes.push(`Servers matching ${allowedServers.join(",")} are now allowed`); } if (unallowedServers.length > 0) { - changes.push(`servers matching ${unallowedServers.join(",")} are no longer allowed`); + changes.push(`Servers matching ${unallowedServers.join(",")} are no longer allowed`); } if (prev.allow_ip_literals !== current.allow_ip_literals) { From 8b9fd7ddcb230271cd8b97187a7578289319f131 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 15:31:21 +0100 Subject: [PATCH 03/10] Clean up rules. --- src/TextForEvent.js | 49 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 42e065be1c..7368d0577b 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -131,26 +131,19 @@ function textForRoomNameEvent(ev) { function textForServerACLEvent(ev) { var senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); - let prev = ev.getPrevContent(); + let prev_content = ev.getPrevContent(); let current = ev.getContent(); let text = ""; let changes = []; - if (prev == undefined) { - text = `${senderDisplayName} set server ACLs for this room:`; - prev = { - deny: [], - allow: [], - allow_ip_literals: true - } + let prev = { + deny: Array.isArray(prev_content.deny) ? prev_content.deny : [], + allow: Array.isArray(prev_content.allow) ? prev_content.allow : [], + allow_ip_literals: !(prev_content.allow_ip_literals === false) + } + if (prev.deny.length === 0 && prev.allow.length === 0) { + text = `${senderDisplayName} set server ACLs for this room: `; } else { - text = `${senderDisplayName} changed the server ACLs for this room:` - if (!Array.isArray(prev.allow)){ - prev.allow = [] - } - - if (!Array.isArray(prev.deny)){ - prev.deny = [] - } + text = `${senderDisplayName} changed the server ACLs for this room: `; } if (!Array.isArray(current.allow)){ @@ -161,30 +154,36 @@ function textForServerACLEvent(ev) { current.deny = [] } - const bannedServers = current.deny.filter((bannedSrv) => !prev.deny.includes(bannedSrv)); - const unbannedServers = prev.deny.filter((bannedSrv) => !current.deny.includes(bannedSrv)); - const allowedServers = current.allow.filter((bannedSrv) => !prev.allow.includes(bannedSrv)); - const unallowedServers = prev.allow.filter((bannedSrv) => !current.allow.includes(bannedSrv)); + const bannedServers = current.deny.filter((srv) => typeof(srv) === 'string' && !prev.deny.includes(srv)); + const unbannedServers = prev.deny.filter((srv) => typeof(srv) === 'string' && !current.deny.includes(srv)); + const allowedServers = current.allow.filter((srv) => typeof(srv) === 'string' && !prev.allow.includes(srv)); + const unallowedServers = prev.allow.filter((srv) => typeof(srv) === 'string' && !current.allow.includes(srv)); + + console.log(bannedServers,unbannedServers,allowedServers,unallowedServers); if (bannedServers.length > 0) { - changes.push(`Servers matching ${bannedServers.join(",")} are now banned`); + changes.push(`Servers matching ${bannedServers.join(",")} are now banned.`); } if (unbannedServers.length > 0) { - changes.push(`Servers matching ${unbannedServers.join(",")} are no longer banned`); + changes.push(`Servers matching ${unbannedServers.join(",")} were removed from the ban list.`); } if (allowedServers.length > 0) { - changes.push(`Servers matching ${allowedServers.join(",")} are now allowed`); + changes.push(`Servers matching ${allowedServers.join(",")} are now allowed.`); } if (unallowedServers.length > 0) { - changes.push(`Servers matching ${unallowedServers.join(",")} are no longer allowed`); + changes.push(`Servers matching ${unallowedServers.join(",")} were removed from the allowed list.`); } if (prev.allow_ip_literals !== current.allow_ip_literals) { const allowban = current.allow_ip_literals ? "allowed" : "banned"; - changes.push(`Participating from a server using ip literals is now ${allowban}`); + changes.push(`Participating from a server using an IP literal hostname is now ${allowban}.`); + } + + if (current.allow.length === 0) { + changes = ["Everyone is banned! 🎉"]; } return text + changes.join("\n"); From 12ce7839f3efb7cceb13647304ba92a37d72d157 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 16:36:26 +0100 Subject: [PATCH 04/10] Const things --- src/TextForEvent.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 7368d0577b..6fb9aa0d7b 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -130,11 +130,11 @@ function textForRoomNameEvent(ev) { } function textForServerACLEvent(ev) { - var senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); - let prev_content = ev.getPrevContent(); - let current = ev.getContent(); + const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); + const prev_content = ev.getPrevContent(); + const changes = []; let text = ""; - let changes = []; + let current = ev.getContent(); let prev = { deny: Array.isArray(prev_content.deny) ? prev_content.deny : [], allow: Array.isArray(prev_content.allow) ? prev_content.allow : [], From 1ca164f1a9699ebff180e39599fa05cf3b38f6bf Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 16:36:44 +0100 Subject: [PATCH 05/10] Change all ban message and move further up --- src/TextForEvent.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 6fb9aa0d7b..5d4c14d1b2 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -146,6 +146,11 @@ function textForServerACLEvent(ev) { text = `${senderDisplayName} changed the server ACLs for this room: `; } + /* If we know for sure everyone is banned, don't bother showing the diff view */ + if (current.allow.length === 0) { + return text + "🎉 All servers are banned from participating! This room can no longer be used."; + } + if (!Array.isArray(current.allow)){ current.allow = [] } @@ -182,11 +187,6 @@ function textForServerACLEvent(ev) { changes.push(`Participating from a server using an IP literal hostname is now ${allowban}.`); } - if (current.allow.length === 0) { - changes = ["Everyone is banned! 🎉"]; - } - - return text + changes.join("\n"); } function textForMessageEvent(ev) { From 1db803ccfcfe82be0c47fc0db216ae77864aa236 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 16:37:40 +0100 Subject: [PATCH 06/10] "/n" -> " " --- src/TextForEvent.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 5d4c14d1b2..f2ddae0e0a 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -187,6 +187,7 @@ function textForServerACLEvent(ev) { changes.push(`Participating from a server using an IP literal hostname is now ${allowban}.`); } + return text + changes.join(" "); } function textForMessageEvent(ev) { From 52b1d946be0b599a2023f395c23a15eab00074b1 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 16:37:52 +0100 Subject: [PATCH 07/10] Remove unused console.log --- src/TextForEvent.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index f2ddae0e0a..cc8f48b2e0 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -164,8 +164,6 @@ function textForServerACLEvent(ev) { const allowedServers = current.allow.filter((srv) => typeof(srv) === 'string' && !prev.allow.includes(srv)); const unallowedServers = prev.allow.filter((srv) => typeof(srv) === 'string' && !current.allow.includes(srv)); - console.log(bannedServers,unbannedServers,allowedServers,unallowedServers); - if (bannedServers.length > 0) { changes.push(`Servers matching ${bannedServers.join(",")} are now banned.`); } From 9a4075c6370f087394eb26383c3e4cbdef95ca00 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 16:38:04 +0100 Subject: [PATCH 08/10] Semicolons --- src/TextForEvent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index cc8f48b2e0..bf8d09b06c 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -152,11 +152,11 @@ function textForServerACLEvent(ev) { } if (!Array.isArray(current.allow)){ - current.allow = [] + current.allow = []; } if (!Array.isArray(current.deny)){ - current.deny = [] + current.deny = []; } const bannedServers = current.deny.filter((srv) => typeof(srv) === 'string' && !prev.deny.includes(srv)); From 83221da7d7cdb5895519393f469a5d43ca5103da Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 6 Jul 2018 16:54:28 +0100 Subject: [PATCH 09/10] Delint --- src/TextForEvent.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index bf8d09b06c..2be4e590ec 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -131,15 +131,15 @@ function textForRoomNameEvent(ev) { function textForServerACLEvent(ev) { const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); - const prev_content = ev.getPrevContent(); + const prevContent = ev.getPrevContent(); const changes = []; + const current = ev.getContent(); + const prev = { + deny: Array.isArray(prevContent.deny) ? prevContent.deny : [], + allow: Array.isArray(prevContent.allow) ? prevContent.allow : [], + allow_ip_literals: !(prevContent.allow_ip_literals === false), + }; let text = ""; - let current = ev.getContent(); - let prev = { - deny: Array.isArray(prev_content.deny) ? prev_content.deny : [], - allow: Array.isArray(prev_content.allow) ? prev_content.allow : [], - allow_ip_literals: !(prev_content.allow_ip_literals === false) - } if (prev.deny.length === 0 && prev.allow.length === 0) { text = `${senderDisplayName} set server ACLs for this room: `; } else { @@ -147,15 +147,15 @@ function textForServerACLEvent(ev) { } /* If we know for sure everyone is banned, don't bother showing the diff view */ - if (current.allow.length === 0) { + if (current.allow.length === 0) { return text + "🎉 All servers are banned from participating! This room can no longer be used."; } - if (!Array.isArray(current.allow)){ + if (!Array.isArray(current.allow)) { current.allow = []; } - if (!Array.isArray(current.deny)){ + if (!Array.isArray(current.deny)) { current.deny = []; } From 4044185cddcc51e662e6bb4608e23106047c20ee Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 6 Jul 2018 19:17:01 +0100 Subject: [PATCH 10/10] add space after commas --- src/TextForEvent.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 2be4e590ec..1f4fc68b07 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -165,19 +165,19 @@ function textForServerACLEvent(ev) { const unallowedServers = prev.allow.filter((srv) => typeof(srv) === 'string' && !current.allow.includes(srv)); if (bannedServers.length > 0) { - changes.push(`Servers matching ${bannedServers.join(",")} are now banned.`); + changes.push(`Servers matching ${bannedServers.join(", ")} are now banned.`); } if (unbannedServers.length > 0) { - changes.push(`Servers matching ${unbannedServers.join(",")} were removed from the ban list.`); + changes.push(`Servers matching ${unbannedServers.join(", ")} were removed from the ban list.`); } if (allowedServers.length > 0) { - changes.push(`Servers matching ${allowedServers.join(",")} are now allowed.`); + changes.push(`Servers matching ${allowedServers.join(", ")} are now allowed.`); } if (unallowedServers.length > 0) { - changes.push(`Servers matching ${unallowedServers.join(",")} were removed from the allowed list.`); + changes.push(`Servers matching ${unallowedServers.join(", ")} were removed from the allowed list.`); } if (prev.allow_ip_literals !== current.allow_ip_literals) {