示例#1
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: add permission to addMember change
        action_1 = client.PermissionResource.add_permission(
            change_type=Changes().Communities.AddMembers,
            actors="{{supplied_fields.addmembers_permission_actors}}",
            roles="{{supplied_fields.addmembers_permission_roles}}")
        action_1.target = "{{context.action.target}}"

        # Step 2: add condition to permission
        permission_data = [{
            "permission_type":
            Changes().Conditionals.Approve,
            "permission_actors":
            "{{nested:context.action.change.member_pk_list}}"
        }, {
            "permission_type":
            Changes().Conditionals.Reject,
            "permission_actors":
            "{{nested:context.action.change.member_pk_list}}"
        }]
        action_2 = client.Conditional.add_condition(
            condition_type="approvalcondition",
            permission_data=permission_data)
        action_2.target = "{{previous.0.result}}"

        return [action_1, action_2]
示例#2
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1 & 2: add addMember permission with anyone set to True and with filter condition to self only
        action_1 = client.PermissionResource.add_permission(
            change_type=Changes().Communities.AddMembers, anyone=True)
        action_1.target = "{{context.action.target}}"
        action_2 = client.Conditional.add_condition(
            condition_type="SelfMembershipFilter", condition_data={})
        action_2.target = "{{previous.0.result}}"

        # Step 3: add condition to permission
        permission_data = [{
            "permission_type":
            Changes().Conditionals.Approve,
            "permission_actors":
            "{{supplied_fields.approve_permission_actors}}",
            "permission_roles":
            "{{supplied_fields.approve_permission_roles}}"
        }]
        action_3 = client.Conditional.add_condition(
            condition_type="approvalcondition",
            permission_data=permission_data)
        action_3.target = "{{previous.0.result}}"

        return [action_1, action_2, action_3]
示例#3
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: create role which will be governing role
        action_1 = client.Community.add_role_to_community(role_name="board")

        # Step 2: add initial people to board
        action_2 = client.Community.add_people_to_role(
            role_name="board",
            people_to_add="{{supplied_fields.initial_board_members}}")

        # Step 3: make 'board' role a governorship role
        action_3 = client.Community.change_governors_of_community(
            roles_to_add=["board"])

        # Step 4: make members an ownership role
        action_4 = client.Community.change_owners_of_community(
            roles_to_add=["members"])

        # Step 5: add vote condition to ownership role
        permission_data = [{
            "permission_type": Changes().Conditionals.AddVote,
            "permission_roles": ["owners"]
        }]
        action_5 = client.Conditional.add_condition(
            condition_type="votecondition",
            leadership_type="owner",
            permission_data=permission_data)

        # Step 6: create role 'membership admins'
        action_6 = client.Community.add_role_to_community(
            role_name="membership admins")

        # Step 7: add initial people to 'membership admins'
        action_7 = client.Community.add_people_to_role(
            role_name="membership admins",
            people_to_add="{{supplied_fields.initial_membership_admins}}")

        # Step 8 & 9: add addMember permission with anyone set to True and self_only set to True
        action_8 = client.PermissionResource.add_permission(
            change_type=Changes().Communities.AddMembers, anyone=True)
        action_9 = client.Conditional.add_condition(
            condition_type="SelfMembershipFilter")
        action_9.target = "{{previous.7.result}}"

        # Step 10: add condition to that permission
        new_permission_data = [{
            "permission_type": Changes().Conditionals.Approve,
            "permission_roles": ["membership admins"]
        }]
        action_10 = client.Conditional.add_condition(
            condition_type="approvalcondition",
            permission_data=new_permission_data)
        action_10.target = "{{previous.7.result}}"

        return [
            action_1, action_2, action_3, action_4, action_5, action_6,
            action_7, action_8, action_9
        ]
示例#4
0
def description_for_passing_approval_condition(permission_data=None):
    """Generate a 'plain English' description for passing the approval condtion."""

    approve_actors = get_permission_value(permission_data,
                                          Changes().Conditionals.Approve,
                                          "actors")
    approve_roles = get_permission_value(permission_data,
                                         Changes().Conditionals.Approve,
                                         "roles")
    reject_actors = get_permission_value(permission_data,
                                         Changes().Conditionals.Reject,
                                         "actors")
    reject_roles = get_permission_value(permission_data,
                                        Changes().Conditionals.Reject, "roles")

    if not approve_roles and not approve_actors:
        return "one person needs to approve this action"

    approve_str = roles_and_actors({
        "roles": approve_roles,
        "actors": approve_actors
    })
    if reject_actors or reject_roles:
        reject_str = f", without {roles_and_actors({'roles': reject_roles, 'actors': reject_actors})} rejecting."
    else:
        reject_str = ""

    return f"{approve_str} needs to approve this action{reject_str}"
