def update(self):
        super(ConfirmWorkflowAction, self).update()
        self.title = safe_unicode(self.context.title_or_id())
        actionId = self.request.get('workflow_action', None)
        # work around doubled form-values returned as lists:
        if actionId and not isinstance(actionId, basestring):
            actionId = actionId[0]

        self.action = None

        pw = getToolByName(self.context, 'portal_workflow')
        for transition in pw.getTransitionsFor(self.context):
            if transition['id'] == actionId:
                self.action = transition

        if not self.action:
            IStatusMessage(self.request).addStatusMessage(
                _(u"No action to perform."), "error")
            self.request.response.redirect(self.context.absolute_url())
        elif 'form.button.Cancel' in self.request:
            IStatusMessage(self.request).addStatusMessage(
                _(u"Canceled state change."), "info")
            self.request.response.redirect(self.context.absolute_url())
        elif 'form.button.Confirm' in self.request:
            actionUrl = ''.join([self.context.absolute_url(),
                '/content_status_modify?workflow_action=', actionId])
            self.request.response.redirect(actionUrl)
Example #2
0
    def postUpdate(self):
        self.context.update_image_fields()
        self.context.previouslyEdited = True

        pw = getToolByName(self.context, 'portal_workflow')
        reviewState = pw.getInfoFor(self.context, 'review_state')
        if reviewState != 'draft':
            # send out invitations:
            newlyInvited = self.context.invitedManagers - self.alreadyInvited
            if newlyInvited:
                for uid in list(newlyInvited):
                    try:
                        self.messenger.sendManagerInvitation(uid)
                    except:
                        self.context.invitedManagers.remove(uid)
                        IStatusMessage(self.request).addStatusMessage(
                            _(COULD_NOT_INVITE_MESSAGE, mapping={'uid': uid}),
                            "error")

            newlyInvited = self.context.invitedMembers - self.alreadyInvited
            if newlyInvited:
                for uid in list(newlyInvited):
                    try:
                        self.messenger.sendInvitation(uid)
                    except:
                        self.context.invitedMembers.remove(uid)
                        IStatusMessage(self.request).addStatusMessage(
                            _(COULD_NOT_INVITE_MESSAGE, mapping={'uid': uid}),
                            "error")
    def send(self, to, subject_template, body_template, extended_mapping={}):
        to_addr = self.getAddressForUid(to)

        if not to_addr:
            raise MissingAddress()
        regtool = getToolByName(self.context, 'portal_registration')
        if not regtool.isValidEmail(to_addr):
            raise InvalidAddress(to_addr)

        mapping = self.getMapping(to)
        mapping.update(extended_mapping)

        subject = _(subject_template, mapping=mapping)
        body = _(body_template, mapping=mapping)

        # Construct and send a message
        message = message_from_string(
            self.context.translate(body).encode('utf-8'))
        message.set_charset('utf-8')
        message['From'] = u"%s <%s>" % (self.portalTitle, self.fromAddress)
        message['To'] = u"%s <%s>" % (
            self.getNameForUid(to).replace('@', '[at]'), to_addr)
        message['Subject'] = Header(self.context.translate(subject), 'utf-8')

        self.mailhost.send(message)
    def update(self):
        super(DeleteConfirmation, self).update()
        self.title = safe_unicode(self.context.title_or_id())
        parent = self.context.aq_inner.aq_parent

        if ('form.button.Delete' not in self.request
            and 'form.button.Cancel' not in self.request):
            # ask for confirmation (don't redirect)
            return

        if 'form.button.Delete' in self.request:
            # check if the object has incoming relations:
            catalog = component.getUtility(ICatalog)
            intids = component.getUtility(IIntIds)
            relations = catalog.findRelations({
                'to_id': intids.getId(self.context)})

            # remove relations
            for rel in relations:
                getattr(rel.from_object, 'relatedFiles', []).remove(rel)

            # delete
            parent.manage_delObjects(self.context.getId())
            IStatusMessage(self.request).addStatusMessage(
                _(u'"%s" has been deleted.' % self.title), "info")

        workspace = parent
        while not IWorkspace.providedBy(workspace):
            workspace = workspace.aq_parent
        self.request.response.redirect(
            '/'.join([workspace.absolute_url(), 'conversation']))
    def validate_options(data):
        ''' Validate options '''
        if getattr(data, 'pollOrRating', None) == 'rating':
            return

        options = getattr(data, 'options', None)
        if not options or len(options) < 2:
            raise InsuficientOptions(
                _(u"You need to provide at least two options for a poll."))
