Пример #1
0
def draftRejectedHandler(event):
    draft = event.draft

    profile = IPersonalProfile(IOwnership(draft).owner, None)
    if profile and profile.email:
        template = getMultiAdapter((event, getRequest()), IMailTemplate)
        template.send((profile.email,))
Пример #2
0
    def isAvailable(self):
        """ visible with the approval
        """
        user = self.getPrincipal()
        if user is not None and user.id != 'zope.anybody':
            if self.author == user.id:
                return True

        content = self.content
        if IContentDiscussion(content).status == 4:
            if not checkPermission('zojax.ModifyContent', content):
                request = getRequest()
                cookieAuthor = getAthorFromCookie(request)

                if cookieAuthor == self.authorName:
                    return True

                if getattr(self, 'social_type', False):
                    facebook_id = request.get('facebook_id', 'emptyid')
                    twitter_id = request.get('screen_name', 'emptyid')

                    if getattr(self, 'twitter_id', '') == twitter_id:
                        return True
                    if getattr(self, 'facebook_id', '') == facebook_id:
                        return True

                return self.approved

        return True
Пример #3
0
 def getPrincipal(self):
     request = getRequest()
     try:
         principal = getUtility(IAuthentication).authenticate(request)
     except:
         principal = None
     return principal
Пример #4
0
    def title(self):
        if not self.isInstalled() or self.space.principal.id == getRequest().principal.id:
            return translate(u'Your stuff', 'zojax.personal.content')
        else:
            principal = self.space.principal
            profile = IPersonalProfile(principal)

            return translate("${user_title}'s stuff", 'zojax.personal.content',
                             mapping={'user_title': profile.title})
Пример #5
0
    def __call__(self, context):
        if not IDraftContent.providedBy(context):
            return Vocabulary(())

        ct = IContentType(context)
        types = []
        for tp in ct.destination:
            types.append(tp.name)

        kwargs = {}
        if types:
            kwargs['type'] = {'any_of': types}

        request = getRequest()
        catalog = getUtility(ICatalog)

        perms = {}
        permissions = []
        for id in listAllowedRoles(request.principal, context):
            perms[ct.submit] = 1
            perms[ct.publish] = 1
            permissions.append((ct.submit, id))
            permissions.append((ct.publish, id))

        results = catalog.searchResults(
            draftSubmitTo={'any_of': permissions}, **kwargs)

        if not results:
            return Vocabulary(())

        perms = perms.keys()
        ids = getUtility(IIntIds)

        contents = []
        for content in results:
            allow = False
            for perm in perms:
                if checkPermission(perm, content):
                    allow = True
                    break

            if allow:
                contents.append(
                    (getPath(content),
                     IItem(content).title, ids.getId(content), content))

        contents.sort()

        terms = []
        for path, title, id, content in contents:
            term = SimpleTerm(
                id, str(id), getMultiAdapter((content, request), IBreadcrumb))
            term.content = content
            terms.append(term)

        return Vocabulary(terms)
Пример #6
0
def getDraftNotification(context):
    request = getRequest()
    if request is not None:
        principal = request.principal
        results = getUtility(ICatalog).searchResults(
            noPublishing=True, noSecurityChecks=True, draftPublishTo={"any_of": listAllowedRoles(principal, context)}
        )

        if bool(results):
            return DraftNotification(context)
Пример #7
0
    def invite(self, principal, message):
        invitation = MemberInvitation(
            principal, getUtility(IIntIds).getId(self.__parent__), message)

        IOwnership(invitation).ownerId = getRequest().principal.id
        event.notify(ObjectCreatedEvent(invitation))

        getUtility(IInvitations).storeInvitation(invitation)

        return invitation
