sobjects/notification.py
changeset 4230 6514a76eaa5c
parent 4023 eae23c40627a
child 4252 6c4f109c2b03
equal deleted inserted replaced
4229:1c8e92afb94b 4230:6514a76eaa5c
   144 url: %(url)s
   144 url: %(url)s
   145 """
   145 """
   146 
   146 
   147     def context(self, **kwargs):
   147     def context(self, **kwargs):
   148         context = super(EntityUpdatedNotificationView, self).context(**kwargs)
   148         context = super(EntityUpdatedNotificationView, self).context(**kwargs)
   149         changes = self.req.transaction_data['changes'][self.rset[0][0]]
   149         changes = self._cw.transaction_data['changes'][self.cw_rset[0][0]]
   150         _ = self.req._
   150         _ = self._cw._
   151         formatted_changes = []
   151         formatted_changes = []
   152         entity = self.entity(self.row or 0, self.col or 0)
   152         entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
   153         for attr, oldvalue, newvalue in sorted(changes):
   153         for attr, oldvalue, newvalue in sorted(changes):
   154             # check current user has permission to see the attribute
   154             # check current user has permission to see the attribute
   155             rschema = self.vreg.schema[attr]
   155             rschema = self._cw.vreg.schema[attr]
   156             if rschema.final:
   156             if rschema.final:
   157                 rdef = entity.e_schema.rdef(rschema)
   157                 rdef = entity.e_schema.rdef(rschema)
   158                 if not rdef.has_perm(self.req, 'read', eid=self.rset[0][0]):
   158                 if not rdef.has_perm(self._cw, 'read', eid=self.cw_rset[0][0]):
   159                     continue
   159                     continue
   160             # XXX suppose it's a subject relation...
   160             # XXX suppose it's a subject relation...
   161             elif not rschema.has_perm(self.req, 'read', fromeid=self.rset[0][0]): # XXX toeid
   161             elif not rschema.has_perm(self._cw, 'read', fromeid=self.cw_rset[0][0]): # XXX toeid
   162                 continue
   162                 continue
   163             if attr in self.no_detailed_change_attrs:
   163             if attr in self.no_detailed_change_attrs:
   164                 msg = _('%s updated') % _(attr)
   164                 msg = _('%s updated') % _(attr)
   165             elif oldvalue not in (None, ''):
   165             elif oldvalue not in (None, ''):
   166                 msg = _('%(attr)s updated from %(oldvalue)s to %(newvalue)s') % {
   166                 msg = _('%(attr)s updated from %(oldvalue)s to %(newvalue)s') % {
   176             raise SkipEmail()
   176             raise SkipEmail()
   177         context['changes'] = '\n'.join(formatted_changes)
   177         context['changes'] = '\n'.join(formatted_changes)
   178         return context
   178         return context
   179 
   179 
   180     def subject(self):
   180     def subject(self):
   181         entity = self.entity(self.row or 0, self.col or 0)
   181         entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
   182         return  u'%s #%s (%s)' % (self.req.__('Updated %s' % entity.e_schema),
   182         return  u'%s #%s (%s)' % (self._cw.__('Updated %s' % entity.e_schema),
   183                                   entity.eid, self.user_data['login'])
   183                                   entity.eid, self.user_data['login'])
   184 
   184 
   185 
   185 
   186 from logilab.common.deprecation import class_renamed, class_moved, deprecated
   186 from logilab.common.deprecation import class_renamed, class_moved, deprecated
   187 from cubicweb.hooks.notification import RenderAndSendNotificationView
   187 from cubicweb.hooks.notification import RenderAndSendNotificationView