Пример #1
0
    def hasPerms(self, mode, group):
        """Checks that the specified session has the appropriate group 
        memberships"""

        # Import here to avoid circular dependencies
        from crcnetd.modules.ccs_contact import getUserCache, getCustomerCache, getGroupCache
        
        # Check session is of appropriate type
        if mode == SESSION_RW:
            if self.mode != SESSION_RW:
                return SESSION_NONE

        # normal users have AUTH_AUTHENTICATED by default
        if group == AUTH_AUTHENTICATED:
            return mode
        
        # If we have a cached permission record, return that
        if group in self.permCache.keys():
            return self.permCache[group]

        # Check group membership
        users = getUserCache(self.session_id)
        customers = getCustomerCache(self.session_id)
        groups = getGroupCache(self.session_id)
        admin_id = users[self.login_id]["admin_id"]

        if self._isGroupMember(admin_id, groups[group], groups):
            self.permCache[group] = mode
            return mode

        self.permCache[group] = SESSION_NONE
        return SESSION_NONE
Пример #2
0
    def getGroupMemberships(self):
        """Returns a list of all groups this session belongs to"""
        # Import here to avoid circular dependencies
        from crcnetd.modules.ccs_contact import getUserCache, getCustomerCache, getGroupCache

        # Check group membership
        users = getUserCache(self.session_id)
        customers = getCustomerCache(self.session_id)
        groups = getGroupCache(self.session_id)
        if self.login_id in users.keys():
            contact_id = users[self.login_id]["admin_id"]
        else:
            return []
        
        # Cache memberships
        res = []
        for group in groups.keys():
            if self._isGroupMember(contact_id, groups[group], groups):
                res.append(group)
        return res