示例#5
0
def process_action(action):
    """Method for getting action data.  The action provided is always valid."""

    if action.status == "implemented":
        action_verb = ""
        follow_up = f"They did so because they have the permission {action.approved_through()}."
    else:
        action_verb = "tried to "
        follow_up = ""

    action_time = action.created_at.strftime("%b %d %Y %I:%M%p")
    if action.target:
        action_description = f"{action.change.description_past_tense()} {action.target.get_name()}"
    else:
        action_description = action.change.description_past_tense()

    action_string = f"At {action_time}, {action.actor.username} {action_verb}{action_description}. {follow_up}"

    conditions = Client().Conditional.get_condition_items_for_action(
        action_pk=action.pk)

    is_template = action.change.get_change_type() == Changes(
    ).Actions.ApplyTemplate
    template_info = action.get_template_info()
    if is_template:
        template_info["full_description"] = TemplateModel.objects.get(
            name=template_info["name"]).user_description

    return {
        "action_pk": action.pk,
        "action_target_pk": action.object_id,
        "action_target_model":
        action.target.__class__.__name__,  # will this work???
        "action_target_content_type": action.content_type.pk,
        "description": action.get_description(with_actor=False,
                                              with_target=False),
        "created": str(action.created_at),
        "change_type": action.change.short_name(),
        "display_date": action_time,
        "actor": action.actor.username,
        "actor_pk": action.actor.pk,
        "status": action.status,
        "note": action.note,
        "resolution_passed_by": action.approved_through(),
        "display": action_string,
        "is_template": is_template,
        "template_description": template_info,
        "has_condition": {
            "exists":
            True if conditions else False,
            "conditions": [{
                "pk":
                condition.pk,
                "type":
                condition.__class__.__name__,
                "passing_description":
                condition.description_for_passing_condition()
            } for condition in conditions]
        }
    }
示例#6
0
def get_action_dict(action, fetch_template_actions=False):
    """Helper method to unpack action information to make it readable for vue/javascript.  Note that
    unlike process_action, which is always called regarding existing actions, get_action_dict
    may be passed an invalid action."""

    if action.status == "invalid":
        return {
            "action_status": "invalid",
            "user_message": action.error_message,
            "action_developer_log": action.error_message
        }

    created_statuses = [
        "implemented", "approved", "waiting", "rejected", "propose-req",
        "propose-vol"
    ]
    return {
        "action_created":
        True if action.status in created_statuses else False,
        "action_status":
        action.status,
        "action_pk":
        action.pk,
        "is_template":
        action.change.get_change_type() == Changes().Actions.ApplyTemplate,
        # text
        "action_description":
        action.get_description(with_actor=False, with_target=False),
        "user_message":
        action.rejection_reason(),
        "action_developer_log":
        action.get_logs()
    }
示例#7
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: add 'voting member'
        action_1 = client.Community.add_role_to_community(
            role_name="voting members")
        action_1.target = "{{context.action.target}}"

        # Step 2: make initial people into 'voting members'
        action_2 = client.Community.add_people_to_role(
            role_name="voting members",
            people_to_add="{{supplied_fields.initial_voting_members}}")
        action_2.target = "{{context.action.target}}"

        # Step 3: make 'voting member' role an ownership role
        action_3 = client.Community.change_owners_of_community(
            roles_to_add=["voting members"])
        action_3.target = "{{context.action.target}}"

        # Step 4: add vote condition to ownership role
        permission_data = [{
            "permission_type": Changes().Conditionals.AddVote,
            "permission_roles": ["voting members"]
        }]
        condition_data = {
            "allow_abstain": "{{supplied_fields.allow_abstain}}",
            "require_majority": "{{supplied_fields.require_majority}}",
            "publicize_votes": "{{supplied_fields.publicize_votes}}",
            "voting_period": "{{supplied_fields.voting_period}}"
        }
        action_4 = client.Conditional.add_condition(
            condition_type="votecondition",
            leadership_type="owner",
            condition_data=condition_data,
            permission_data=permission_data)
        action_4.target = "{{context.action.target}}"

        # Step 5: add anyone can join permission
        action_5 = client.PermissionResource.add_permission(
            change_type=Changes().Communities.AddMembers, anyone=True)
        action_5.target = "{{context.action.target}}"
        action_6 = client.Conditional.add_condition(
            condition_type="SelfMembershipFilter", condition_data={})
        action_6.target = "{{previous.4.result}}"

        return [action_1, action_2, action_3, action_4, action_5]
