Beispiel #1
0
def get_user_notifications(obj, event):
    """
    Collect all the users with new/changed roles and send mail    
    """
    registration = getToolByName(obj, 'portal_registration')

    # Unite user ids
    users = set(event.old_user_roles.keys())
    users.update(set(event.new_user_roles.keys()))

    userssource = UsersSource(obj)

    notifications = {}

    for user in users:
        old_roles = event.old_user_roles.get(user, [])
        new_roles = event.new_user_roles.get(user, [])
        # Ony notify if something has changed
        if old_roles != new_roles:
            # Get the email and if it is ok store the notification
            # information
            user = userssource.get(user)
            user_id = user.getId()
            email = user.getProperty('email', None)
            if email and registration.isValidEmail(email):
                notifications[user_id] = {
                    'old_roles': set(old_roles),
                    'new_roles': set(new_roles),
                    'email': email,
                }

    return notifications
def get_user_notifications(obj, event):
    """
    Collect all the users with new/changed roles and send mail    
    """   
    registration = getToolByName(obj, 'portal_registration')

    # Unite user ids
    users = set(event.old_user_roles.keys())
    users.update(set(event.new_user_roles.keys()))

    userssource = UsersSource(obj)

    notifications = {}

    for user in users:
        old_roles = event.old_user_roles.get(user, [])
        new_roles = event.new_user_roles.get(user, [])
        # Ony notify if something has changed
        if old_roles != new_roles:
            # Get the email and if it is ok store the notification 
            # information
            user = userssource.get(user)
            user_id = user.getId()
            email = user.getProperty('email', None)
            if email and registration.isValidEmail(email):
                notifications[user_id] = {'old_roles':set(old_roles),
                                          'new_roles':set(new_roles),
                                          'email':email,
                                         }

    return notifications
    def existing_role_settings(self):
        """Get current settings for users and groups that have already got
        at least one of the managed roles.

        Returns a list of dicts as per role_settings()
        """
        context = aq_inner(self.context)

        # Compile a list of user and group information with their roles
        info = []

        # Only accept known roles in the result list
        knownroles = self.roles()

        if context.user_roles:
            userssource = UsersSource(context)
            for user_id, user_roles in context.user_roles.items():
                # Fetch the user and compile the existing role settings
                user = userssource.get(user_id)
                if user is None:
                    continue
                roles = {}
                for role in knownroles:
                    # Only return information on any known roles
                    if role['id'] in user_roles:
                        roles[role['id']] = True
                    else:
                        roles[role['id']] = False
                if roles:
                    # Only add the user info if he has any role
                    info.append({'type': 'user',
                                 'id': user_id,
                                 'title': user.getProperty('fullname', None) or user.getId(),
                                 'roles': roles,
                            })

        if context.group_roles:
            groupssource = GroupsSource(context)
            for group_id, group_roles in context.group_roles.items():
                # Fetch the group and compile the existing role settings
                group = groupssource.get(group_id)
                if group is None:
                    continue
                roles = {}
                for role in knownroles:
                    # Only return information on any known roles
                    if role['id'] in group_roles:
                        roles[role['id']] = True
                    else:
                        roles[role['id']] = False
                if roles:
                    # Only add the group info if it has any role
                    info.append({'type': 'group',
                                 'id': group_id,
                                 'title': group.getProperty('title', None) or group.getId(),
                                 'roles': roles,
                                })

        return info
