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

        context = self.context
        object = removeSecurityProxy(context.object)

        try:
            principal = getPrincipal(context.principal)
        except PrincipalLookupError:
            principal = ''

        profile = IPersonalProfile(principal, None)

        datetime = ''
        if context.date:
            datetime = context.date.strftime('%Y-%m-%d %H:%M UTC')

        self.info = {
            'title': object.title,
            'user': getattr(profile, 'title', 'NO NAME'),
            'datetime': datetime,
            'url': '%s/' % absoluteURL(
                object,
                self.request).replace('/++skin++JSONRPC.acknowledgement', '')
        }
    def retract(self, principal=None):
        if principal is None:
            principal = getPrincipal()

        if not self.isRetractable(principal):
            raise DraftException('Cannot retract content.')

        container = queryMultiAdapter((principal, self), IDraftContainer)
        if container is None:
            raise DraftException('Cannot find draft container.')

        content = self.context

        origName = content.__name__
        oldContainer = content.__parent__

        newName = INameChooser(container).chooseName(u'', content)

        container[newName] = removeAllProxies(content)
        del removeAllProxies(oldContainer)[origName]

        draft = container[newName]
        event.notify(ObjectRetractedEvent(content, draft))

        return draft
Beispiel #3
0
def initObjectOwnership(object, event):
    if interfaces.IUnchangeableOwnership.providedBy(object) or \
            interfaces.IInheritOwnership.providedBy(object):
        return

    principal = getPrincipal()
    if principal is not None:
        interfaces.IOwnership(removeSecurityProxy(object)).owner = principal
    def isRetractable(self, principal=None):
        if not IBoundContentType.providedBy(self):
            return False

        if not self.retractable or not self.retractperm:
            return False

        if principal is None:
            principal = getPrincipal()

        return checkPermissionForPrincipal(
            principal, self.retractperm, self.context)
Beispiel #5
0
    def prepare(self):
        results = getUtility(IAcknowledgements).search(object=self.context)

        acknowledged = [i.principal for i in results]
        allusers = searchPrincipals(
            type=('user',),
            principalSubscribed={'any_of': (True,)})

        members = []
        bannedusers = getUtility(IBanPrincipalConfiglet)
        rolemanager = IPrincipalRoleManager(getSite())
        checkroles = ['zope.Anonymous', ]

        portal_roles = getUtility(IPortalRoles)
        if 'site.member' in portal_roles:
            checkroles.append(portal_roles['site.member'].id)

        for pid in [i.id for i in allusers if i.id not in acknowledged]:
            # Note: skip banned users
            if pid in bannedusers.banned:
                continue

            try:
                principal = getPrincipal(pid)
            except PrincipalLookupError:
                continue

            # Note: skip users with Deny roles
            nextitem = False
            for role, setting in rolemanager.getRolesForPrincipal(pid):
                if role == 'zope.Manager':
                    continue
                if role in checkroles and setting == Deny:
                    nextitem = True
                    break
            if nextitem:
                continue

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

            members.append(profile)

        return self.export(members)
Beispiel #6
0
    def prepare(self):
        results = getUtility(IAcknowledgements).search(object=self.context)

        acknowledged = [i.principal for i in results]
        allusers = searchPrincipals(
            type=('user',),
            principalSubscribed={'any_of': (True,)})

        members = []
        bannedusers = getUtility(IBanPrincipalConfiglet)
        rolemanager = IPrincipalRoleManager(getSite())
        checkroles = ['zope.Anonymous', ]

        portal_roles = getUtility(IPortalRoles)
        if 'site.member' in portal_roles:
            checkroles.append(portal_roles['site.member'].id)

        for pid in [i.id for i in allusers if i.id not in acknowledged]:
            # Note: skip banned users
            if pid in bannedusers.banned:
                continue

            try:
                principal = getPrincipal(pid)
            except PrincipalLookupError:
                continue

            # Note: skip users with Deny roles
            nextitem = False
            for role, setting in rolemanager.getRolesForPrincipal(pid):
                if role == 'zope.Manager':
                    continue
                if role in checkroles and setting == Deny:
                    nextitem = True
                    break
            if nextitem:
                continue

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

            members.append(profile)

        return self.export(members)
Beispiel #7
0
    def prepare(self):
        results = getUtility(IAcknowledgements).search(object=self.context)

        if len(results) > 0:
            members = []
            # localtz = tz.tzlocal()
            bannedusers = getUtility(IBanPrincipalConfiglet)
            rolemanager = IPrincipalRoleManager(getSite())
            checkroles = ['zope.Anonymous', ]

            portal_roles = getUtility(IPortalRoles)
            if 'site.member' in portal_roles:
                checkroles.append(portal_roles['site.member'].id)

            for pid, ack_date in [(i.principal, i.date) for i in results]:
                # Note: skip banned users
                if pid in bannedusers.banned:
                    continue

                try:
                    principal = getPrincipal(pid)
                except PrincipalLookupError:
                    continue

                # Note: skip users with Deny roles
                nextitem = False
                for role, setting in rolemanager.getRolesForPrincipal(pid):
                    if role == 'zope.Manager':
                        continue
                    if role in checkroles and setting == Deny:
                        nextitem = True
                        break
                if nextitem:
                    continue

                profile = IPersonalProfile(principal, None)
                if profile is None:
                    continue
                members.append(
                    (profile, ack_date.strftime('%Y-%m-%d %H:%M UTC')))
                # NOTE: convert date to local time zone
                # .replace(tzinfo=utc).astimezone(localtz).strftime('%Y-%m-%d %H:%M %Z')

            return self.export(members)
Beispiel #8
0
    def prepare(self):
        results = getUtility(IAcknowledgements).search(object=self.context)

        if len(results) > 0:
            members = []
            # localtz = tz.tzlocal()
            bannedusers = getUtility(IBanPrincipalConfiglet)
            rolemanager = IPrincipalRoleManager(getSite())
            checkroles = ['zope.Anonymous', ]

            portal_roles = getUtility(IPortalRoles)
            if 'site.member' in portal_roles:
                checkroles.append(portal_roles['site.member'].id)

            for pid, ack_date in [(i.principal, i.date) for i in results]:
                # Note: skip banned users
                if pid in bannedusers.banned:
                    continue

                try:
                    principal = getPrincipal(pid)
                except PrincipalLookupError:
                    continue

                # Note: skip users with Deny roles
                nextitem = False
                for role, setting in rolemanager.getRolesForPrincipal(pid):
                    if role == 'zope.Manager':
                        continue
                    if role in checkroles and setting == Deny:
                        nextitem = True
                        break
                if nextitem:
                    continue

                profile = IPersonalProfile(principal, None)
                if profile is None:
                    continue
                members.append(
                    (profile, ack_date.strftime('%Y-%m-%d %H:%M UTC')))
                # NOTE: convert date to local time zone
                # .replace(tzinfo=utc).astimezone(localtz).strftime('%Y-%m-%d %H:%M %Z')

            return self.export(members)
Beispiel #9
0
    def getPrincipal(self, space):
        if space in self:
            if space in self.bassignments:
                return getPrincipal(self.bassignments[space])

        return None
 def __init__(self, context):
     self.context = context
     self.ownerId = context.author
     self.owner = getPrincipal(context.author)
     self.isGroup = False
Beispiel #11
0
 def ownerId(self, pid):
     self.owner = getPrincipal(pid)
Beispiel #12
0
 def owner(self):
     if self._ownerId:
         return getPrincipal(self._ownerId)
     else:
         return None