We have a background task running which creates wiki pages in Phorge using the phriction.create and phriction.edit Conduit API methods.
Some of these wiki pages should only be visible by some users.
Currently phriction.create and phriction.edit can only make fully public wiki pages.
It would be nice if phriction.document.edit could be extended with a viewPolicy and an editPolicy constraint.
phriction-edit-policy.py
import json import requests import sys phabricator_url = sys.argv[1] api_token = sys.argv[2] slug = "test-1/" # edit the wiki url to be tested def call_conduit(method, params): params['__conduit__'] = {'token': api_token} headers = {'Content-Type': 'application/x-www-form-urlencoded'} data = 'params={}&output=json'.format(json.dumps(params)) response = requests.post(f'{phabricator_url}/api/{method}', data=data, headers=headers) response_json = json.loads(response.text) pretty_json = json.dumps(response_json, indent=2) print("Result conduit api call " + method + ":") print(pretty_json) print("") return response_json # Edit the document using phriction.document.edit transactions = [{ "type": "comment", "value": "yeehaa!" },{ "type": "edit", "value": "admin" }] transaction_params = { "objectIdentifier": slug, "transactions": transactions } edit_result = call_conduit('phriction.document.edit', transaction_params)
The script above, which tests the extended phriction.document.edit api, can be executed like this:
export phorge=http://phorge.local export api=api-zgjsay4m3vbwx23uy99v5zad5g24 python3 phriction-edit-policy.py $phorge $api
The script will change the edit policy of wiki page /w/test-1 to admin and add a comment