Beispiel #4
0
 def _get_user_mails(self, user):
     """
     Get the user information if he has local roles
     """
     is_valid_email = self.portal_registration.isValidEmail
     context = aq_inner(self.context)
     emails = {}
     userssource = UsersSource(context)
     if not context.user_roles is None and user in context.user_roles:
         # Send mail to a specific user
         # The user does really have a local role here
         user_object = userssource.get(user)
         user_mail = user_object.getProperty('email', None)
         # Make sure the email address is valid
         if user_mail and is_valid_email(user_mail):
             user_name = user_object.getProperty('fullname', None)
             emails[user] = [user_name, user, user_mail]
         return emails.values()
 def _get_user_mails(self, user):
     """
     Get the user information if he has local roles
     """
     is_valid_email = self.portal_registration.isValidEmail
     context = aq_inner(self.context)
     emails = {}
     userssource = UsersSource(context)
     if not context.user_roles is None and user in context.user_roles:
         # Send mail to a specific user
         # The user does really have a local role here
         user_object = userssource.get(user)
         user_mail = user_object.getProperty('email', None)
         # Make sure the email address is valid
         if user_mail and is_valid_email(user_mail):
             user_name = user_object.getProperty('fullname', None)
             emails[user] = [user_name, user, user_mail]
         return emails.values()
Beispiel #6
0
    def get_mails(self, role=None, user=None, group=None):
        """
        Get groupspace emails

        Returns unique emails of specific group members or groups
        """
        if user:
            return self._get_user_mails(user)

        if group:
            return self._get_group_mails(group)

        is_valid_email = self.portal_registration.isValidEmail
        context = aq_inner(self.context)
        emails = {}
        userssource = UsersSource(context)
        groupssource = GroupsSource(context)

        # From here on all users and groups are considered

        # If a specific role is given, only this is considered
        # Otherwise only the allowed roles are considered
        if not role:
            # If no specific role is given, consider them all
            groupspace_roles = set([r['id'] for r in self.roles()])
        elif role:
            # Make sure the selected role is really existing
            if role in [r['id'] for r in self.roles()]:
                groupspace_roles = set([
                    role,
                ])

        # Collect all users from the groups having local roles
        if not context.group_roles is None:
            for group, roles in context.group_roles.items():
                # Check that the group has a role that we are interested in
                if set(roles).intersection(groupspace_roles):
                    group_object = groupssource.get(group)
                    # We go through all users of the group to get the emails
                    for user_object in group_object.getGroupMembers():
                        user = user_object.getId()
                        # No need to consider users twice
                        if not user in emails:
                            user_mail = user_object.getProperty('email', None)
                            # Make sure the email address is valid
                            if user_mail and is_valid_email(user_mail):
                                user_name = user_object.getProperty(
                                    'fullname', None)
                                emails[user] = [user_name, user, user_mail]

        # Collect all users having local roles
        if not context.user_roles is None:
            for user, roles in context.user_roles.items():
                # No need to consider users twice
                if not user in emails:
                    # Check that the user has a role that we are interested in
                    if set(roles).intersection(roles):
                        user_object = userssource.get(user)
                        user_mail = user_object.getProperty('email', None)
                        # Make sure the email address is valid
                        if user_mail and is_valid_email(user_mail):
                            user_name = user_object.getProperty(
                                'fullname', None)
                            emails[user] = [user_name, user, user_mail]

        result = emails.values()
        # Sort by user name
        result.sort()
        return result
