Merge pull request #2856 from alphagov/edit-members-who-see-folder

Edit members who see folder
This commit is contained in:
Pea (Malgorzata Tyczynska)
2019-03-19 14:11:59 +00:00
committed by GitHub
7 changed files with 125 additions and 32 deletions

View File

@@ -1285,6 +1285,15 @@ class ReturnedLettersForm(StripWhitespaceForm):
class TemplateFolderForm(StripWhitespaceForm):
def __init__(self, all_service_users=None, *args, **kwargs):
super().__init__(*args, **kwargs)
if all_service_users is not None:
self.users_with_permission.all_service_users = all_service_users
self.users_with_permission.choices = [
(item.id, item.name) for item in all_service_users
]
users_with_permission = MultiCheckboxField('Users who can see this folder:')
name = StringField('Folder name', validators=[DataRequired(message='Cant be empty')])

View File

@@ -430,14 +430,19 @@ def action_blocked(service_id, notification_type, return_to, template_id):
@login_required
@user_has_permissions('manage_templates')
def manage_template_folder(service_id, template_folder_id):
current_folder = current_service.get_template_folder(template_folder_id)
form = TemplateFolderForm(
name=current_service.get_template_folder(template_folder_id)['name']
name=current_folder['name'],
users_with_permission=current_folder.get('users_with_permission', None),
all_service_users=[user for user in current_service.active_users if user.id != current_user.id]
)
if form.validate_on_submit():
users_with_permission = form.users_with_permission.data + [current_user.id]
template_folder_api_client.update_template_folder(
current_service.id, template_folder_id, name=form.name.data
current_service.id,
template_folder_id,
name=form.name.data,
users_with_permission=users_with_permission
)
return redirect(
url_for('.choose_template', service_id=service_id, template_folder_id=template_folder_id)
@@ -449,7 +454,7 @@ def manage_template_folder(service_id, template_folder_id):
template_folder_path=current_service.get_template_folder_path(template_folder_id),
current_service_id=current_service.id,
template_folder_id=template_folder_id,
template_type="all"
template_type="all",
)

View File

@@ -42,10 +42,13 @@ class TemplateFolderAPIClient(NotifyAdminAPIClient):
))
@cache.delete('service-{service_id}-template-folders')
def update_template_folder(self, service_id, template_folder_id, name):
def update_template_folder(self, service_id, template_folder_id, name, users_with_permission=None):
data = {"name": name}
if users_with_permission:
data["users_with_permission"] = users_with_permission
self.post(
'/service/{}/template-folder/{}'.format(service_id, template_folder_id),
{"name": name}
data
)
@cache.delete('service-{service_id}-template-folders')

View File

@@ -1,4 +1,4 @@
{% from "components/select-input.html" import select_nested %}
{% from "components/select-input.html" import select_nested, select %}
{% macro checkbox(
field,
@@ -20,7 +20,12 @@
{% macro checkboxes_nested(field, child_map, hint=None, disable=[], option_hints={}, hide_legend=False) %}
{{ select_nested(field, child_map, hint=None, disable=[], option_hints={}, hide_legend=False, input="checkbox") }}
{{ select_nested(field, child_map, hint, disable, option_hints, hide_legend, input="checkbox") }}
{% endmacro %}
{% macro checkboxes(field, hint=None, disable=[], option_hints={}, hide_legend=False) %}
{{ select(field, hint, disable, option_hints, hide_legend, input="checkbox") }}
{% endmacro %}
@@ -39,17 +44,3 @@
<label></label>
</div>
{% endmacro %}
{% macro checkbox_group(
legend,
fields
) %}
<fieldset class="form-group">
<legend class="form-label">
{{ legend }}
</legend>
{% for field in fields %}
{{ checkbox(field) }}
{% endfor %}
</fieldset>
{% endmacro %}

View File

@@ -1,6 +1,7 @@
{% extends "withnav_template.html" %}
{% from "components/folder-path.html" import folder_path, page_title_folder_path %}
{% from "components/textbox.html" import textbox %}
{% from "components/checkbox.html" import checkbox, checkboxes %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/form.html" import form_wrapper %}
@@ -23,6 +24,10 @@
{% call form_wrapper(action=url_for('main.manage_template_folder', service_id=current_service.id, template_folder_id=template_folder_id)) %}
{{ textbox(form.name) }}
{% if current_service.has_permission("edit_folder_permissions") %}
{{ checkboxes(form.users_with_permission) }}
{% endif %}
{{ page_footer(
'Save',
delete_link=url_for(