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.
``` lang=python, name=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 pageurl 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
# policies can be formatted like "PHID-USER-hmlbd3wfegzjhbpbnoc7", "admin", "users", "PHID-PLCY-6gqsbo7wm3ha5mmsrt5v"
edit_params = transactions = [{
"slug": slug"type": "comment",
"editPolicy": "admin","value": "yeehaa!"
},{
"viewPolicy"type": "PHID-PLCY-6gqsbo7wm3ha5mmsrt5v"
}edit",
edit_result = call_conduit('phriction.edit', edit_params)
# Search for documents using phriction.document.search "value": "admin"
search}]
transaction_params = {
"constraints": {
"paths": ["objectIdentifier": slug[1:] + "/"],
}"transactions": transactions
}
searchedit_result = call_conduit('phriction.document.search'edit', searchtransaction_params)
```
The script above, which tests the extended phriction.document.edit api, can be executed like this:
``` lang=bash
export phorge=http://phorge.local
export api=api-zgjsay4m3vbwx23uy99v5zad5g24
python3 phriction-edit-policy.py $phorge $api
```
The script will change the view and edit policiesy of wiki page `/w/test-1` to admin and a custom policyadd a comment