Beispiel #7
0
def onModificaColeccion(colectObj,event):
    """Listener para la modificación de una coleccion"""
    infoCoor = []
    infoInvest=[]
    groups_tool = getToolByName(colectObj, 'portal_groups')
    acl_users   = getToolByName(colectObj, 'acl_users')
    userssource = UsersSource(colectObj)

    
    if hasattr(colectObj, "coordinador"):
        coors=colectObj.coordinador
        for cor in coors:
            user=userssource.get(cor)
            user_id=cor
            infoCoor.append({'type': 'user',
                         'id': user_id,
                         'title': user.getProperty('fullname', None) or user.getId(),
                         'roles': ["Contributor"],
                         })

    
    if hasattr(colectObj, "integrantes"):
        integrantes=colectObj.integrantes
        for integrante in integrantes:
            user=userssource.get(integrante)
            user_id=integrante
            infoInvest.append({'type': 'user',
                             'id': user_id,
                             'title': user.getProperty('fullname', None) or user.getId(),
                             'roles': ["Contributor"],
                             })

    #asigna el rol de owner al grupo Coordinador con id del id deesta carpeta
    gruposVocab = GroupsSource(colectObj)
    grupIdCooR=dameGroupNameFrom(colectObj).replace("_g",PREFIJO_COOR_GROUP)
    grupIdPot =dameGroupNameFrom(colectObj).replace("_g",PREFIJO_COOR_POTENCIAL)
    groupIdInves=dameGroupNameFrom(colectObj)
    
    try:
        grupoObj=groups_tool.getGroupById(grupIdCooR)
    except :
        print "el grupo %s no existe" %grupIdCooR
        return

    try:
        grupoObjInvest=groups_tool.getGroupById(groupIdInves)
    except :
        print "el grupo %s no existe" %groupIdInves
        return


    #todos los usuarios asignados al grupo de coordinacion
    listUsers=grupoObj.getGroupMembers()
    listInvest=grupoObjInvest.getGroupMembers()

    
    #elimino todos de los grupos grupo
    for userO in listUsers:
        groups_tool.removePrincipalFromGroup(userO, grupIdCooR)
    for userI in listInvest:
        groups_tool.removePrincipalFromGroup(userI, groupIdInves)

        
    #Regenero los grupos con los usuarios actuales
    for userObj in infoCoor:
        groups_tool.addPrincipalToGroup(userObj["id"], grupIdCooR)
        
    for investObj in infoInvest:
        groups_tool.addPrincipalToGroup(investObj["id"], groupIdInves)
Beispiel #8
0
    def existing_role_settings(self):
        """Get current settings for users and groups that have already got
        at least one of the managed roles.

        Returns a list of dicts as per role_settings()
        """
        context = aq_inner(self.context)

        # Compile a list of user and group information with their roles
        info = []

        # Only accept known roles in the result list
        knownroles = self.roles()

        if context.user_roles:
            userssource = UsersSource(context)
            for user_id, user_roles in context.user_roles.items():
                # Fetch the user and compile the existing role settings
                user = userssource.get(user_id)
                if user is None:
                    continue
                roles = {}
                for role in knownroles:
                    # Only return information on any known roles
                    if role['id'] in user_roles:
                        roles[role['id']] = True
                    else:
                        roles[role['id']] = False
                if roles:
                    # Only add the user info if he has any role
                    info.append({
                        'type':
                        'user',
                        'id':
                        user_id,
                        'title':
                        user.getProperty('fullname', None) or user.getId(),
                        'roles':
                        roles,
                    })

        if context.group_roles:
            groupssource = GroupsSource(context)
            for group_id, group_roles in context.group_roles.items():
                # Fetch the group and compile the existing role settings
                group = groupssource.get(group_id)
                if group is None:
                    continue
                roles = {}
                for role in knownroles:
                    # Only return information on any known roles
                    if role['id'] in group_roles:
                        roles[role['id']] = True
                    else:
                        roles[role['id']] = False
                if roles:
                    # Only add the group info if it has any role
                    info.append({
                        'type':
                        'group',
                        'id':
                        group_id,
                        'title':
                        group.getProperty('title', None) or group.getId(),
                        'roles':
                        roles,
                    })

        return info
    def get_mails(self, role=None, user=None, group=None):
        """
        Get groupspace emails

        Returns unique emails of specific group members or groups
        """
        if user:
            return self._get_user_mails(user)
            
        if group:
            return self._get_group_mails(group)

        is_valid_email = self.portal_registration.isValidEmail 
        context = aq_inner(self.context)        
        emails = {}     
        userssource = UsersSource(context)
        groupssource = GroupsSource(context)
 
        # From here on all users and groups are considered

        # If a specific role is given, only this is considered
        # Otherwise only the allowed roles are considered 
        if not role:
            # If no specific role is given, consider them all
            groupspace_roles = set([r['id'] for r in self.roles()])
        elif role:
            # Make sure the selected role is really existing
            if role in [r['id'] for r in self.roles()]:                    
                groupspace_roles = set([role, ])
 
        # Collect all users from the groups having local roles
        if not context.group_roles is None:
            for group, roles in context.group_roles.items():
                # Check that the group has a role that we are interested in
                if set(roles).intersection(groupspace_roles):
                    group_object = groupssource.get(group)
                    # We go through all users of the group to get the emails
                    for user_object in group_object.getGroupMembers():
                        user = user_object.getId()
                        # No need to consider users twice
                        if not user in emails:
                            user_mail = user_object.getProperty('email', None)
                            # Make sure the email address is valid
                            if user_mail and is_valid_email(user_mail):
                                user_name = user_object.getProperty('fullname', 
                                                                    None)
                                emails[user] = [user_name, user, user_mail]

        # Collect all users having local roles
        if not context.user_roles is None:
            for user, roles in context.user_roles.items():
                # No need to consider users twice
                if not user in emails:
                    # Check that the user has a role that we are interested in
                    if set(roles).intersection(roles):
                        user_object = userssource.get(user)        
                        user_mail = user_object.getProperty('email', None)
                        # Make sure the email address is valid
                        if user_mail and is_valid_email(user_mail):
                            user_name = user_object.getProperty('fullname', 
                                                                None)
                            emails[user] = [user_name, user, user_mail]
       
        result = emails.values()
        # Sort by user name
        result.sort()
        return result