Пример #8
0
    def search(self, object=None, contexts=(),
               sort_on='date', sort_order='reverse',
               noSecurityChecks=False, **kw):

        ids = getUtility(IIntIds)

        query = dict(kw)

        # records for object
        if type(object) is not type({}) and object is not None:
            oid = ids.queryId(removeAllProxies(object))
            if oid is None:
                return ResultSet(IFBTree(), getUtility(IActivity))

            query['object'] = {'any_of': (oid,)}

        # context
        if not contexts:
            contexts = (getSite(),)

        c = []
        for context in contexts:
            id = ids.queryId(removeAllProxies(context))
            if id is not None:
                c.append(id)

        query['contexts'] = {'any_of': c}

        # security
        if not noSecurityChecks:
            request = getRequest()
            if request is not None:
                users = listAllowedRoles(request.principal, getSite())
                if 'zope.Anonymous' not in users:
                    users.append('zope.Anonymous')

                query['allowedUsers'] = {'any_of': users}

        # apply searh terms
        results = self.apply(query)
        if results is None:
            results = IFBTree()

        # sort result by index
        if sort_on and sort_on in self:
            sortable = ISortable(self[sort_on], None)
            if sortable is not None:
                results = sortable.sort(results)

        if sort_order == 'reverse':
            return ReverseResultSet(results, getUtility(IActivity))
        else:
            return ResultSet(results, getUtility(IActivity))
Пример #9
0
def memberInvitationHandler(invitation, ev):
    try:
        principal = getUtility(
            IAuthentication).getPrincipal(invitation.principal)
    except PrincipalLookupError:
        return

    profile = IPersonalProfile(principal, None)
    if profile is None:
        return

    email = profile.email
    if not email:
        return

    template = getMultiAdapter(
        (invitation, getRequest()), IMailTemplate, 'text')
    template.addAlternative(
        getMultiAdapter(
            (invitation, getRequest()), IMailTemplate, 'html'))
    template.send((email,))
Пример #10
0
def draftPublishedHandler(event):
    draft = event.draft

    ownership = IOwnership(draft, None)
    if ownership is None:
        return

    profile = IPersonalProfile(ownership.owner, None)
    if profile and profile.email:
        request = getRequest()
        if request.principal.id != owner.id:
            template = getMultiAdapter((event, request), IMailTemplate)
            template.send((profile.email,))
Пример #11
0
    def isAvailable(self):
        if super(DraftedContentType, self).isAvailable():
            if self.permission is not None:
                principal = getattr(getRequest(), 'principal', None)
                df = queryMultiAdapter(
                    (principal, getUtility(IDraftContentType, self.name)),
                    IDraftContainer)
                if df is not None:
                    return True
            else:
                return True

        return False
Пример #12
0
    def search(self, content=None,
               contexts=(), sort_on='date', sort_order='reverse', types=(), approved=()):
        ids = getUtility(IIntIds)
        indexes = list(self.values())

        query = {}

        # comments for content
        if content:
            query['content'] = {'any_of':(ids.getId(removeAllProxies(content)),)}

        # context
        if contexts:
            c = []
            for context in contexts:
                id = ids.queryId(removeAllProxies(context))
                if id is not None:
                    c.append(id)

            query['contexts'] = {'any_of': c}

        # content type
        if types:
            query['type'] = {'any_of': types}

        # security
        users = listAllowedRoles(getRequest().principal, getSite())
        if 'zope.Anonymous' not in users:
            users.append('zope.Anonymous')

        query['access'] = {'any_of': users}

        # comments approved
        if approved:
            query['approved'] = {'any_of': approved}

        # apply searh terms
        results = self.apply(query)
        if results is None:
            results = IFBTree()

        # sort result by index
        if sort_on and sort_on in self:
            sortable = ISortable(self[sort_on], None)
            if sortable is not None:
                results = sortable.sort(results)

        if sort_order == 'reverse':
            return ReverseResultSet(results, ids)
        else:
            return ResultSet(results, ids)
Пример #13
0
def membersAwareObjectCreated(object, ev):
    if 'members' not in object:
        members = Members()
        event.notify(ObjectCreatedEvent(members))
        object['members'] = members

    request = getRequest()
    if request is not None:
        pid = request.principal.id
        members = object['members']
        members.joinPrincipal(pid,)
        members.toManager(pid)

    event.notify(ObjectModifiedEvent(object))
