From 595667d15dbbe9c1e8580ea62e8095be3f0dbb2f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 3 Mar 2018 14:46:40 -0700 Subject: [PATCH 1/8] Spec /directory/list Adds https://github.com/matrix-org/matrix-doc/issues/417 Signed-off-by: Travis Ralston --- api/client-server/list_public_rooms.yaml | 111 ++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/api/client-server/list_public_rooms.yaml b/api/client-server/list_public_rooms.yaml index 6d25a1ac2..4d3923bd1 100644 --- a/api/client-server/list_public_rooms.yaml +++ b/api/client-server/list_public_rooms.yaml @@ -13,7 +13,7 @@ # limitations under the License. swagger: '2.0' info: - title: "Matrix Client-Server Room Creation API" + title: "Matrix Client-Server Room Directory API" version: "1.0.0" host: localhost:8008 schemes: @@ -25,6 +25,115 @@ consumes: produces: - application/json paths: + "/directory/list/room/{roomId}": + get: + summary: Gets the visibility of a room in the directory + description: |- + Gets the visibility of a given room on the server's public room directory. + operationId: getRoomVisibilityOnDirectory + security: + - accessToken: [] + parameters: + - in: path + type: string + name: roomId + description: The room ID. + required: true + x-example: "!curbf:matrix.org" + responses: + 200: + description: The visibility of the room in the directory + schema: + type: object + properties: + visibility: + type: string + enum: ['private', 'public'] + description: The visibility of the room in the directory. + examples: + application/json: { + "visibility": "public" + } + 400: + description: The room is not known to the server + examples: + application/json: { + "errcode": "M_UNKNOWN", + "error": "Room not found" + } + put: + summary: Sets the visibility of a room in the room directory + description: |- + Sets the visibility of a given room in the server's public room + directory. + operationId: setRoomVisibilityOnDirectory + security: + - accessToken: [] + parameters: + - in: path + type: string + name: roomId + description: The room ID. + required: true + x-example: "!curbf:matrix.org" + - in: body + name: body + required: true + description: |- + The new visibility for the room on the room directory. + schema: + type: object + properties: + visibility: + type: string + enum: ["private", "public"] + description: |- + The new visibility setting for the room. + Defaults to 'public'. + example: { + "visibility": "public" + } + responses: + 200: + description: The visibility was updated, or no change was needed. + examples: + application/json: { + } + 400: + description: The room is not known to the server + examples: + application/json: { + "errcode": "M_UNKNOWN", + "error": "Room not found" + } + delete: + summary: Sets a room to be private on the room directory + description: |- + Updates the visibility of a room to be private on the server's room + directory. + operationId: setRoomPrivateOnDirectory + security: + - accessToken: [] + parameters: + - in: path + type: string + name: roomId + description: The room ID. + required: true + x-example: "!curbf:matrix.org" + responses: + 200: + description: The visibility was updated, or no change was needed. + examples: + application/json: { + } + 400: + description: The room is not known to the server + examples: + application/json: { + "errcode": "M_UNKNOWN", + "error": "Room not found" + } "/publicRooms": get: summary: Lists the public rooms on the server. From b41bd9635db85c38966195ecd52f927fc5f1cdb9 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 3 Mar 2018 14:50:19 -0700 Subject: [PATCH 2/8] Add /directory/list to changelog Signed-off-by: Travis Ralston --- changelogs/client_server.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelogs/client_server.rst b/changelogs/client_server.rst index d86aeb63e..70bc2bd27 100644 --- a/changelogs/client_server.rst +++ b/changelogs/client_server.rst @@ -19,6 +19,8 @@ Unreleased changes (`#1106 `_). - Clarify default values for some fields on the /search API (`#1109 `_). + - Add the room visibility options for the room directory + (`#1141 Date: Mon, 5 Mar 2018 18:45:57 -0700 Subject: [PATCH 3/8] Remove extraneous comma from m.presence schema This causes the build to fail. Fixes #1146 Signed-off-by: Travis Ralston --- event-schemas/examples/m.presence | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/event-schemas/examples/m.presence b/event-schemas/examples/m.presence index bdc0baea1..824ffcb71 100644 --- a/event-schemas/examples/m.presence +++ b/event-schemas/examples/m.presence @@ -3,7 +3,7 @@ "avatar_url": "mxc://localhost:wefuiwegh8742w", "last_active_ago": 2478593, "presence": "online", - "currently_active": false, + "currently_active": false }, "sender": "@example:localhost", "type": "m.presence" From a36bd1a6d2f8d10d908764af7177e7e6a1aa21b4 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 6 Mar 2018 11:02:40 +0000 Subject: [PATCH 4/8] Make build fail if gendoc fails (cf https://github.com/matrix-org/matrix-doc/issues/1146) --- scripts/generate-matrix-org-assets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/generate-matrix-org-assets b/scripts/generate-matrix-org-assets index 2f8acc5d2..cb3cf4552 100755 --- a/scripts/generate-matrix-org-assets +++ b/scripts/generate-matrix-org-assets @@ -2,6 +2,8 @@ # # generate a tarball of assets suitable for the matrix.org site +set -e + cd `dirname $0`/.. mkdir -p assets From 9150ba0dce83a4273e25001d1461d02d8c114ea2 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 6 Mar 2018 11:09:33 +0000 Subject: [PATCH 5/8] Improve error output from failing to parse examples --- scripts/templating/matrix_templates/units.py | 28 +++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/templating/matrix_templates/units.py b/scripts/templating/matrix_templates/units.py index 1540a7fd5..d8cfe1e34 100644 --- a/scripts/templating/matrix_templates/units.py +++ b/scripts/templating/matrix_templates/units.py @@ -694,15 +694,25 @@ class MatrixUnits(Units): for filename in os.listdir(path): if not filename.startswith("m."): continue - with open(os.path.join(path, filename), "r") as f: - event_name = filename.split("#")[0] - example = json.loads(f.read()) - - examples[filename] = examples.get(filename, []) - examples[filename].append(example) - if filename != event_name: - examples[event_name] = examples.get(event_name, []) - examples[event_name].append(example) + + event_name = filename.split("#")[0] + filepath = os.path.join(path, filename) + logger.info("Reading event example: %s" % filepath) + try: + with open(filepath, "r") as f: + example = json.load(f) + examples[filename] = examples.get(filename, []) + examples[filename].append(example) + if filename != event_name: + examples[event_name] = examples.get(event_name, []) + examples[event_name].append(example) + except Exception, e: + e2 = Exception("Error reading event example "+filepath+": "+ + str(e)) + # throw the new exception with the old stack trace, so that + # we don't lose information about where the error occurred. + raise e2, None, sys.exc_info()[2] + return examples def load_event_schemas(self): From 709fca81905cc966a7f32149ddce3bbca6afeff3 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 6 Mar 2018 08:50:23 -0700 Subject: [PATCH 6/8] Move /directory/list changelog entry Signed-off-by: Travis Ralston --- changelogs/client_server.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelogs/client_server.rst b/changelogs/client_server.rst index d5c7d048b..80927b544 100644 --- a/changelogs/client_server.rst +++ b/changelogs/client_server.rst @@ -23,13 +23,13 @@ Unreleased changes (`#1137 `_). - Clarify that ``m.tag`` ordering is done with numbers, not strings (`#1139 `_). - - Add the room visibility options for the room directory - (`#1141 `_). + - Add the room visibility options for the room directory + (`#1141 `_). r0.3.0 ====== From 5cbfa73fe40fa0996f2034f1715f3e63377b9d21 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 6 Mar 2018 08:51:57 -0700 Subject: [PATCH 7/8] Improve documentation of /directory/list * 404 for room not found instead of 400 * GET doesn't require an access token * PUT (and therefore DELETE) can have it's own access control checks * DELETE is implemented because of synapse Signed-off-by: Travis Ralston --- api/client-server/list_public_rooms.yaml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/api/client-server/list_public_rooms.yaml b/api/client-server/list_public_rooms.yaml index 4d3923bd1..e6d2616cc 100644 --- a/api/client-server/list_public_rooms.yaml +++ b/api/client-server/list_public_rooms.yaml @@ -31,8 +31,6 @@ paths: description: |- Gets the visibility of a given room on the server's public room directory. operationId: getRoomVisibilityOnDirectory - security: - - accessToken: [] parameters: - in: path type: string @@ -54,11 +52,11 @@ paths: application/json: { "visibility": "public" } - 400: + 404: description: The room is not known to the server examples: application/json: { - "errcode": "M_UNKNOWN", + "errcode": "M_NOT_FOUND", "error": "Room not found" } put: @@ -66,6 +64,10 @@ paths: description: |- Sets the visibility of a given room in the server's public room directory. + + Servers may choose to implement additional access control checks + here, for instance that room visibility can only be changed by + the room creator or a server administrator. operationId: setRoomVisibilityOnDirectory security: - accessToken: [] @@ -99,18 +101,19 @@ paths: examples: application/json: { } - 400: + 404: description: The room is not known to the server examples: application/json: { - "errcode": "M_UNKNOWN", + "errcode": "M_NOT_FOUND", "error": "Room not found" } delete: summary: Sets a room to be private on the room directory description: |- Updates the visibility of a room to be private on the server's room - directory. + directory. This is the same as using the PUT operation with a private + as the visibility. operationId: setRoomPrivateOnDirectory security: - accessToken: [] @@ -127,11 +130,11 @@ paths: examples: application/json: { } - 400: + 404: description: The room is not known to the server examples: application/json: { - "errcode": "M_UNKNOWN", + "errcode": "M_NOT_FOUND", "error": "Room not found" } "/publicRooms": From d88a1308c2e9a6075346b91fd79d714bde30f0a5 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 6 Mar 2018 10:05:32 -0700 Subject: [PATCH 8/8] Formatting and remove DELETE /directory/list Signed-off-by: Travis Ralston --- api/client-server/list_public_rooms.yaml | 52 +++++------------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/api/client-server/list_public_rooms.yaml b/api/client-server/list_public_rooms.yaml index e6d2616cc..334d528c3 100644 --- a/api/client-server/list_public_rooms.yaml +++ b/api/client-server/list_public_rooms.yaml @@ -50,15 +50,15 @@ paths: description: The visibility of the room in the directory. examples: application/json: { - "visibility": "public" - } + "visibility": "public" + } 404: description: The room is not known to the server examples: application/json: { - "errcode": "M_NOT_FOUND", - "error": "Room not found" - } + "errcode": "M_NOT_FOUND", + "error": "Room not found" + } put: summary: Sets the visibility of a room in the room directory description: |- @@ -93,50 +93,20 @@ paths: The new visibility setting for the room. Defaults to 'public'. example: { - "visibility": "public" - } + "visibility": "public" + } responses: 200: description: The visibility was updated, or no change was needed. examples: - application/json: { - } + application/json: {} 404: description: The room is not known to the server examples: application/json: { - "errcode": "M_NOT_FOUND", - "error": "Room not found" - } - delete: - summary: Sets a room to be private on the room directory - description: |- - Updates the visibility of a room to be private on the server's room - directory. This is the same as using the PUT operation with a private - as the visibility. - operationId: setRoomPrivateOnDirectory - security: - - accessToken: [] - parameters: - - in: path - type: string - name: roomId - description: The room ID. - required: true - x-example: "!curbf:matrix.org" - responses: - 200: - description: The visibility was updated, or no change was needed. - examples: - application/json: { - } - 404: - description: The room is not known to the server - examples: - application/json: { - "errcode": "M_NOT_FOUND", - "error": "Room not found" - } + "errcode": "M_NOT_FOUND", + "error": "Room not found" + } "/publicRooms": get: summary: Lists the public rooms on the server.