def _check_permission(self, perm):
     sm = getSecurityManager()
     if not sm.checkPermission(perm, self.context):
         portal_state = getMultiAdapter(
             (self.context, self.request), name=u'plone_portal_state')
         member = portal_state.member()
         logging.error(
             'Failed permission check. Required Permission "%s", user "%s"',
             perm, member)
         raise Unauthorized(_('You do not have the required permission'))
     return True
Esempio n. 2
0
 def _check_permission(self, perm):
     sm = getSecurityManager()
     if not sm.checkPermission(perm, self.context):
         portal_state = getMultiAdapter((self.context, self.request),
                                        name=u'plone_portal_state')
         member = portal_state.member()
         logging.error(
             'Failed permission check. Required Permission "%s", user "%s"',
             perm, member)
         raise Unauthorized(_('You do not have the required permission'))
     return True
Esempio n. 3
0
class NoticeBoardSettingsForm(group.GroupForm, form.EditForm):
    """ The page that holds all the noticeboard settings
    """

    fields = field.Fields(INothing)
    groups = [MainSettingsGroup]

    label = _(u'heading_noticeboard_settings_form',
              default=u'Noticeboard')
    description = _(u'description_noticeboard_settings_form',
                    default=u'Configure the settings of this noticeboard.')
    successMessage = _(u'successMessage_noticeboard_settings_form',
                       default=u'Noticeboard settings saved.')
    noChangesMessage = _(
        u'noChangesMessage_noticeboard_settings_form',
        default=u'There are no changes in the Noticeboard settings.')

    def add_fields_to_group(self, type_, groupname):
        group = None
        for g in self.groups:
            if groupname == g.label:
                group = g

        if group is None:
            g = plonegroup.GroupFactory(groupname,
                                        field.Fields(type_.schema))
            self.groups.append(g)
        else:
            fields = field.Fields(type_.schema)
            toadd = []
            for f in fields._data_values:
                if f.__name__ not in group.fields.keys():
                    toadd.append(f)

            group.fields = field.Fields(group.fields, *toadd)

    def update(self):
        super(NoticeBoardSettingsForm, self).update()

    def set_status_message(self, settings, has_changes):
        msg = has_changes and self.successMessage \
            or self.noChangesMessage
        msg = zope.i18n.translate(msg)

        self.status = msg

    @button.buttonAndHandler(_('Apply'), name='apply')
    def handleApply(self, action):
        (data, errors) = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        changes = self.applyChanges(data)
        settings = NoticeboardSettings(self.context)

        has_changes = False
        if changes:
            settings = NoticeboardSettings(self.context)
            has_changes = True

        self.set_status_message(settings, has_changes)
        return self.request.response.redirect(self.context.absolute_url())
Esempio n. 4
0
class MainSettingsGroup(plonegroup.Group):

    fields = field.Fields(INoticeboardSettings)
    label = _(u'Main')
Esempio n. 5
0
    def __call__(self):  # noqa
        self.request.response.setHeader('Content-Type',
                                        'application/json; charset=utf-8')
        self.request.response.setHeader('Expires', '-1')
        self.request.response.setHeader('Cache-Control', 'private')
        retval = []
        new = []
        max_zindex = 0
        items = self.contents()
        check_perm = getSecurityManager().checkPermission
        delete_url = None
        settings = NoticeboardSettings(self.context)
        hide_after = settings.hide_after_days
        if hide_after:
            limit = datetime.now() - timedelta(days=hide_after)
        for item in items:
            if isinstance(item, CatalogContentListingObject):
                item = item.getObject()
            item = aq_inner(item)
            if hide_after:
                # ignore items that are older than the limit
                modified = item.modified().utcdatetime()
                if modified <= limit:
                    continue
            if isinstance(item.exclude_from_nav, bool):
                if item.exclude_from_nav:
                    continue
            else:
                if item.exclude_from_nav():
                    continue
            actions = []
            note = INote(item)
            if check_perm(permissions.ModifyPortalContent, item):
                if note.review_state == 'private':
                    actions.append(
                        dict(content=self.context.translate(PMF('Publish')),
                             title="",
                             class_='publish',
                             url=item.absolute_url() +
                             '/content_status_modify?workflow_action=publish'))
        # alternatively use a popup with the form from /content_status_history

                actions.append(
                    dict(content=self.context.translate(_('Color')),
                         title=self.context.translate(_("Change color")),
                         class_='change_color',
                         url=item.absolute_url() + '/change_color'))
                actions.append(
                    dict(content=self.context.translate(PMF('Edit')),
                         title='',
                         class_='edit',
                         url=item.absolute_url() + '/edit'))

            if check_perm(permissions.DeleteObjects, item):
                delete_url = item.absolute_url() \
                    + '/delete_confirmation'
                actions.append(
                    dict(content=self.context.translate(PMF('Delete')),
                         title='',
                         class_='delete',
                         url=delete_url))
            notedata = note.jsonable
            try:
                max_zindex = max(max_zindex, int(note.zIndex))
            except ValueError:
                new.append(notedata)
            notedata.update(dict(hasactions=bool(actions)))
            notedata.update(dict(actions=actions))

            if delete_url:
                notedata.update(dict(delete_url=delete_url))
                are_you_sure = self.context.translate(_('Are you sure'))
                notedata.update(dict(are_you_sure=are_you_sure))
            retval.append(notedata)
        for (new_note, new_index) in zip(
                new, range(max_zindex + 1, max_zindex + len(new) + 1)):
            new_note['zIndex'] = new_index
        return json.dumps(retval)
Esempio n. 6
0

