Exemple #1
0
def setupSiteSecurity(portal):
    """
        site security setup!
    """
    logger = logging.getLogger("fatac.content")
    secSchema = ISecuritySchema(portal)

    # Activa el poder crear carpetes d'usuari al fer login un usuari
    if secSchema.get_enable_user_folders() == False:
        secSchema.set_enable_user_folders(True)
        logger.info("fatac.content >> enabled user folder creation")

    # Activa el registre automatic d'usuaris al site
    if secSchema.get_enable_self_reg() == False:
        secSchema.set_enable_self_reg(True)
        logger.info("fatac.content >> enabled user registration")

    # Set the username to email login
    if secSchema.get_use_email_as_login() == False:
        secSchema.set_use_email_as_login(True)
        logger.info("fatac.content >> enabled username as email login")

    # Afegim propietat en els grups per controlar qui es el creador / Administradors
    gd_tool = getToolByName(portal, 'portal_groupdata')
    if not hasattr(gd_tool, 'delegated_group_member_managers'):
        gd_tool._setProperty('delegated_group_member_managers', (), 'lines')
        logger.info("fatac.content >> add group member managers property to portal_groupdata")

    # Si no esta creada la carpeta de grups la creem
    if "Groups" not in portal.objectIds():
        crearObjecte(portal, "Groups", "Folder", 'Groups', 'Carpeta contenidora de les carpetes de grup')
        logger.info("fatac.content >> Groups folder added")

    gtool = getToolByName(portal, 'portal_groups')
    if 'Reviewers' in gtool.listGroupNames():
        gtool.removeGroup("Reviewers")
        logger.info("fatac.content >> Removed 'Reviewers' group")
Exemple #2
0
    def __call__(self):

        context = aq_inner(self.context)
        ploneview = getMultiAdapter((self.context, self.request), name=u'plone')

        self.gtool = getToolByName(context, 'portal_groups')
        self.gdtool = getToolByName(context, 'portal_groupdata')
        self.regtool = getToolByName(context, 'portal_registration')
        self.groupname = getattr(self.request, 'groupname', None)
        self.grouproles = self.request.set('grouproles', [])
        self.group = self.gtool.getGroupById(self.groupname)
        self.grouptitle = self.groupname
        if self.group is not None:
            self.grouptitle = self.group.getGroupTitleOrName()

        self.request.set('grouproles', self.group.getRoles() if self.group else [])

        flagAdded = False

        submitted = self.request.form.get('form.submitted', False)
        if submitted:
            CheckAuthenticator(self.request)

            msg = _(u'No changes made.')
            self.group = None

            title = self.request.form.get('title', None)
            description = self.request.form.get('description', None)

            #addname = self.request.form.get('addname', None)
            addname = ploneview.normalizeString(title)

            if addname:
                if not self.regtool.isMemberIdAllowed(addname):
                    msg = _(u'The group name you entered is not valid.')
                    IStatusMessage(self.request).add(msg, 'error')
                    return self.index()

                success = self.gtool.addGroup(addname, (), (), title=title,
                                              description=description,
                                              REQUEST=self.request)
                if not success:
                    msg = _(u'Could not add group ${name}, perhaps a user or group with '
                            u'this name already exists.', mapping={u'name': addname})
                    IStatusMessage(self.request).add(msg, 'error')
                    return self.index()
                else:
                    portal = getToolByName(self, 'portal_url').getPortalObject()
                    # Si no existeix la carpeta de grup la creem
                    if addname not in portal.Groups.objectIds():
                        crearObjecte(portal.Groups, addname, 'Folder', title, description)
                        newgroup = portal.Groups[addname]
                        # Giving the group permissions to the recently created folder
                        newgroup.manage_setLocalRoles(addname, ['Owner'])
                        newgroup.indexObject()

                    # Afegim el creador a la llista de managers del grup
                    flagAdded = True

                self.group = self.gtool.getGroupById(addname)
                msg = _(u'Group ${name} has been added.',
                        mapping={u'name': addname})

            elif self.groupname:
                self.gtool.editGroup(self.groupname, roles=None, groups=None,
                                     title=title, description=description,
                                     REQUEST=context.REQUEST)
                self.group = self.gtool.getGroupById(self.groupname)
                msg = _(u'Changes saved.')

            else:
                msg = _(u'Group name required.')

            processed = {}
            for id, property in self.gdtool.propertyItems():
                processed[id] = self.request.get(id, None)

            if self.group:
                # Si hem creat un nou grup, afegim a l'usuari en la llista i dins del grup per defecte
                if flagAdded:
                    self.mtool = getToolByName(context, 'portal_membership')
                    self.userid = self.mtool.getAuthenticatedMember().getId()
                    processed['delegated_group_member_managers'] = [self.userid]
                    self.gtool.addPrincipalToGroup(self.userid, self.group.getId(), self.request)
                    context.plone_utils.addPortalMessage(_(u'Changes made.'))
                self.group.setGroupProperties(processed)

            IStatusMessage(self.request).add(msg, type=self.group and 'info' or 'error')
            if self.group and not self.groupname:
                target_url = '%s/%s' % (self.context.absolute_url(), '@@manage-groups')
                self.request.response.redirect(target_url)
                return ''

        return self.index()