Beispiel #10
0
def onModificaColeccion(colectObj,event):
    """Listener para la modificación de una coleccion"""
    infoCoor = []
    infoInvest=[]
    groups_tool = getToolByName(colectObj, 'portal_groups')
    acl_users   = getToolByName(colectObj, 'acl_users')
    userssource = UsersSource(colectObj)
    
    if hasattr(colectObj, "coordinador"):
        coors=colectObj.coordinador
        for cor in coors:
            user=userssource.get(cor)
            user_id=cor
            infoCoor.append({'type': 'user',
                         'id': user_id,
                         'title': user.getProperty('fullname', None) or user.getId(),
                         'roles': ["Contributor",],
                         })
            

    if hasattr(colectObj, "integrantes"):
        integrantes=colectObj.integrantes
        for integrante in integrantes:
            user=userssource.get(integrante)
            user_id=integrante
            infoInvest.append({'type': 'user',
                             'id': user_id,
                             'title': user.getProperty('fullname', None) or user.getId(),
                             'roles': ["Contributor"],
                             })

    #asigna el rol de owner al grupo Coordinador con id del id deesta carpeta
    gruposVocab = GroupsSource(colectObj)
    grupIdCooR=dameGroupNameFrom(colectObj).replace("_g",PREFIJO_COOR_GROUP)
    grupIdPot =dameGroupNameFrom(colectObj).replace("_g",PREFIJO_COOR_POTENCIAL)
    groupIdInves=dameGroupNameFrom(colectObj)
    
    try:
        grupoObj=groups_tool.getGroupById(grupIdCooR)
    except :
        print "el grupo %s no existe" %grupIdCooR
        return

    try:
        grupoObjInvest=groups_tool.getGroupById(groupIdInves)
    except :
        print "el grupo %s no existe" %groupIdInves
        return


    #todos los usuarios asignados al grupo de coordinacion
    listUsers=grupoObj.getGroupMembers()
    listInvest=grupoObjInvest.getGroupMembers()

    
    #elimino todos de los grupos grupo
    for userO in listUsers:
        groups_tool.removePrincipalFromGroup(userO, grupIdCooR)
    for userI in listInvest:
        groups_tool.removePrincipalFromGroup(userI, groupIdInves)

        
    #Regenero los grupos con los usuarios actuales
    for userObj in infoCoor:
        groups_tool.addPrincipalToGroup(userObj["id"], grupIdCooR)
        
    for investObj in infoInvest:
        groups_tool.addPrincipalToGroup(investObj["id"], groupIdInves)