def get_manage_links(self, view, container_namespace=None, rank=None, total_ranks=None): allowed = [] for action in self.actions: if action[2] and permission.perform_action(self, self.section.path, action[0]): allowed.append(action) if permission.is_admin(self.section.path) and container_namespace: pass elif len(allowed) == 0: return '' for v in self.views: if v[0] == view: view = v[1] break params = { 'content': self, 'view': view, 'can_manage': permission.is_admin(self.section.path), 'container_namespace': container_namespace, 'rank': rank, 'total_ranks': total_ranks, 'allowed_actions': allowed, } return template.snippet('content-permissions', params)
def view_default(self, params): ret = '' add_action = self.actions[0] can_add = permission.perform_action(self, self.section.path, add_action[0]) if can_add: self.section.css.append('container.css') add_link = '<a class="container add" href="/' + self.section.path + '/' + self.namespace + '/' + add_action[ 0] + '/%d">' + add_action[1] + '</a>' for i in range(len(self.content_namespaces)): if can_add: ret += add_link % i item = content.get( self.content_types[i], self.content_paths[i] if self.content_paths[i] else None, self.content_namespaces[i]) if not item: ret += self.get_manage_links( self.content_views[i], self.namespace, i ) + '<div class="status error">Content for this view was deleted</div>' else: ret += item.init(self.section).view( self.content_views[i], params=None, container_namespace=self.namespace, rank=i, total_ranks=len(self.content_namespaces)) if can_add: ret += add_link % len(self.content_namespaces) return ret
def get_action(self): item = content.get_local_else_global(self.path, self.path_namespace) if not item: raise Exception('NotFound') elif not permission.perform_action(item, self.path, self.path_action): raise Exception('Forbidden', self.path, self.path_namespace, self.path_action, self.path_params) return item.init(self)
def view_default(self, params): ret = '' add_action = self.actions[0] can_add = permission.perform_action(self, self.section.path, add_action[0]) if can_add: self.section.css.append('container.css') add_link = '<a class="container add" href="/' + self.section.path + '/' + self.namespace + '/' + add_action[0] + '/%d">' + add_action[1] + '</a>' for i in range(len(self.content_namespaces)): if can_add: ret += add_link % i item = content.get(self.content_types[i], self.content_paths[i] if self.content_paths[i] else None, self.content_namespaces[i]) if not item: ret += self.get_manage_links(self.content_views[i], self.namespace, i) + '<div class="status error">Content for this view was deleted</div>' else: ret += item.init(self.section).view(self.content_views[i], params=None, container_namespace=self.namespace, rank=i, total_ranks=len(self.content_namespaces)) if can_add: ret += add_link % len(self.content_namespaces) return ret
def get_manage_links(self, view, container_namespace=None, rank=None, total_ranks=None): allowed = [] for action in self.actions: if action[2] and permission.perform_action(self, self.section.path, action[0]): allowed.append(action) if permission.is_admin(self.section.path) and container_namespace: pass elif len(allowed) == 0: return "" for v in self.views: if v[0] == view: view = v[1] break params = { "content": self, "view": view, "can_manage": permission.is_admin(self.section.path), "container_namespace": container_namespace, "rank": rank, "total_ranks": total_ranks, "allowed_actions": allowed, } return template.snippet("content-permissions", params)