示例#8
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: add 'core team'
        action_1 = client.Community.add_role_to_community(
            role_name="core team")

        # Step 2: make initial people into 'core team'
        action_2 = client.Community.add_people_to_role(
            role_name="core team",
            people_to_add="{{supplied_fields.initial_core_team_members}}")

        # Step 3: make 'core team' role an ownership role
        action_3 = client.Community.change_owners_of_community(
            roles_to_add=["core team"])

        # Step 4: make 'core team' role an governorship role
        action_4 = client.Community.change_governors_of_community(
            roles_to_add=["core team"])

        # Step 5: add approval condition to ownership role
        permission_data = [{
            "permission_type": Changes().Conditionals.Approve,
            "permission_roles": ["core team"]
        }, {
            "permission_type": Changes().Conditionals.Reject,
            "permission_roles": ["core team"]
        }]
        action_5 = client.Conditional.add_condition(
            condition_type="approvalcondition",
            leadership_type="owner",
            permission_data=permission_data)

        # Step 6: add anyone can join permission
        action_6 = client.PermissionResource.add_permission(
            change_type=Changes().Communities.AddMembers, anyone=True)
        action_7 = client.Conditional.add_condition(
            condition_type="SelfMembershipFilter", condition_data={})
        action_7.target = "{{previous.5.result}}"

        return [
            action_1, action_2, action_3, action_4, action_5, action_6,
            action_7
        ]
示例#9
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: template permissions
        action_0 = client.PermissionResource.add_permission(
            change_type=Changes().Actions.ApplyTemplate, roles=["members"])
        action_1 = client.Conditional.add_condition(condition_type="CreatorFilter", condition_data={})
        action_1.target = "{{previous.0.result}}"

        # Step 2: comment permissions
        action_2 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.AddComment, roles=["members"])

        action_3 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.EditComment, roles=["members"])
        action_4 = client.Conditional.add_condition(condition_type="CommenterFilter", condition_data={})
        action_4.target = "{{previous.3.result}}"

        action_5 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.DeleteComment, roles=["members"])
        action_6 = client.Conditional.add_condition(condition_type="CommenterFilter", condition_data={})
        action_6.target = "{{previous.5.result}}"

        # Step 3: list permissions
        action_7 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.AddList, roles=["members"])

        # Step 4: forum & post permissions
        action_8 = client.PermissionResource.add_permission(
            change_type=Changes().Groups.AddForum, roles=["members"])
        action_9 = client.PermissionResource.add_permission(
            change_type=Changes().Groups.AddPost, roles=["members"])

        return [action_0, action_1, action_2, action_3, action_4, action_5, action_6, action_7, action_8, action_9]
示例#10
0
def description_for_passing_voting_condition(condition, permission_data=None):
    """Generate a 'plain English' description for passing the approval condtion."""

    vote_actors = get_permission_value(permission_data,
                                       Changes().Conditionals.AddVote,
                                       "actors")
    vote_roles = get_permission_value(permission_data,
                                      Changes().Conditionals.AddVote, "roles")

    vote_type = "majority" if condition.require_majority else "plurality"

    if vote_roles or vote_actors:
        people_str = roles_and_actors({
            'roles': vote_roles,
            'actors': vote_actors
        })
    else:
        people_str = "people"

    return f"a {vote_type} of {people_str} vote for it within {condition.describe_voting_period()}"
示例#11
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: add addMember permission with anyone set to True and self_only set to True
        action_1 = client.PermissionResource.add_permission(
            change_type=Changes().Communities.AddMembers, anyone=True)
        action_1.target = "{{context.action.target}}"
        action_2 = client.Conditional.add_condition(
            condition_type="SelfMembershipFilter", condition_data={})
        action_2.target = "{{previous.0.result}}"

        return [action_1, action_2]
