src/pyams_content/shared/common/zmi/__init__.py
changeset 132 ae2a738e3d23
parent 69 8c5bbc396670
child 189 85bbfd8dcd65
equal deleted inserted replaced
131:b113d88d9ee8 132:ae2a738e3d23
    77     def updateWidgets(self, prefix=None):
    77     def updateWidgets(self, prefix=None):
    78         super(SharedContentAddForm, self).updateWidgets(prefix)
    78         super(SharedContentAddForm, self).updateWidgets(prefix)
    79         if 'title' in self.widgets:
    79         if 'title' in self.widgets:
    80             self.widgets['title'].description = _("This title can be modified afterwards")
    80             self.widgets['title'].description = _("This title can be modified afterwards")
    81         if 'notepad' in self.widgets:
    81         if 'notepad' in self.widgets:
       
    82             self.widgets['notepad'].label = IWorkflowCommentInfo['comment'].title
       
    83             self.widgets['notepad'].description = IWorkflowCommentInfo['comment'].description
    82             self.widgets['notepad'].widget_css_class = 'textarea'
    84             self.widgets['notepad'].widget_css_class = 'textarea'
    83 
    85 
    84     def create(self, data):
    86     def create(self, data):
    85         return self.context.shared_content_factory.content_class()
    87         return self.context.shared_content_factory.content_class()
    86 
    88 
   100         content = self.context.shared_content_factory()
   102         content = self.context.shared_content_factory()
   101         self.request.registry.notify(ObjectCreatedEvent(content))
   103         self.request.registry.notify(ObjectCreatedEvent(content))
   102         uuid = self.__uuid = str(uuid4())
   104         uuid = self.__uuid = str(uuid4())
   103         self.context[uuid] = content
   105         self.context[uuid] = content
   104         IWorkflowVersions(content).add_version(wf_content, None)
   106         IWorkflowVersions(content).add_version(wf_content, None)
   105         IWorkflowInfo(wf_content).fire_transition('init')
   107         IWorkflowInfo(wf_content).fire_transition('init', comment=wf_content.notepad)
   106 
   108 
   107     def nextURL(self):
   109     def nextURL(self):
   108         return absolute_url(self.context, self.request, '{0}/++versions++/1/admin'.format(self.__uuid))
   110         return absolute_url(self.context, self.request, '{0}/++versions++/1/admin'.format(self.__uuid))
   109 
   111 
   110 
   112 
   131 class WfSharedContentBreadcrumbAdapter(BreadcrumbItem):
   133 class WfSharedContentBreadcrumbAdapter(BreadcrumbItem):
   132     """Shared content breadcrumb adapter"""
   134     """Shared content breadcrumb adapter"""
   133 
   135 
   134     @property
   136     @property
   135     def label(self):
   137     def label(self):
   136         return II18n(self.context).query_attribute('short_name', request=self.request)
   138         return II18n(self.context).query_attribute('title', request=self.request)
   137 
   139 
   138 
   140 
   139 #
   141 #
   140 # Edit adapters and views
   142 # Edit adapters and views
   141 #
   143 #
   154             return MANAGE_SITE_ROOT_PERMISSION
   156             return MANAGE_SITE_ROOT_PERMISSION
   155         else:
   157         else:
   156             request = check_request()
   158             request = check_request()
   157             if request.has_permission(MANAGE_SITE_ROOT_PERMISSION, self.context):  # webmaster access
   159             if request.has_permission(MANAGE_SITE_ROOT_PERMISSION, self.context):  # webmaster access
   158                 return MANAGE_SITE_ROOT_PERMISSION
   160                 return MANAGE_SITE_ROOT_PERMISSION
       
   161             principal_id = request.principal.id
   159             if state in workflow.manager_states:  # restricted manager access
   162             if state in workflow.manager_states:  # restricted manager access
   160                 if request.principal.id in self.context.managers:
   163                 if principal_id in self.context.managers:
   161                     return PUBLISH_CONTENT_PERMISSION
   164                     return PUBLISH_CONTENT_PERMISSION
   162                 restrictions = IManagerRestrictions(self.context).get_restrictions(request.principal)
   165                 restrictions = IManagerRestrictions(self.context).get_restrictions(principal_id)
   163                 if restrictions and restrictions.check_access(self.context,
   166                 if restrictions and restrictions.check_access(self.context,
   164                                                               permission=PUBLISH_CONTENT_PERMISSION,
   167                                                               permission=PUBLISH_CONTENT_PERMISSION,
   165                                                               request=request):
   168                                                               request=request):
   166                     return PUBLISH_CONTENT_PERMISSION
   169                     return PUBLISH_CONTENT_PERMISSION
   167             else:
   170             else:
   168                 if request.principal.id in self.context.owner | self.context.contributors | self.context.managers:
   171                 if principal_id in self.context.owner | self.context.contributors | self.context.managers:
   169                     return MANAGE_CONTENT_PERMISSION
   172                     return MANAGE_CONTENT_PERMISSION
   170                 restrictions = IManagerRestrictions(self.context).get_restrictions(request.principal)
   173                 restrictions = IManagerRestrictions(self.context).get_restrictions(principal_id)
   171                 if restrictions and restrictions.check_access(self.context,
   174                 if restrictions and restrictions.check_access(self.context,
   172                                                               permission=MANAGE_CONTENT_PERMISSION,
   175                                                               permission=MANAGE_CONTENT_PERMISSION,
   173                                                               request=request):
   176                                                               request=request):
   174                     return MANAGE_CONTENT_PERMISSION
   177                     return MANAGE_CONTENT_PERMISSION
   175         return FORBIDDEN_PERMISSION
   178         return FORBIDDEN_PERMISSION