From 56ce432399f3dd72614664d8d9450da41afb46f0 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 8 Oct 2015 10:14:05 +0100 Subject: [PATCH] Get profile tag keys displaying correctly. --- api/client-server/v1/pushrules.yaml | 4 +- specification/modules/push.rst | 81 ------------------- .../matrix_templates/templates/http-api.tmpl | 10 +-- templating/matrix_templates/units.py | 5 +- 4 files changed, 11 insertions(+), 89 deletions(-) diff --git a/api/client-server/v1/pushrules.yaml b/api/client-server/v1/pushrules.yaml index 17061b2d..c9dd777e 100644 --- a/api/client-server/v1/pushrules.yaml +++ b/api/client-server/v1/pushrules.yaml @@ -25,7 +25,7 @@ paths: Retrieve all push rulesets for this user. Clients can "drill-down" on the rulesets by suffixing a ``scope`` to this path e.g. ``/pushrules/global/``. This will return a subset of this data under the - specified key: in this case the ``global`` key. + specified key e.g. the ``global`` key. security: - accessToken: [] responses: @@ -38,7 +38,7 @@ paths: device: type: object title: Devices - description: A dictionary of devices. + description: A dictionary of profile tags to rulesets. additionalProperties: x-pattern: "$PROFILE_TAG" type: object diff --git a/specification/modules/push.rst b/specification/modules/push.rst index 72991565..6411f3df 100644 --- a/specification/modules/push.rst +++ b/specification/modules/push.rst @@ -336,33 +336,6 @@ rules, the rule_id of the rule determines its behaviour. Push Rules: API ~~~~~~~~~~~~~~~ -Rules live under a hierarchy in the REST API that resembles:: - - $PREFIX/pushrules/// - -The component parts are as follows: - -scope - Either 'global' or 'device/' to specify global rules or - device rules for the given profile_tag. -kind - The kind of rule, i.e. 'override', 'underride', 'sender', 'room', 'content'. -rule_id - The identifier for the rule. - -To add or change a rule, a client performs a PUT request to the appropriate URL. -When adding rules of a type that has an ordering, the client can add parameters -that define the priority of the rule: - -before - Use 'before' with a rule_id as its value to make the new rule the next-more - important rule with respect to the given rule. -after - This makes the new rule the next-less important rule relative to the given - rule. - -All requests to the push rules API also require an access_token as a query -parameter. The content of the PUT request is a JSON object with a list of actions under the 'actions' key and either conditions (under the 'conditions' key) or the @@ -391,60 +364,6 @@ To add a custom sound for notifications messages containing the word 'beer' in a curl -X PUT -H "Content-Type: application/json" -d '{ "conditions": [{"kind": "event_match", "key": "content.body", "pattern": "beer" }, {"kind": "room_member_count", "is": "<=10"}], "actions" : ["notify", {"set_sound":"beeroclock.wav"}] }' "http://localhost:8008/_matrix/client/api/v1/pushrules/global/override/U2VlIHlvdSBpbiBUaGUgRHVrZQ?access_token=123456 -To delete rules, a client would just make a DELETE request to the same URL:: - - curl -X DELETE "http://localhost:8008/_matrix/client/api/v1/pushrules/global/room/%23spam%3Amatrix.org?access_token=123456" - - -Retrieving the current ruleset can be done either by fetching individual rules -using the scheme as specified above. This returns the rule in the same format as -would be given in the PUT API with the addition of a rule_id:: - - curl "http://localhost:8008/_matrix/client/api/v1/pushrules/global/room/%23spam%3Amatrix.org?access_token=123456" - -Returns:: - - { - "actions": [ - "dont_notify" - ], - "rule_id": "#spam:matrix.org", - "enabled": true - } - -Clients can also fetch broader sets of rules by removing path components. -Requesting the root level returns a structure as follows:: - - { - "device": { - "exampledevice": { - "content": [], - "override": [], - "room": [ - { - "actions": [ - "dont_notify" - ], - "rule_id": "#spam:matrix.org", - "enabled", true - } - ], - "sender": [], - "underride": [] - } - }, - "global": { - "content": [], - "override": [], - "room": [], - "sender": [], - "underride": [] - } - } - -Adding patch components to the request drills down into this structure to filter -to only the requested set of rules. - Enabling and Disabling Rules ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Rules can be enabled or disabled with a PUT operation to the 'enabled' component diff --git a/templating/matrix_templates/templates/http-api.tmpl b/templating/matrix_templates/templates/http-api.tmpl index f2c3d0b6..33b2cc98 100644 --- a/templating/matrix_templates/templates/http-api.tmpl +++ b/templating/matrix_templates/templates/http-api.tmpl @@ -31,18 +31,18 @@ Response format: {% for table in endpoint.res_tables -%} {{"``"+table.title+"``" if table.title else "" }} -======================= ================= ========================================== - Param Type Description -======================= ================= ========================================== +======================= ========================= ========================================== + Param Type Description +======================= ========================= ========================================== {% for row in table.rows -%} {# -#} {# Row type needs to prepend spaces to line up with the type column (20 ch) -#} {# Desc needs to prepend the required text (maybe) and prepend spaces too -#} {# It also needs to then wrap inside the desc col (42 ch width) -#} {# -#} -{{row.key}}{{row.type|indent(24-row.key|length)}}{{row.desc|wrap(40,row.req_str | indent(18 - (row.type|length))) |indent_block(42)}} +{{row.key}}{{row.type|indent(24-row.key|length)}}{{row.desc|wrap(40,row.req_str | indent(26 - (row.type|length))) |indent_block(50)}} {% endfor -%} -======================= ================= ========================================== +======================= ========================= ========================================== {% endfor %} {% endif -%} diff --git a/templating/matrix_templates/units.py b/templating/matrix_templates/units.py index 1b4b8c7d..24e92f5a 100644 --- a/templating/matrix_templates/units.py +++ b/templating/matrix_templates/units.py @@ -86,7 +86,10 @@ def get_json_schema_object_fields(obj, enforce_title=False): props[key_name]["additionalProperties"], enforce_title=True ) - value_type = "{string: %s}" % nested_object[0]["title"] + key = props[key_name]["additionalProperties"].get( + "x-pattern", "string" + ) + value_type = "{%s: %s}" % (key, nested_object[0]["title"]) if not nested_object[0].get("no-table"): tables += nested_object else: