Exemplo n.º 1
0
 def show(self):
     if not IOSH_Link.providedBy(self.context):
         return False
     qi = getToolByName(self.context, 'portal_quickinstaller')
     if not qi.isProductInstalled('Products.OSHContentLink'):
         return False
     user = getToolByName(self.context, 'portal_membership').getAuthenticatedMember()
     if user.has_role(('Manager', 'Reviewer')):
         return True
     return False
Exemplo n.º 2
0
 def show(self):
     if not IOSH_Link.providedBy(self.context):
         return False
     qi = getToolByName(self.context, 'portal_quickinstaller')
     if not qi.isProductInstalled('Products.OSHContentLink'):
         return False
     user = getToolByName(self.context,
                          'portal_membership').getAuthenticatedMember()
     if user.has_role(('Manager', 'Reviewer')):
         return True
     return False
Exemplo n.º 3
0
    def __call__(self, skipRedirect=False, **args):
        context = self.context
        request = context.REQUEST
        status = IStatusMessage(request)
        errors = list()
        plone_utils = getToolByName(context, 'plone_utils')
        id = request.get('id')
        uid = request.get('uid')

        if IProvider.providedBy(context):
            target = context.restrictedTraverse('/osha/portal/data/links')
            if not target:
                errors.append(
                    "Error: folder for adding the OSH Resource could not be found"
                )
            else:
                if getattr(aq_base(target), id, None):
                    errors.append(
                        "The ID '%s' already exists as an OSH Resource."
                        " Please choose a different id" % id)
                else:
                    target.invokeFactory(id=id, type_name="OSH_Link")
                    obj = getattr(target, id)
                    for fname in COMMON_FIELDS:
                        value = context.getField(fname).getAccessor(context)()
                        obj.getField(fname).getMutator(obj)(value)
                    obj.setText(context.Description())
                    obj.reindexObject()
                    ann = IAnnotations(context)
                    ann[EXISTING_SWITCHED_CONTENT_UID] = obj.UID()
                    status.addStatusMessage(
                        "Switching content was successful! See the box below for a link to "
                        "the new OSH Resource.",
                        type='info')
                    try:
                        pwt = getToolByName(context, 'portal_workflow')
                        pwt.doActionFor(context, 'delete')
                        status.addStatusMessage(
                            "The workflow state on this Provider was set to 'deleted'",
                            type='info')
                    except:
                        status.addStatusMessage(
                            "Setting the workflow state to 'deleted' was NOT possible.",
                            type="warning")
        elif IOSH_Link.providedBy(context):
            target = context.restrictedTraverse('/osha/portal/data/provider')
            if not target:
                errors.append(
                    "Error: folder for adding the Provider could not be found")
            else:
                if getattr(aq_base(target), id, None):
                    errors.append(
                        "The ID '%s' already exists as a Provider. Please choose a different id"
                        % id)
                else:
                    target.invokeFactory(id=id, type_name="Provider")
                    obj = getattr(target, id)
                    for fname in COMMON_FIELDS:
                        value = context.getField(fname).getAccessor(context)()
                        obj.getField(fname).getMutator(obj)(value)
                    obj.setDescription(context.getText())
                    obj.reindexObject()
                    ann = IAnnotations(context)
                    ann[EXISTING_SWITCHED_CONTENT_UID] = obj.UID()
                    status.addStatusMessage(
                        "Switching content was successful! See the box below for a link to "
                        "the new Provider.",
                        type='info')
                    try:
                        pwt = getToolByName(context, 'portal_workflow')
                        pwt.doActionFor(context, 'delete')
                        status.addStatusMessage(
                            "The workflow state on this OSH Resource was set to 'deleted'",
                            type='info')
                    except:
                        status.addStatusMessage(
                            "Setting the workflow state to 'deleted' was NOT possible.",
                            type="warning")
        else:
            errors.append(
                'This form was used on content other than a Provider or OSH Resource.'
            )

        if len(errors):
            path = "%s/oshcontent_switch_form?uid=%s&id=%s" % (
                context.absolute_url(), uid, id)
            for error in errors:
                status.addStatusMessage(error, type="error")
        else:
            path = context.absolute_url()
        self.request.RESPONSE.redirect(path)
Exemplo n.º 4
0
    def __call__(self, skipRedirect=False, **args):
        context = self.context
        request = context.REQUEST
        status = IStatusMessage(request)
        errors = list()
        plone_utils = getToolByName(context, "plone_utils")
        id = request.get("id")
        uid = request.get("uid")

        if IProvider.providedBy(context):
            target = context.restrictedTraverse("/osha/portal/data/links")
            if not target:
                errors.append("Error: folder for adding the OSH Resource could not be found")
            else:
                if getattr(aq_base(target), id, None):
                    errors.append("The ID '%s' already exists as an OSH Resource." " Please choose a different id" % id)
                else:
                    target.invokeFactory(id=id, type_name="OSH_Link")
                    obj = getattr(target, id)
                    for fname in COMMON_FIELDS:
                        value = context.getField(fname).getAccessor(context)()
                        obj.getField(fname).getMutator(obj)(value)
                    obj.setText(context.Description())
                    obj.reindexObject()
                    ann = IAnnotations(context)
                    ann[EXISTING_SWITCHED_CONTENT_UID] = obj.UID()
                    status.addStatusMessage(
                        "Switching content was successful! See the box below for a link to " "the new OSH Resource.",
                        type="info",
                    )
                    try:
                        pwt = getToolByName(context, "portal_workflow")
                        pwt.doActionFor(context, "delete")
                        status.addStatusMessage("The workflow state on this Provider was set to 'deleted'", type="info")
                    except:
                        status.addStatusMessage(
                            "Setting the workflow state to 'deleted' was NOT possible.", type="warning"
                        )
        elif IOSH_Link.providedBy(context):
            target = context.restrictedTraverse("/osha/portal/data/provider")
            if not target:
                errors.append("Error: folder for adding the Provider could not be found")
            else:
                if getattr(aq_base(target), id, None):
                    errors.append("The ID '%s' already exists as a Provider. Please choose a different id" % id)
                else:
                    target.invokeFactory(id=id, type_name="Provider")
                    obj = getattr(target, id)
                    for fname in COMMON_FIELDS:
                        value = context.getField(fname).getAccessor(context)()
                        obj.getField(fname).getMutator(obj)(value)
                    obj.setDescription(context.getText())
                    obj.reindexObject()
                    ann = IAnnotations(context)
                    ann[EXISTING_SWITCHED_CONTENT_UID] = obj.UID()
                    status.addStatusMessage(
                        "Switching content was successful! See the box below for a link to " "the new Provider.",
                        type="info",
                    )
                    try:
                        pwt = getToolByName(context, "portal_workflow")
                        pwt.doActionFor(context, "delete")
                        status.addStatusMessage(
                            "The workflow state on this OSH Resource was set to 'deleted'", type="info"
                        )
                    except:
                        status.addStatusMessage(
                            "Setting the workflow state to 'deleted' was NOT possible.", type="warning"
                        )
        else:
            errors.append("This form was used on content other than a Provider or OSH Resource.")

        if len(errors):
            path = "%s/oshcontent_switch_form?uid=%s&id=%s" % (context.absolute_url(), uid, id)
            for error in errors:
                status.addStatusMessage(error, type="error")
        else:
            path = context.absolute_url()
        self.request.RESPONSE.redirect(path)