示例#12
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: create moderator role
        action_0 = client.Community.add_role_to_community(role_name="moderators")
        action_0.target = "{{context.group}}"

        # Step 2: add initial people to role
        action_1 = client.Community.add_people_to_role(
            role_name="moderators", people_to_add="{{supplied_fields.initial_moderators}}")
        action_1.target = "{{context.group}}"

        # Step 3: give moderators permission to delete posts
        action_2 = client.PermissionResource.add_permission(
            change_type=Changes().Groups.DeletePost, roles=["moderators"])

        # Step 4: give moderators permission to delete comments
        action_3 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.DeleteComment, roles=["moderators"])

        return [action_0, action_1, action_2, action_3]
示例#13
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: create commenter role
        action_1 = client.Community.add_role_to_community(
            role_name="commenters")

        # Step 2: set permissions
        action_2 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.AddComment, roles=["commenters"])
        action_3 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.EditComment, roles=["commenters"])
        action_4 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.DeleteComment,
            roles=["commenters"])
        action_5 = client.Conditional.add_condition(
            condition_type="CommenterFilter", condition_data={})
        action_5.target = "{{previous.2.result}}"
        action_6 = client.Conditional.add_condition(
            condition_type="CommenterFilter", condition_data={})
        action_6.target = "{{previous.4.result}}"

        return [action_1, action_2, action_3, action_4, action_5, action_6]
示例#14
0
def description_for_passing_consensus_condition(condition,
                                                permission_data=None):
    """Generate a 'plain English' description for passing the consensus condtion."""

    participate_actors = get_permission_value(
        permission_data,
        Changes().Conditionals.RespondConsensus, "actors")
    participate_roles = get_permission_value(
        permission_data,
        Changes().Conditionals.RespondConsensus, "roles")

    if not participate_roles and not participate_actors:
        consensus_type = "strict" if condition.is_strict else "loose"
        return f"a group of people must agree to it through {consensus_type} consensus"

    participate_str = roles_and_actors({
        "roles": participate_roles,
        "actors": participate_actors
    })

    if condition.is_strict:
        return f"{participate_str} must agree to it with everyone participating and no one blocking"
    else:
        return f"{participate_str} must agree to it with no one blocking"
示例#15
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: give members permission to add row
        action_1 = client.PermissionResource.add_permission(
            roles=['members'], change_type=Changes().Resources.AddRow)

        # Step 2: give members permission to edit list
        action_2 = client.PermissionResource.add_permission(
            roles=['members'], change_type=Changes().Resources.EditList)

        # Step 3: set approval condition on permission
        permission_data = [{
            "permission_type":
            Changes().Conditionals.Approve,
            "permission_actors":
            "{{nested:context.simplelist.creator||to_pk_in_list}}"
        }, {
            "permission_type":
            Changes().Conditionals.Reject,
            "permission_actors":
            "{{nested:context.simplelist.creator||to_pk_in_list}}"
        }]
        action_3 = client.Conditional.add_condition(
            condition_type="approvalcondition",
            permission_data=permission_data)
        action_3.target = "{{previous.1.result}}"

        # Step 4: give members permission to edit row
        action_4 = client.PermissionResource.add_permission(
            roles=['members'], change_type=Changes().Resources.EditRow)

        # Step 5: set approval condition on permission
        action_5 = client.Conditional.add_condition(
            condition_type="approvalcondition",
            permission_data=permission_data)
        action_5.target = "{{previous.3.result}}"

        # Step 6: give members permission to edit row
        action_6 = client.PermissionResource.add_permission(
            roles=['members'], change_type=Changes().Resources.DeleteRow)

        # Step 7: set approval condition on permission
        action_7 = client.Conditional.add_condition(
            condition_type="approvalcondition",
            permission_data=permission_data)
        action_7.target = "{{previous.5.result}}"

        return [
            action_1, action_2, action_3, action_4, action_5, action_6,
            action_7
        ]
