Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conditionals bug update tests #10

Merged
merged 4 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.6.10, 3.7, 3.8]

services:
postgres:
Expand Down
24 changes: 16 additions & 8 deletions kybern/accounts/templates/accounts/base_vue_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
}

update_actions = function (response, dispatch) {

console.log("Updating actions given response data: ", response.data)
if (response.data.multiple_actions) {
for (index in response.data.actions) {
if (response.data.actions[index].action_pk) {
Expand All @@ -24,6 +26,7 @@
}
} else {
if (response.data.action_pk ) {
console.log("Adding or updating an action: ", response.data.action_pk )
dispatch('addOrUpdateAction', { action_pk: response.data.action_pk })
} else {
console.log("Warning: no action_pk for single!")
Expand All @@ -40,10 +43,12 @@
if (response.data.action_status == "implemented") {
implementationCallback(response)
} else {
throw Error(response.data.action_log)
console.log("Not implemented due to: ", response.data.action_developer_log)
throw response.data.action_log
}

}).catch(error => { console.log("Got error: ", error); throw error })
}).catch(error => {
console.log("Got error: ", error); throw error })
}

const store = new Vuex.Store({
Expand Down Expand Up @@ -388,23 +393,25 @@
state.governor_condition_pk = null
},
REPLACE_ACTIONS_FOR_ITEM (state, data) {
Vue.set(state.actions, data.item_key, data.action_data)
Vue.set(state.actions, data.item_key.toLowerCase(), data.action_data)
},
ADD_OR_UPDATE_ACTION (state, data) {
// Takes in action data and the item_key for the item the action targets

if (!state.actions[data.item_key]) {
Vue.set(state.actions, data.item_key, [])
item_key = data.item_key.toLowerCase()

if (!state.actions[item_key]) {
Vue.set(state.actions, item_key, [])
}

for (index in state.actions[item_key]) {
if (state.actions[data.item_key][index].action_pk == data.action_data.action_pk) {
state.actions[data.item_key].splice(index, 1, data.action_data)
if (state.actions[item_key][index].action_pk == data.action_data.action_pk) {
state.actions[item_key].splice(index, 1, data.action_data)
return
}
}

state.actions[data.item_key].push(data.action_data) // If we get here, we're adding the action
state.actions[item_key].push(data.action_data) // If we get here, we're adding the action
},
ADD_OR_UPDATE_FORUM (state, data) {
for (index in state.forums) {
Expand Down Expand Up @@ -667,6 +674,7 @@
return standard_get_api_call(url, params, implementationCallback, dispatch)
},
addOrUpdateAction ({ commit, state, dispatch}, payload) {
console.log("Action called!")
url = "{{ base_url }}/groups/get_action_data/";
params = { action_pk : payload.action_pk }
implementationCallback = (response) => {
Expand Down
21 changes: 21 additions & 0 deletions kybern/accounts/templates/accounts/error_404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'accounts/base.html' %}

{% block content %}

<div class="col-2"></div>
<div class="col-8">

<h5>The page you requested could not be found</h5>

<form method="post">

<p class="pt-md-3 mt-5">
We're sorry, the page you requested could not be found. If you think it really ought to have
been found, <a href="[email protected]">email us</a> and let us know.
</p>

</div>



{% endblock %}
22 changes: 22 additions & 0 deletions kybern/accounts/templates/accounts/error_500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'accounts/base.html' %}

{% block content %}

<div class="col-2"></div>
<div class="col-8">

<h5>There was a problem with our server</h5>

<form method="post">

<p class="pt-md-3 mt-5">
We're sorry, something happened on our end. If you're willing, please
<a href="[email protected]">email us</a> and let us know what you
were doing just now, so we can try to figure out what went wrong.
</p>

</div>



{% endblock %}
2 changes: 1 addition & 1 deletion kybern/groups/templates/groups/add_role_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
aria-describedby="role_name_prompt" v-model="new_role_name" name="role_name">
</div>

<div class="mb-3 text-warning" v-if="error_message">
<div class="mb-3" v-if="error_message">
[[ error_message ]]
</div>

Expand Down
36 changes: 23 additions & 13 deletions kybern/groups/templates/groups/approve_condition_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<b-form-radio-group id="btn-radios-1" v-model="button_selected" :options="button_options"
buttons name="radios-btn-default" button-variant="outline-primary">
</b-form-radio-group>
<b-button @click="update_conditional">Save</b-button>
<b-button @click="update_conditional" id="save_approve_choice">Save</b-button>
</span>

<span v-else>
Expand All @@ -35,7 +35,7 @@
</span>
</span>

<span v-if="error_message" class="text-danger">[[ error_message ]]</span>
<span v-if="error_message" class="text-danger mt-3">[[ error_message ]]</span>

</span>
</script>
Expand Down Expand Up @@ -78,6 +78,7 @@
},
condition_status: function() {
if (this.condition_details) {
console.log("New status is: ", this.condition_details.status)
return this.condition_details.status
} else {
return null
Expand All @@ -90,10 +91,10 @@
axios = this.prep_axios()
url = "{{ base_url }}/groups/get_conditional_data/"
params = { condition_pk: this.condition_pk, condition_type: this.condition_type }
axios.post(url, params).then(response => {
return axios.post(url, params).then(response => {
this.permission_details = response.data.permission_details
this.condition_details = response.data.condition_details
}).catch(error => { console.log("ERROR in approval dontion get_conditional_data") })
}).catch(error => { console.log(error) })
},
update_conditional() {

Expand All @@ -106,17 +107,26 @@
params = { condition_pk: this.condition_pk, action_to_take: this.button_selected }
axios.post(url, params).then(response => {

new_action_pk = response.data.action_pk

// update condition data
this.get_conditional_data()
this.user_has_taken_action = true

// update action this was a condition on
this.addOrUpdateAction({ action_pk: this.action_details["action_pk"] })

// also call vuex to record this as an action (need to do this for all actions)
this.addOrUpdateAction({ action_pk: response.data.action_pk })

})
this.get_conditional_data().then(response => {

if (this.condition_status == "waiting") {
// In a limited set of circumstances, there may be a condition on a conditional action
// (for instance, if someone is using a governing or owning authority to act)
this.error_message = "Before your decision to " + this.button_selected + " can be implemented, a condition must be satisfied."
} else {
// update action this was a condition on
this.addOrUpdateAction({ action_pk: this.action_details["action_pk"] })
// also call vuex to record this as an action (need to do this for all actions)
this.addOrUpdateAction({ action_pk: new_action_pk })
}

}).catch(error => { console.log("Error refreshing condition data:", error); this.error_message = error })

}).catch(error => { console.log("Error updating condition: ", error); this.error_message = error })

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</div>

<!-- Should be a choice field populated by current roles -->
<div v-if="field.type=='PermissionRoleField'" class="input-group mb-3">
<div v-if="field.type=='PermissionRoleField'" class="input-group mb-3 permissionrolefield">

[[ field.display ]]

Expand All @@ -40,7 +40,7 @@
</div>

<!-- Should be a multiselect field populated by current members -->
<div v-if="field.type=='PermissionActorField'" class="input-group mb-3">
<div v-if="field.type=='PermissionActorField'" class="input-group mb-3 permissionactorfield">

[[ field.display ]]

Expand Down
5 changes: 4 additions & 1 deletion kybern/groups/templates/groups/edit_role_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<b>People with this role can...</b>

<b-list-group v-for="pair in permission_condition_pairs" v-bind:key="pair.permission.id">
<b-list-group-item>
<b-list-group-item :id=pair_element_id(pair.permission.id)>
<div class="btn-group permission-row" role="group" aria-label="Basic example">
<b-button variant="light">
<small class="permission-display">[[ pair.permission.display ]]</small>
Expand Down Expand Up @@ -95,6 +95,9 @@
this.permission_to_edit = permission_id
this.permission_mode_from_parent = 'update'
},
pair_element_id: function(pk) {
return "permission_element_" + pk
},
add_condition(permission_id) {
this.clearState() // clear previous state
this.permission_to_condition = permission_id
Expand Down
7 changes: 4 additions & 3 deletions kybern/groups/templates/groups/manage_condition_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
<span v-if="mode == 'create' && !condition_selected ">
<b>Select condition to add</b>
<template><div>
<b-form-select v-model="condition_selected" :options="condition_options" :select-size="4">
<b-form-select v-model="condition_selected" :options="condition_options" :select-size="4"
name="condition_select">
</b-form-select>
</div></template>
</span>
Expand All @@ -43,9 +44,9 @@

<!-- Save configuration -->
<b-button v-if="condition_selected && mode == 'create'" size="sm"
class="mt-3" @click="add_condition()">Save condition</b-button>
class="mt-3" @click="add_condition()" id="save_condition_button">Save condition</b-button>
<b-button v-if="condition_to_edit && mode == 'update'" size="sm"
class="mt-3" @click="update_condition()">Save changes</b-button>
class="mt-3" @click="update_condition()" id="save_condition_button">Save changes</b-button>

</span>

Expand Down
32 changes: 23 additions & 9 deletions kybern/groups/templates/groups/vote_condition_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<b-form-radio-group id="btn-radios-1" v-model="button_selected" :options="button_options"
buttons name="radios-btn-default" button-variant="outline-primary">
</b-form-radio-group>
<b-button @click="update_condition">Submit</b-button>
<b-button @click="update_condition" id="save_vote_choice">Submit</b-button>

</span>

Expand Down Expand Up @@ -124,7 +124,7 @@
axios = this.prep_axios()
url = "{{ base_url }}/groups/get_conditional_data/"
params = { condition_pk: this.condition_pk, condition_type: this.condition_type }
axios.post(url, params).then(response => {
return axios.post(url, params).then(response => {
this.condition_details = response.data.condition_details
this.permission_details = response.data.permission_details
for (field in this.condition_details.fields) {
Expand All @@ -145,17 +145,31 @@
params = { condition_pk: this.condition_pk, action_to_take: this.button_selected }
axios.post(url, params).then(response => {

new_action_pk = response.data.action_pk

// update condition data
this.get_conditional_data()
this.user_has_taken_action = true
this.get_conditional_data().then(response => {

if (this.condition_details.status == "waiting") {

// In a vote, *usually* the condition is still waiting after a person's taken action,
// because the condition is only resolved after the voting period ends. So we'll need
// a separate way to let people know if their vote isn't cast due to a condition.

} else {

// update action this was a condition on
this.addOrUpdateAction({ action_pk: this.action_details["action_pk"] })

// also call vuex to record this as an action (need to do this for all actions)
this.addOrUpdateAction({ action_pk: new_action_pk })

// update action this was a condition on
this.addOrUpdateAction({ action_pk: this.action_details["action_pk"] })

// also call vuex to record this as an action (need to do this for all actions)
this.addOrUpdateAction({ action_pk: response.data.action_pk })
}

})
}).catch(error => { console.log("Error refreshing condition data:", error); this.error_message = error })

}).catch(error => { console.log("Error updating condition: ", error); this.error_message = error })

}
}
Expand Down
23 changes: 18 additions & 5 deletions kybern/groups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ def get_model(model_name):
pass


readable_log_dict = {
"action did not meet any permission criteria": "You do not have permission to take this action."
}


def make_action_errors_readable(action):
"""If needed, gets or creates both a developer-friendly (detailed) log and a user-friendly log."""

if action.resolution.status in ["accepted", "implemented"]:
return action.resolution.log, action.resolution.log # unlikely to be displayed/accessed
if action.resolution.status == "waiting":
return "This action cannot be completed until a condition is passed.", action.resolution.log
return readable_log_dict.get(action.resolution.log, "We're sorry, there was an error"), action.resolution.log


def process_action(action):

if action.resolution.status == "implemented":
Expand Down Expand Up @@ -81,14 +96,13 @@ def process_action(action):


def get_action_dict(action):
action_log = action.resolution.log
if (not action_log and action.resolution.status == "waiting"):
action_log = "waiting on condition"
display_log, developer_log = make_action_errors_readable(action)
return {
"action_created": True if action.resolution.status in ["implemented", "approved", "waiting", "rejected"] else False,
"action_status": action.resolution.status,
"action_log": action_log,
"action_pk": action.pk,
"action_log": display_log,
"action_developer_log": developer_log
}


Expand Down Expand Up @@ -472,7 +486,6 @@ def delete_post(request, target):

action_dict = get_action_dict(action)
action_dict["deleted_post_pk"] = pk
print(action_dict)
return JsonResponse(action_dict)


Expand Down
2 changes: 1 addition & 1 deletion kybern/mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


ALLOWED_HOSTS = ['127.0.0.1', 'kybern.herokuapp.com']
ALLOWED_HOSTS = ['127.0.0.1', 'kybern.herokuapp.com', 'www.kybern.org']


# Application definition
Expand Down
Loading