Hide current folder templates if user doesn't have a folder permission

TemplateList gets a list of templates in a current folder separately,
so we need to make sure `service.get_templates` checks for the
appropriate user permission
This commit is contained in:
Alexey Bezhan
2019-03-07 11:05:44 +00:00
committed by Pea Tyczynska
parent 70e6732255
commit 3d401ce856
2 changed files with 7 additions and 2 deletions

View File

@@ -154,7 +154,12 @@ class Service():
def all_template_ids(self):
return {template['id'] for template in self.all_templates}
def get_templates(self, template_type='all', template_folder_id=None):
def get_templates(self, template_type='all', template_folder_id=None, user_id=None):
if user_id and template_folder_id and self.has_permission('edit_folder_permissions'):
folder = self.get_template_folder(template_folder_id)
if user_id not in folder.get("users_with_permission", []):
return []
if isinstance(template_type, str):
template_type = [template_type]
if template_folder_id:

View File

@@ -40,7 +40,7 @@ class TemplateList():
yield sub_item
for item in self.service.get_templates(
template_type, template_folder_id
template_type, template_folder_id, user_id
):
yield TemplateListTemplate(
item,