Пример #14
0
def acknowledgementAddedHandler(object, ev):
    obj = IContentAcknowledgement(object)
    if not obj:
        return

    emails = obj.emails_list
    if not emails:
        return

    try:
        template = getMultiAdapter((ev.record, getRequest()),
                                   IMailTemplate,
                                   'html')
    except ComponentLookupError:
        template = getMultiAdapter((ev.record, TestRequest()),
                                   IMailTemplate,
                                   'html')
    template.send(emails)
Пример #15
0
    def __call__(self, context):
        request = getRequest()
        if request is None:
            return SimpleVocabulary(())

        results = getUtility(ICatalog).searchResults(
            type = {'any_of': ('content.group',)},
            members = {'any_of': (request.principal.id,)})

        groups = []
        for group in results:
            term = SimpleTerm(group.id, str(group.id), group.title)
            term.description = group.description

            groups.append((group.title, term))

        groups.sort()
        return SimpleVocabulary([term for _t, term in groups])
Пример #16
0
    def install(self):
        manager = self.space.get('people')

        if not IPersonalSpaceManager.providedBy(manager):
            manager = PersonalSpaceManager(
                title = u'People',
                description = u'Personal spaces for members.')
            event.notify(ObjectCreatedEvent(manager))

            removeAllProxies(self.space)['people'] = manager

            request = getRequest()
            if request is not None:
                manager.getPersonalSpace(request.principal)

            sm = component.getSiteManager()
            sm.registerUtility(manager, IPersonalSpaceManager)

            manager = self.space['people']

        return manager
Пример #17
0
 def postForm(self, formName, **data):
     request = getRequest()
     
     def force_unicode(s):
         if isinstance(s, unicode):
             return s.encode('utf-8')
         return s
     data = dict(map(lambda (x, y): (x, force_unicode(y)), data.items()))
     
     data['UserToken'] = request.getCookie('hubspotutk')
     data['IPAddress'] = request.get('REMOTE_ADDR', '')
     apiUrl = self.apiURL
     if not self.enabled:
         return
     if not apiUrl:
         # HubSpot API is not configured. Abort the submission.
         logger.warning("HubSpot API is not configured.")
         return
     url = '%s?%s'%(apiUrl, urllib.urlencode(dict(data, app='leaddirector', FormName=formName)))
     try:
         urllib.urlopen(url)
     except IOError, exc:
         logger.warning('Form post error', exc_info=True)
Пример #18
0
    def isAvailable(self):
        if self.data is None or not self.data.data:
            return False
        tz = ITZInfo(getRequest(), utc)
        lt = datetime.datetime.now(tz).timetz()

        beginTime, endTime = self.beginTime, self.endTime
        if self.beginTime is not None and self.beginTime.tzinfo is None:
            beginTime = self.beginTime.replace(tzinfo=tz)
        if self.endTime is not None and self.endTime.tzinfo is None:
            endTime = self.endTime.replace(tzinfo=tz)
        return (
            self.enabled
            and self.data is not None
            and self.data.data
            and (
                beginTime is None
                or endTime is None
                or  beginTime <= lt <= endTime
                or  (
                    beginTime >= endTime
                    and (
                        endTime <= lt
                        or  lt <= beginTime
                        )
                    )
                )
            and (
                self.beginDate is None
                or self.beginDate <= datetime.date.today()
                )
            and (
                self.endDate is None
                or self.endDate >= datetime.date.today()
                )
            )
Пример #19
0
 def url(self):
     url = "%s/@@managediscussion/%s/context.html"
     return url % (absoluteURL(self.content, getRequest()), self.id)
Пример #20
0
 def __init__(self, context):
     self.context = context
     self.request = getRequest()
Пример #21
0
    def isAvailable(self):
        request = getRequest()
        if request.principal.id != self.space.principalId:
            return False

        return True
Пример #22
0
 def join(self):
     request = getRequest()
     if request is not None:
         self.joinPrincipal(request.principal.id, self.approving)
Пример #23
0
 def remove(self):
     request = getRequest()
     if request is not None:
         self.removePrincipal(request.principal.id)