Example #1
0
def test_parse_permissions():
    tests = [
        (
            "*****@*****.**",
            {
                "value": "*****@*****.**",
                "perm_type": "user",
                "role": "reader",
            },
        ),
        (
            "aiguofer.com|owner",
            {"value": "aiguofer.com", "perm_type": "domain", "role": "owner"},
        ),
        ("anyone|writer", {"perm_type": "anyone", "role": "writer"}),
        (
            "[email protected]|no",
            {
                "value": "*****@*****.**",
                "perm_type": "user",
                "role": "reader",
                "notify": False,
            },
        ),
        ("anyone|link", {"perm_type": "anyone", "role": "reader", "with_link": True}),
    ]

    for test in tests:
        assert util.parse_permission(test[TEST]) == test[ANSWER]
Example #2
0
    def add_permission(self, permission):
        """
        Add a permission to the current spreadsheet.

        The format should be:
        ``<id>|(<group>)|(<role>)|(<notify>)|(<require_link>)`` where:

        <id> - email address of group or individual, domain, or 'anyone'
        <group> - optional, if the id is a group e-mail, this needs to be 'group' or
            'grp'
        <role> - optional, one of 'owner', 'writer', or 'reader'. If ommited, 'reader'
            will be used
        <notify> - optional, if you don't want to notify the user, pass 'no' or 'false'
        <require_link> - optional, if you want to require the user to have the link,
            pass 'link'

        For example, to allow anyone with a link in the group [email protected] to
        write when they have a link, but without sending a notification to the group:
        ``[email protected]|grp|owner|false|link``

        Or if you want to give [email protected] reader permissions without a
        notification:
        ``[email protected]|no``

        Or to give anyone read access:
        ``anyone``

        Parameters
        ----------
        permissions : string
            A strings meeting the above mentioned format.


        Returns
        -------
        None
        """
        perm = parse_permission(permission)
        self.client.insert_permission(self.spread.id, perm.pop("value", None),
                                      **perm)