示例#16
0
    def get_action_list(self):

        client = self.get_client()

        # Step 1: add permissions for authors to edit or delete their own posts, and add/edit/delete comments

        action_0 = client.PermissionResource.add_permission(change_type=Changes().Groups.EditPost, anyone=True)
        action_0.target = "{{context.action.target}}"
        action_1 = client.Conditional.add_condition(condition_type="CreatorFilter", condition_data={})
        action_1.target = "{{previous.0.result}}"

        action_2 = client.PermissionResource.add_permission(change_type=Changes().Groups.DeletePost, anyone=True)
        action_2.target = "{{context.action.target}}"
        action_3 = client.Conditional.add_condition(condition_type="CreatorFilter", condition_data={})
        action_3.target = "{{previous.2.result}}"

        action_4 = client.PermissionResource.add_permission(change_type=Changes().Resources.EditComment, anyone=True)
        action_4.target = "{{context.action.target}}"
        action_5 = client.Conditional.add_condition(condition_type="CreatorFilter", condition_data={})
        action_5.target = "{{previous.4.result}}"

        action_6 = client.PermissionResource.add_permission(change_type=Changes().Resources.DeleteComment, anyone=True)
        action_6.target = "{{context.action.target}}"
        action_7 = client.Conditional.add_condition(condition_type="CreatorFilter", condition_data={})
        action_7.target = "{{previous.6.result}}"

        action_8 = client.PermissionResource.add_permission(change_type=Changes().Resources.AddComment, anyone=True)
        action_8.target = "{{context.action.target}}"
        action_9 = client.Conditional.add_condition(condition_type="CreatorFilter", condition_data={})
        action_9.target = "{{previous.8.result}}"

        # Step 2: give other people ability to add comments if approved by original poster

        action_10 = client.PermissionResource.add_permission(change_type=Changes().Resources.AddComment, anyone=True)
        action_10.target = "{{context.action.target}}"

        permission_data = [
            {"permission_type": Changes().Conditionals.Approve,
             "permission_actors": "{{nested:context.post.author||to_pk_in_list}}"},
            {"permission_type": Changes().Conditionals.Reject,
             "permission_actors": "{{nested:context.post.author||to_pk_in_list}}"}
        ]
        action_11 = client.Conditional.add_condition(
            condition_type="approvalcondition", permission_data=permission_data)
        action_11.target = "{{previous.10.result}}"

        # Step 3: give other people the ability to edit or delete their own comments IF they are the original commenter
        # AND they are approved by original poster

        action_12 = client.PermissionResource.add_permission(change_type=Changes().Resources.EditComment, anyone=True)
        action_12.target = "{{context.action.target}}"
        action_13 = client.Conditional.add_condition(condition_type="CommenterFilter", condition_data={})
        action_13.target = "{{previous.12.result}}"
        action_14 = client.Conditional.add_condition(
            condition_type="approvalcondition", permission_data=permission_data)  # re-use permission data from before
        action_14.target = "{{previous.12.result}}"

        action_15 = client.PermissionResource.add_permission(
            change_type=Changes().Resources.DeleteComment, anyone=True)
        action_15.target = "{{context.action.target}}"
        action_16 = client.Conditional.add_condition(condition_type="CommenterFilter", condition_data={})
        action_16.target = "{{previous.15.result}}"
        action_17 = client.Conditional.add_condition(
            condition_type="approvalcondition", permission_data=permission_data)  # re-use permission data from before
        action_17.target = "{{previous.15.result}}"

        return [action_0, action_1, action_2, action_3, action_4, action_5, action_6, action_7, action_8, action_9,
                action_10, action_11, action_12, action_13, action_14, action_15, action_16, action_17]
示例#17
0
from concord.utils.helpers import Changes


DEFAULT_PERMISSIONS = {
    "forum": [
        {"change_type": Changes().Groups.AddPost,
         "roles": ["members"]},
        {"change_type": Changes().Resources.AddComment,
         "roles": ["members"]}
    ]
}
示例#18
0
from concord.utils.helpers import Changes


DEFAULT_PERMISSIONS = {
    "community": [
        {"change_type": Changes().Resources.AddComment,
         "roles": ["members"],
         "conditions": [{"condition_type": "TargetTypeFilter", "condition_data": {"target_type": "action"}}]},
        {"change_type": Changes().Actions.ApplyTemplate,
         "roles": ["members"],
         "conditions": [{"condition_type": "CreatorFilter"}]},
        {"change_type": Changes().Communities.AddMembers,
         "anyone": True,
         "conditions": [
            {"condition_type": "approvalcondition",
                "permission_data": [
                    {"permission_type": Changes().Conditionals.Approve, "permission_roles": ["governors"]},
                    {"permission_type": Changes().Conditionals.Reject, "permission_roles": ["governors"]}]},
            {"condition_type": "SelfMembershipOnly"}]}
    ],
    "comment": [
    ]
}