Was this page helpful?

Create New Role

    Description of the code sample

    The following command creates new role "foo" with permissions listed in file "roles.xml"

    Sample Code

    curl -u admin:password -H "Content-Type: application/xml" -T roles.xml -i http://mindtouch.address/@api/deki/site/roles/=foo

    Implementation notes 

    curl flags

    -u
    Basic HTTP authentication. Sends a username and password to server so it can verify whether a user is of privilege to perform specific operation.
    -H
    Adds a header or modifies an existing one. In this case, since an xml document is being sent, the content type must be set to "application/xml". The server will not accept the request otherwise.
    -T file
    Specifies a PUT command and the .xml file that contains the user data.
    -i
    Includes the HTTP response header in the output. Useful for debugging.

    Permissions

    ADMIN permission is required to execute above command. Otherwise, a 401 HTTP response (Unauthorized) will be returned.

    Example

    We want to add a "Grammar Police" role to our role list and give the role permissions LOGIN, BROWSE, READ, SUBSCRIBE, and UPDATE. File "gproles.xml" contains the list of roles.

    gproles.xml

    Content-Type: application/xml

    <permissions>
        <operations>LOGIN, BROWSE, READ, SUBSCRIBE, UPDATE</operations>
    </permissions>

    Command Line

    curl -u admin:password -H "Content-Type: application/xml" -T gproles.xml -i http://192.168.168.110/@api/deki/site/roles/=Grammar%2520Police

    HTTP Response Headers

    HTTP/1.1 200 OK
    Date: Wed, 13 Jan 2010 19:28:00 GMT
    Server: Dream-HTTPAPI/1.7.2.17433
    X-Deki-Site: id="default"
    Content-Type: application/xml; charset=utf-8
    Content-Length: 183
    Via: 1.1 dekiwiki
    

    HTTP Response Body

    Content-Type: application/xml

    <?xml version="1.0"?>
    <permissions>
      <operations mask="31">LOGIN,BROWSE,READ,SUBSCRIBE,UPDATE</operations>
      <role id="6" href="http://192.168.168.110/@api/deki/site/roles/6">Grammar Police</role>
    </permissions>

    Notes

    • The page path is double encoded. In the above example, the space in "Grammar Police" are replaced with %2520.
    • Running the command again on the same role name will overwrite and replace the existing permissions.
    Was this page helpful?
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by