class NoticeboardArchive(NoticeboardNotes):
    """ A listing-view of all outdated items
    """
    def __call__(self):
        """ Render the content item listing.
        """

        notes = []
        items = self.contents()
        settings = NoticeboardSettings(self.context)
        hide_after = settings.hide_after_days
        if not hide_after:
            self.contents = ""
            return self.index()
        limit = datetime.now() - timedelta(days=hide_after)
        for item in items:
            if hide_after:
                # ignore items that are newer than the limit
                modified = item.modified().utcdatetime()
                if modified >= limit:
                    continue
            notes.append(item)
        self.contents = notes
        return self.index()


# missing translations
dummy = _("Are you sure")
class INoticeboardSettings(Interface):
    '''Marker interface for content types that can be configured for
    noticeboards
    '''
    note_type = schema.Choice(
        title=_(u"label_Note_type", default=u"Default type for notes"),
        description=_(
            u"description_note_type",
            default=u"Which content type should be created when adding a note."),  # noqa
        vocabulary="plone.app.vocabularies.ReallyUserFriendlyTypes",
        required=True,
        default="News Item")

    display_types = schema.List(
        title=_(u"label_Display_types", default=u"Display types"),
        description=_(
            u"description_display_types",
            default=u"Which content types should be shown on the noticeboard? If the board is a collection this setting will be ignored. The default type for notes is always shown."),  # noqa
        value_type=schema.Choice(source="plone.app.vocabularies.ReallyUserFriendlyTypes"),  # noqa
        required=True,
        default=["News Item", "Image", "Document"])

    create_on_click = schema.Bool(
        title=_(u"label_Create_on_click",
                default="New note with click on background"),
        description=_(u"description_Create_on_click", default=""),
        required=False,
        default=False)

    publish_on_creation = schema.Bool(
        title=_(u"label_Publish_on_create",
                default="Publish new items automatically"),
        description=_(u"description_Publish_on_create", default=""),
        required=False,
        default=False)

    hide_after_days = schema.Int(
        title=_(u"label_Hide_after_days",
                default="Hide items this many days after the last change"),
        description=_(u"description_Hide_after_days",
                      default="How many days after the last modification should items be ommitted from the board? Leave empty or 0 to never hide old items."),  # noqa
        required=False,
        default=0)

    show_help = schema.Bool(
        title=_(u"label_Showhelp", default="Show a link to a help-page"),
        description=_(u"description_Showhelp",
                      default="The link automatically points to a page with the id 'noticeboard-help', you should create one if you enable this."),  # noqa
        required=False,
        default=False)
    def __call__(self):  # noqa
        self.request.response.setHeader('Content-Type',
                                        'application/json; charset=utf-8')
        self.request.response.setHeader('Expires', '-1')
        self.request.response.setHeader('Cache-Control', 'private')
        retval = []
        new = []
        max_zindex = 0
        items = self.contents()
        check_perm = getSecurityManager().checkPermission
        delete_url = None
        settings = NoticeboardSettings(self.context)
        hide_after = settings.hide_after_days
        if hide_after:
            limit = datetime.now() - timedelta(days=hide_after)
        for item in items:
            if isinstance(item, CatalogContentListingObject):
                item = item.getObject()
            item = aq_inner(item)
            if hide_after:
                # ignore items that are older than the limit
                modified = item.modified().utcdatetime()
                if modified <= limit:
                    continue
            if isinstance(item.exclude_from_nav, bool):
                if item.exclude_from_nav:
                    continue
            else:
                if item.exclude_from_nav():
                    continue
            actions = []
            note = INote(item)
            if check_perm(permissions.ModifyPortalContent, item):
                if note.review_state == 'private':
                    actions.append(
                        dict(content=self.context.translate(PMF('Publish')),
                             title="",
                             class_='publish',
                             url=item.absolute_url() +
                             '/content_status_modify?workflow_action=publish'))
        # alternatively use a popup with the form from /content_status_history

                actions.append(
                    dict(content=self.context.translate(_('Color')),
                         title=self.context.translate(_("Change color")),
                         class_='change_color',
                         url=item.absolute_url() + '/change_color'))
                actions.append(
                    dict(content=self.context.translate(PMF('Edit')),
                         title='',
                         class_='edit',
                         url=item.absolute_url() + '/edit'))

            if check_perm(permissions.DeleteObjects, item):
                delete_url = item.absolute_url() \
                    + '/delete_confirmation'
                actions.append(
                    dict(content=self.context.translate(PMF('Delete')),
                         title='',
                         class_='delete',
                         url=delete_url))
            notedata = note.jsonable
            try:
                max_zindex = max(max_zindex, int(note.zIndex))
            except ValueError:
                new.append(notedata)
            notedata.update(dict(hasactions=bool(actions)))
            notedata.update(dict(actions=actions))

            if delete_url:
                notedata.update(dict(delete_url=delete_url))
                are_you_sure = self.context.translate(_('Are you sure'))
                notedata.update(dict(are_you_sure=are_you_sure))
            retval.append(notedata)
        for (new_note, new_index) in zip(new, range(max_zindex + 1,
                                         max_zindex + len(new) + 1)):
            new_note['zIndex'] = new_index
        return json.dumps(retval)

class NoticeboardArchive(NoticeboardNotes):
    """ A listing-view of all outdated items
    """

    def __call__(self):
        """ Render the content item listing.
        """

        notes = []
        items = self.contents()
        settings = NoticeboardSettings(self.context)
        hide_after = settings.hide_after_days
        if not hide_after:
            self.contents = ""
            return self.index()
        limit = datetime.now() - timedelta(days=hide_after)
        for item in items:
            if hide_after:
                # ignore items that are newer than the limit
                modified = item.modified().utcdatetime()
                if modified >= limit:
                    continue
            notes.append(item)
        self.contents = notes
        return self.index()

# missing translations
dummy = _("Are you sure")