def getDefaultRetractSubject(self):
     _ = getToolByName(self, "translation_service").translate
     return _(
         msgid="subject_rejected",
         default=u"[Form Online] - Form Online rejected",
         domain="auslfe.formonline.pfgadapter",
         context=self,
     )
 def getDefaultDispatchSubject(self):
     _ = getToolByName(self, "translation_service").translate
     return _(
         msgid="subject_dispatched",
         default=u"[Form Online] - Form Online approved",
         domain="auslfe.formonline.pfgadapter",
         context=self,
     )
 def getDefaultApprovalSubject(self):
     _ = getToolByName(self, "translation_service").translate
     return _(
         msgid="subject_pending_dispatch",
         default=u"[Form Online] - Form Online in pending state dispatch",
         domain="auslfe.formonline.pfgadapter",
         context=self,
     )
    def getDefaultDispatchMessage(self):
        _ = getToolByName(self, "translation_service").translate
        rstText = _(
            msgid="mail_text_dispatched",
            default=u"""Dear user,

this is a personal communication regarding the Form Online **${formonline_title}**.

The request has been *approved*. Follow the link below to see the document:

${formonline_url}

Regards
""",
            domain="auslfe.formonline.pfgadapter",
            context=self,
        )
        return rstHTML(rstText, input_encoding="utf-8", output_encoding="utf-8")
    def getDefaultApprovalMessage(self):
        _ = getToolByName(self, "translation_service").translate
        rstText = _(
            msgid="mail_text_dispatch_required",
            default=u"""Dear user,

this is a personal communication regarding the Form Online **${formonline_title}**, created on **${insertion_date}** by **${formonline_owner}**.

The request has been approved and it's waiting for your confirmation. Follow the link below for perform your actions:

${formonline_url}

Regards
""",
            domain="auslfe.formonline.pfgadapter",
            context=self,
        )
        return rstHTML(rstText, input_encoding="utf-8", output_encoding="utf-8")
    def checkFieldSubmitter(self, fields):
        # We take care of the "formFieldSubmitter" info only for anonymous
        formFieldSubmitterName = self.getFormFieldSubmitter()
        _ = getToolByName(self, "translation_service").translate

        ownerEmail = None
        if formFieldSubmitterName:
            for field in fields:
                if field.__name__ == queryUtility(IURLNormalizer).normalize(formFieldSubmitterName):
                    ownerEmail = field.htmlValue(self.REQUEST)
                    break
            if not ownerEmail:
                error_message = _(
                    "error_nofieldownermail",
                    default=u'There is no field "${email_field}" in the Form to specify the owner of the request.',
                    context=self,
                    domain="auslfe.formonline.pfgadapter",
                    mapping={"email_field": formFieldSubmitterName},
                )
                return {FORM_ERROR_MARKER: error_message}
    def checkFieldOverseer(self, fields):
        """
        Checks if the email address of the assignee is provided in a form field.
        
        Possible returns values:
        * a tuple with ('email', eMailAddress)
        * a dict with error message
        """

        formFieldName = self.getFormFieldOverseer()
        _ = getToolByName(self, "translation_service").translate

        overseerEmail = None
        hasOverseerField = False
        overseerMustBeMember = self.getOverseerMustBeMember()
        tokenaccessInstalled = self.restrictedTraverse("@@checkDependencies").tokenaccess

        # verify if the form cotains overseer filed and get the value
        for field in fields:
            if field.__name__ == queryUtility(IURLNormalizer).normalize(formFieldName):
                hasOverseerField = True
                overseerEmail = field.htmlValue(self.REQUEST)
                break

        # if Overseer set as empty return error
        if hasOverseerField and not overseerEmail:
            error_message = _(
                "error_overseer_email",
                default=u"No Overseer email has been provided, enter a new value.",
                context=self,
                domain="auslfe.formonline.pfgadapter",
            )
            return {queryUtility(IURLNormalizer).normalize(formFieldName): error_message}

        if hasOverseerField and overseerEmail != "No Input":
            membership = getToolByName(self, "portal_memberdata")
            users = membership.searchMemberDataContents("email", overseerEmail)
            if users:
                if len(users) > 1:
                    logger.warning(
                        "There are multiple users with the same email address provided for the field %s."
                        % formFieldName
                    )
                #                    warning_message = ts.translate(msgid='error_multipleusers', domain='auslfe.formonline.pfgadapter',
                #                                                   default=u'There are multiple users with the same email address provided for the field %s.') % formFieldName
                #                    addStatusMessage(self.REQUEST, warning_message, type='warning')
                return ("user", users[0]["username"])
            elif overseerMustBeMember or not tokenaccessInstalled:
                error_message = _(
                    "error_nouser",
                    default=u"No user corresponds to the email address provided, enter a new value.",
                    context=self,
                    domain="auslfe.formonline.pfgadapter",
                )
                return {queryUtility(IURLNormalizer).normalize(formFieldName): error_message}
            else:
                # Here only if no user found but also we are not forced to have a site member
                # Also auslfe.formonline.tokenaccess is installed
                return ("email", overseerEmail)
        else:
            return ("email", "")
 def vocabularyAllStringFields(self):
     form = aq_parent(self)
     fields = form.objectValues()
     return [("None", _("None"))] + [
         (content.id, content.title) for content in fields if isinstance(content, FGStringField)
     ]
    def onSuccess(self, fields, REQUEST=None):
        """ Called by form to invoke custom success processing.
            return None (or don't use "return" at all) if processing is
            error-free.
            
            Return a dictionary like {'field_id':'Error Message'}
            and PFG will stop processing action adapters and
            return back to the form to display your error messages
            for the matching field(s).

            You may also use Products.PloneFormGen.config.FORM_ERROR_MARKER
            as a marker for a message to replace the top-of-the-form error
            message.

            For example, to set a message for the whole form, but not an
            individual field:

            {FORM_ERROR_MARKER:'Yuck! You will need to submit again.'}

            For both a field and form error:

            {FORM_ERROR_MARKER:'Yuck! You will need to submit again.',
             'field_id':'Error Message for field.'}
            
            Messages may be string types or zope.i18nmessageid objects.                
        """

        mtool = getToolByName(self, "portal_membership")
        utool = getToolByName(self, "plone_utils")
        wtool = getToolByName(self, "portal_workflow")

        # fields will be a sequence of objects with an IPloneFormGenField interface
        check_fieldOverseer = self.checkFieldOverseer(fields)
        if type(check_fieldOverseer) == dict:
            return check_fieldOverseer

        try:
            formonline = self.save_form(fields)
        except ValueError:
            utool.addPortalMessage(_(u"You are not authorized to write on this folder."), type="error")
            return
        except Unauthorized:
            utool.addPortalMessage(_(u"You are not authorized to fill that form."), type="error")
            return

        # Share the form with the proper user only if a Overseer is provided and the proper workflow has to be used.
        if check_fieldOverseer[1]:
            sharing_provider = getMultiAdapter(
                (self, self.REQUEST), IFormSharingProvider, name="provider-for-%s" % check_fieldOverseer[0]
            )
            sharing_provider.share(formonline, check_fieldOverseer[1])

        if mtool.isAnonymousUser():
            check_fieldSubmitter = self.checkFieldSubmitter(fields)
            if type(check_fieldSubmitter) == dict:
                return check_fieldSubmitter

            formFieldSubmitterName = self.getFormFieldSubmitter()
            if formFieldSubmitterName:
                # Memoize the e-mail, for later notification
                for field in fields:
                    if field.fgField.getName() == queryUtility(IURLNormalizer).normalize(formFieldSubmitterName):
                        IAnnotations(formonline)["owner-email"] = field.htmlValue(self.REQUEST)
                        break

            # Immediatly submit the form (he can't edit it later)
            wtool.doActionFor(formonline, "submit")
            utool.addPortalMessage(_(u"Your data has been sent."), type="info")
            # self.REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
            return
        else:
            # Playing with the workflow you can allow owners to modify the document
            # right after its creation. Below the check for the proper redirect URL
            if formonline.restrictedTraverse("@@plone_context_state").is_editable():
                utool.addPortalMessage(_(u"Feel free to modify your data"), type="info")
                self.REQUEST.RESPONSE.redirect(formonline.absolute_url() + "/edit")
            else:
                self.REQUEST.RESPONSE.redirect(formonline.absolute_url() + "/view")