Example #6
0
    def update(self):
        self.canVote = False
        self.context.voters = getattr(self.context, 'voters', set())
        self.totalVotes = len(self.context.voters)

        checkPermission = getSecurityManager().checkPermission
        if not checkPermission('Add portal content', self.context):
            self.redirectIfNotInThread()
            return

        if self.authenticated_member_id in self.context.voters:
            self.redirectIfNotInThread()
            return

        isDeadlinePassed = False
        pollDeadline = getattr(self.context, 'deadline', None)
        if pollDeadline is not None:
            isDeadlinePassed = pollDeadline < datetime.datetime.now()

        if isDeadlinePassed:
            self.redirectIfNotInThread()
            return

        self.canVote = True

        option = self.request.form.get('option', None)
        self.context.isRating = self.context.pollOrRating == 'rating'

        if option not in self.context.availableOptions.by_token:
            self.redirectIfNotInThread()
            return

        # count this vote
        pw = getToolByName(self.context, 'portal_workflow')
        self.reviewState = pw.getInfoFor(self.context, 'review_state')

        if self.reviewState == 'published':
            pw.doActionFor(self.context, 'activate')

        count_vote(self.context, option, self.authenticated_member_id)

        confirm = _(u"Thank you! Your vote has been counted.")
        IStatusMessage(self.request).add(confirm, type='info')

        self.redirectIfNotInThread()
Example #7
0
    def update(self):
        self.canVote = False
        self.context.voters = getattr(self.context, 'voters', set())
        self.totalVotes = len(self.context.voters)
        self.sortedVotes = [self.context.votes[token] for token in sorted(self.context.votes)]

        # Determine if the current user may see the voter info
        #   1. The poll must not be anonymous
        #   2. Permission must be granted.
        #   3. Votes must be confidential (it must not be possible
        #      to clearly see who voted for which option).
        self.showVoterInfo = not self.context.anonymous and self.hasVoterInfoPermission() and self.hasSufficientVotes()

        # Determine all potential voters and nonvoters.
        ws = self.context.getParentNode()
        eligibleVoters = ws.getMemberIds()
        nonvoters = set(eligibleVoters) - set(self.context.voters)
        self.totalEligibleVoters = len(eligibleVoters)
        self.totalNonvoters = len(nonvoters)

        # Has the voting started? Have all members made their vote?
        self.votingStarted = (self.totalVotes > 0)
        self.votingComplete = (self.totalVotes == self.totalEligibleVoters)

        # Get full names of voters and nonvoters.
        self.voterNames = [member.getProperty('fullname') for member in ws.getUsersByIds(self.context.voters)]
        self.nonvoterNames = [member.getProperty('fullname') for member in ws.getUsersByIds(nonvoters)]

        checkPermission = getSecurityManager().checkPermission
        if not checkPermission('Add portal content', self.context):
            self.redirectIfNotInThread()
            return

        if self.authenticated_member_id in self.context.voters:
            self.redirectIfNotInThread()
            return

        isDeadlinePassed = False
        pollDeadline = getattr(self.context, 'deadline', None)
        if pollDeadline is not None:
            isDeadlinePassed = pollDeadline < datetime.datetime.now()

        if isDeadlinePassed:
            self.redirectIfNotInThread()
            return

        self.canVote = True

        option = self.request.form.get('option', None)
        self.context.isRating = self.context.pollOrRating == 'rating'

        if option not in self.context.availableOptions.by_token:
            self.redirectIfNotInThread()
            return

        # count this vote
        pw = getToolByName(self.context, 'portal_workflow')
        self.reviewState = pw.getInfoFor(self.context, 'review_state')

        if self.reviewState == 'published':
            pw.doActionFor(self.context, 'activate')

        count_vote(self.context, option, self.authenticated_member_id)

        confirm = _(u"Thank you! Your vote has been counted.")
        IStatusMessage(self.request).add(confirm, type='info')

        self.redirectIfNotInThread()
        subject = _(subject_template, mapping=mapping)
        body = _(body_template, mapping=mapping)

        # Construct and send a message
        message = message_from_string(
            self.context.translate(body).encode('utf-8'))
        message.set_charset('utf-8')
        message['From'] = u"%s <%s>" % (self.portalTitle, self.fromAddress)
        message['To'] = u"%s <%s>" % (
            self.getNameForUid(to).replace('@', '[at]'), to_addr)
        message['Subject'] = Header(self.context.translate(subject), 'utf-8')

        self.mailhost.send(message)


JOINED_WORKSPACE_MESSAGE = _(u"Welcome to the workspace.")
ALLOWED_TO_ADMIN_WORKSPACE_MESSAGE = _(
    u"You are a co-administrator in this workspace.")
ALREADY_MEMBER_MESSAGE = _(u"You already are a member of this workspace.")
WORKSPACE_FULL_MESSAGE = _(u"This workspace is full.")
WORKSPACE_CLOSED_MESSAGE = _(u'This workspace is closed for new members.')


class Join(grok.View, view_mixins.PortalMembership):
    """Checks if the user is allowed to join the workspace and adds her/him to
    the users list. Redirects to the workspaces default-view.
    """
    grok.context(IWorkspace)
    grok.require('ixds.JoinWorkspace')
    grok.name('join')