Skip to content

Commit

Permalink
Collective voice tweaks (#602)
Browse files Browse the repository at this point in the history
* Add option to get private channels only.

Use this as default for Collective Voice first round.

* Update procedures to use the "message" field, not "text"

* use `addslashes` tag, names can have quote chars

* remove preview image for first round

* fix typo with slack.post_message
  • Loading branch information
nickmvincent committed Jun 5, 2023
1 parent a0d7851 commit 5fbe385
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
13 changes: 7 additions & 6 deletions policykit/integrations/slack/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ def make_call(self, method_name, values={}, action=None, method=None):
raise Exception("must provide method_name in values to slack make_call")
return self.metagov_plugin.method(**values)

def get_conversations(self, types=["channel"]):
def get_conversations(self, types=["channel"], types_arg="public_channel"):
"""
acceptable types are "im", "group", "channel"
types_arg is the exact `types` arg that's passed to list.conversations
Allows for asking for private_channel only
"""
def get_channel_type(channel):
if channel.get("is_im", False):
Expand All @@ -169,9 +172,7 @@ def get_channel_type(channel):
else:
return None

# logger.debug("start getting conversations")
response = self.__make_generic_api_call("conversations.list", {})
#logger.debug("get_conversations response: " + str(response))
response = self.__make_generic_api_call("conversations.list", {"types": types_arg})
return [channel for channel in response["channels"] if get_channel_type(channel) in types]

def get_real_users(self):
Expand All @@ -180,7 +181,7 @@ def get_real_users(self):
"""
response = self.__make_generic_api_call("users.list", {})
members = response['members']
ret = [{'value': x['id'], 'name': x['real_name']} for x in members if x['is_bot'] is False and x['name'] != 'slackbot']
ret = [{'value': x['id'], 'name': x.get('real_name', '')} for x in members if x['is_bot'] is False and x['name'] != 'slackbot']
return ret


Expand Down Expand Up @@ -243,7 +244,7 @@ def execution_codes(**kwargs):
message = kwargs.get("message", None)
channel = kwargs.get("channel", None)
thread = kwargs.get("thread", None)
return f"slack.post_message(text={message} channel={channel}, thread_ts={thread}"
return f"slack.post_message(text={message}, channel={channel}, thread_ts={thread})"


class SlackRenameConversation(GovernableAction):
Expand Down
2 changes: 1 addition & 1 deletion policykit/policyengine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def load_entities(platform, get_slack_users=False):
{
"name": channel.get("name", channel["id"]),
"value": channel["id"]
} for channel in platform.get_conversations(types=["channel"])
} for channel in platform.get_conversations(types=["channel"], types_arg="private_channel")
]
if get_slack_users:
entities["SlackUser"] = platform.get_real_users()
Expand Down
40 changes: 20 additions & 20 deletions policykit/policytemplates/procedures.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"notify": [
{
"action": "initiate_vote",
"vote_message": "An expense was submitted to Open Collective and requires a vote. Expense description: {action.description} | Amount: {action.formatted_amount} {action.currency} | Tags: {action.tags} | Payee (OC username): {action.expense_user_slug} | Eligible voters please react with :thumbsup: or :thumbsdown: on this post to vote. See the expense on OpenCollective: {action.url}",
"vote_message": "An expense was submitted to Open Collective and requires a vote. Description: {action.description} | Amount: {action.formatted_amount} {action.currency} | Tags: {action.tags} | Username of payee: {action.expense_user_slug} | Eligible voters please react with :thumbsup: or :thumbsdown: on this post to vote. {action.url} to see the expense on OpenCollective.",
"post_type": "channel",
"users": "variables.users",
"channel": "variables.vote_channel",
"platform": "slack"
},
{
"action": "slackpostmessage",
"text": "Based on our CollectiveVoice policy named {policy.name} (Peer Approval), this expense requires one eligible voter to give a thumbs up for approval.",
"message": "Based on our CollectiveVoice policy named {policy.name} (Peer Approval), this expense requires one eligible voter to give a thumbs up for approval.",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
},
{
"action": "slackpostmessage",
"text": "variables.vote_message",
"message": "variables.vote_message",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand All @@ -38,7 +38,7 @@
},
{
"action": "slackpostmessage",
"text": "Vote passed, Expense was approved!",
"message": "Vote passed, Expense was approved!",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand All @@ -51,7 +51,7 @@
},
{
"action": "slackpostmessage",
"text": "Vote failed, Expense was not approved!",
"message": "Vote failed, Expense was not approved!",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand Down Expand Up @@ -121,21 +121,21 @@
"notify": [
{
"action": "initiate_vote",
"vote_message": "An expense was submitted to Open Collective and requires a vote. Expense description: {action.description} | Amount: {action.formatted_amount} {action.currency} | Tags: {action.tags} | Payee (OC username): {action.expense_user_slug} | Eligible voters please react with :thumbsup: or :thumbsdown: on this post to vote. See the expense on OpenCollective: {action.url}",
"vote_message": "An expense was submitted to Open Collective and requires a vote. Description: {action.description} | Amount: {action.formatted_amount} {action.currency} | Tags: {action.tags} | Username of payee: {action.expense_user_slug} | Eligible voters please react with :thumbsup: or :thumbsdown: on this post to vote. {action.url} to see the expense on OpenCollective.",
"post_type": "channel",
"users": "variables.users",
"channel": "variables.vote_channel",
"platform": "slack"
},
{
"action": "slackpostmessage",
"text": "Based on our CollectiveVoice policy named {policy.name} (Majority Vote), this expense requires a majority of eligible voters to give a thumbs up for approval.",
"message": "Based on our CollectiveVoice policy named {policy.name} (Majority Vote), this expense requires a majority of eligible voters to give a thumbs up for approval.",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
},
{
"action": "slackpostmessage",
"text": "variables.vote_message",
"message": "variables.vote_message",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand All @@ -148,7 +148,7 @@
},
{
"action": "slackpostmessage",
"text": "Vote passed, Expense was approved!",
"message": "Vote passed, Expense was approved!",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand All @@ -161,7 +161,7 @@
},
{
"action": "slackpostmessage",
"text": "Vote failed, Expense was not approved!",
"message": "Vote failed, Expense was not approved!",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand Down Expand Up @@ -231,21 +231,21 @@
"notify": [
{
"action": "initiate_vote",
"vote_message": "An expense was submitted to Open Collective and requires a vote. Expense description: {action.description} | Amount: {action.formatted_amount} {action.currency} | Tags: {action.tags} | Payee (OC username): {action.expense_user_slug} | Eligible voters please react with :thumbsup: or :thumbsdown: on this post to vote. See the expense on OpenCollective: {action.url}",
"vote_message": "An expense was submitted to Open Collective and requires a vote. Description: {action.description} | Amount: {action.formatted_amount} {action.currency} | Tags: {action.tags} | Username of payee: {action.expense_user_slug} | Eligible voters please react with :thumbsup: or :thumbsdown: on this post to vote. {action.url} to see the expense on OpenCollective.",
"post_type": "channel",
"users": "variables.users",
"channel": "variables.vote_channel",
"platform": "slack"
},
{
"action": "slackpostmessage",
"text": "Based on our CollectiveVoice policy named {policy.name} (Consensus), this expense all eligible voters to give a thumbs up for approval.",
"message": "Based on our CollectiveVoice policy named {policy.name} (Consensus), this expense all eligible voters to give a thumbs up for approval.",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
},
{
"action": "slackpostmessage",
"text": "variables.vote_message",
"message": "variables.vote_message",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand All @@ -258,7 +258,7 @@
},
{
"action": "slackpostmessage",
"text": "Vote passed, Expense was approved!",
"message": "Vote passed, Expense was approved!",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand All @@ -271,7 +271,7 @@
},
{
"action": "slackpostmessage",
"text": "Vote failed, Expense was not approved!",
"message": "Vote failed, Expense was not approved!",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand Down Expand Up @@ -341,21 +341,21 @@
"notify": [
{
"action": "initiate_vote",
"vote_message": "An expense was submitted to Open Collective and requires a vote. Expense description: {action.description} | Amount: {action.formatted_amount} {action.currency} | Tags: {action.tags} | Payee (OC username): {action.expense_user_slug} | Eligible voters please react with :thumbsup: or :thumbsdown: on this post to vote. See the expense on OpenCollective: {action.url}",
"vote_message": "An expense was submitted to Open Collective and requires a vote. Description: {action.description} | Amount: {action.formatted_amount} {action.currency} | Tags: {action.tags} | Username of payee: {action.expense_user_slug} | Eligible voters please react with :thumbsup: or :thumbsdown: on this post to vote. {action.url} to see the expense on OpenCollective.",
"post_type": "channel",
"users": "variables.users",
"channel": "variables.vote_channel",
"platform": "slack"
},
{
"action": "slackpostmessage",
"text": "This vote will be based on {policy.name} (Custom Voting)",
"message": "This vote will be based on {policy.name} (Custom Voting)",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
},
{
"action": "slackpostmessage",
"text": "variables.vote_message",
"message": "variables.vote_message",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand All @@ -368,7 +368,7 @@
},
{
"action": "slackpostmessage",
"text": "Vote passed, Expense was approved!",
"message": "Vote passed, Expense was approved!",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand All @@ -381,7 +381,7 @@
},
{
"action": "slackpostmessage",
"text": "Vote failed, Expense was not approved!",
"message": "Vote failed, Expense was not approved!",
"channel": "variables.vote_channel",
"thread": "proposal.vote_post_id"
}
Expand Down
2 changes: 1 addition & 1 deletion policykit/templates/collectivevoice/edit_expenses.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h3 class="heading-3">Define Expenses</h3>
const filter_parameters_dict = JSON.parse('{{filter_parameters | safe}}');
const filters_per_app = JSON.parse('{{filter_modules | safe}}');
console.log(filters_per_app)
const entities = JSON.parse('{{entities|safe}}');
const entities = JSON.parse('{{entities|safe|addslashes}}');
const showFilterParameters = () => {
var selected_options = Array.from(document.getElementById("actionpicker").selectedOptions);
selected_options = selected_options.filter(option => option.value != "none");
Expand Down
2 changes: 1 addition & 1 deletion policykit/templates/collectivevoice/edit_voting.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h4 class="heading-4" id="procedure-name"></h4>
<script>
const procedure_details = JSON.parse('{{procedure_details|safe}}');
const procedures = JSON.parse('{{procedures|safe}}');
const entities = JSON.parse('{{entities|safe}}');
const entities = JSON.parse('{{entities|safe|addslashes}}');

const showProcedureDetails = () => {
var cur_index = parseInt(document.getElementById("procedure-picker").value);
Expand Down
4 changes: 2 additions & 2 deletions policykit/templates/collectivevoice/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ <h2 class="heading-2">
</button>
</div> -->

<div>
<!-- <div>
Preview:
</div>
<div>
<img style="width:300px" src="{% static 'policyengine/img/collectivevoice_preview.png' %}"
alt="Image showing what the vote will look like in Slack">
</div>
</div> -->

<br>
<div>
Expand Down

0 comments on commit 5fbe385

Please sign in to comment.