Ejemplo n.º 1
0
    def remove_members(self, REQUEST):
        """ Remove several members from a role """

        agent = self._get_ldap_agent(bind=True)
        role_id = REQUEST.form['role_id']
        role_name = get_role_name(agent, role_id)
        country_code = role_id.rsplit('-', 1)[-1]
        if not self._allowed(agent, REQUEST, country_code):
            return None
        user_id_list = REQUEST.form.get('user_id_list', [])
        assert type(user_id_list) is list

        if user_id_list:
            with agent.new_action():
                for user_id in user_id_list:
                    roles_id_list = agent.remove_from_role(
                        role_id, 'user', user_id)
                    log.info("%s REMOVED USER %s FROM ROLES %r",
                             logged_in_user(REQUEST), user_id, roles_id_list)

            msg = "Users %r removed from role %s" % (user_id_list, role_name)
            _set_session_message(REQUEST, 'info', msg)

        if '-nrc-' in role_id:
            REQUEST.RESPONSE.redirect(self.absolute_url() +
                                      '/nrcs?nfp=%s#role_%s' %
                                      (country_code, role_id))
        if '-awp-' in role_id:
            REQUEST.RESPONSE.redirect(self.absolute_url() +
                                      '/awps?nfp=%s#role_%s' %
                                      (country_code, role_id))
Ejemplo n.º 2
0
    def remove_members_html(self, REQUEST):
        """ Bulk-remove several members """

        role_id = REQUEST.form['role_id']
        country_code = role_id.rsplit('-', 1)[-1]
        country_name = code_to_name(country_code)
        agent = self._get_ldap_agent()
        role_name = get_role_name(agent, role_id)
        if not self._allowed(agent, REQUEST, country_code):
            return None
        options = {
            'role_id': role_id,
            'role_name': role_name,
            'country': country_code,
            'country_name': country_name,
            'role_members': role_members(agent, role_id),
        }

        if '-nrc-' in role_id:
            self._set_breadcrumbs([
                ("Browsing NRC-s in %s" % country_name,
                 self.absolute_url() + '/nrcs?nfp=%s' % country_code),
                ("Remove members", "#")
            ])
        elif '-awp-' in role_id:
            self._set_breadcrumbs([
                ("Browsing reporters in %s" % country_name,
                 self.absolute_url() + '/awps?nfp=%s' % country_code),
                ("Remove members", "#")
            ])
        return self._render_template('zpt/nfp_nrc/remove_members.zpt',
                                     **options)
Ejemplo n.º 3
0
    def remove_members(self, REQUEST):
        """ Remove several members from a role """

        agent = self._get_ldap_agent(bind=True)
        role_id = REQUEST.form['role_id']
        role_name = get_role_name(agent, role_id)
        country_code = role_id.rsplit('-', 1)[-1]
        if not self._allowed(agent, REQUEST, country_code):
            return None
        user_id_list = REQUEST.form.get('user_id_list', [])
        assert type(user_id_list) is list

        if user_id_list:
            with agent.new_action():
                for user_id in user_id_list:
                    roles_id_list = agent.remove_from_role(role_id,
                                                           'user',
                                                           user_id)
                    log.info("%s REMOVED USER %s FROM ROLES %r",
                             logged_in_user(REQUEST), user_id, roles_id_list)

            msg = "Users %r removed from role %s" % (user_id_list, role_name)
            _set_session_message(REQUEST, 'info', msg)

        if '-nrc-' in role_id:
            REQUEST.RESPONSE.redirect(self.absolute_url() +
                                      '/nrcs?nfp=%s#role_%s' %
                                      (country_code, role_id))
        if '-awp-' in role_id:
            REQUEST.RESPONSE.redirect(self.absolute_url() +
                                      '/awps?nfp=%s#role_%s' %
                                      (country_code, role_id))
Ejemplo n.º 4
0
    def remove_members_html(self, REQUEST):
        """ Bulk-remove several members """

        role_id = REQUEST.form['role_id']
        country_code = role_id.rsplit('-', 1)[-1]
        country_name = code_to_name(country_code)
        agent = self._get_ldap_agent()
        role_name = get_role_name(agent, role_id)
        if not self._allowed(agent, REQUEST, country_code):
            return None
        options = {
            'role_id': role_id,
            'role_name': role_name,
            'country': country_code,
            'country_name': country_name,
            'role_members': role_members(agent, role_id),
        }

        if '-nrc-' in role_id:
            self._set_breadcrumbs([("Browsing NRC-s in %s" % country_name,
                                    self.absolute_url() + '/nrcs?nfp=%s' %
                                    country_code),
                                  ("Remove members", "#")])
        elif '-awp-' in role_id:
            self._set_breadcrumbs([("Browsing reporters in %s" % country_name,
                                    self.absolute_url() + '/awps?nfp=%s' %
                                    country_code),
                                  ("Remove members", "#")])
        return self._render_template('zpt/nfp_nrc/remove_members.zpt',
                                     **options)
Ejemplo n.º 5
0
    def add_user(self, REQUEST):
        """ Add user `user_id` to role `role_id`;

        This is used to add a user to an NRC role
        """

        role_id = REQUEST.form['role_id']
        country_code = role_id.rsplit('-', 1)[-1]
        user_id = REQUEST.form['user_id']
        agent = self._get_ldap_agent(bind=True)
        if not self._allowed(agent, REQUEST, country_code):
            return None

        with agent.new_action():
            role_id_list = agent.add_to_role(role_id, 'user', user_id)

        role_msg = get_role_name(agent, role_id)
        msg = "User %r added to role %s. \n" % (user_id, role_msg)

        # for NRC roles only, test if the added user is member of a national
        # organisation
        if '-nrc-' in role_id:
            if not get_national_org(agent, user_id, role_id):
                msg += ("The user you added as an NRC does not have a "
                        "mandatory reference to an organisation for your "
                        "country. Please corect!")

        _set_session_message(REQUEST, 'info', msg)

        log.info("%s ADDED USER %r TO ROLE %r", logged_in_user(REQUEST),
                 user_id, role_id_list)

        if '-nrc-' in role_id:
            REQUEST.RESPONSE.redirect(self.absolute_url() +
                                      '/nrcs?nfp=%s#role_%s' %
                                      (country_code, role_id))
        elif '-awp-' in role_id:
            REQUEST.RESPONSE.redirect(self.absolute_url() +
                                      '/awps?nfp=%s#role_%s' %
                                      (country_code, role_id))
Ejemplo n.º 6
0
    def add_user(self, REQUEST):
        """ Add user `user_id` to role `role_id`;

        This is used to add a user to an NRC role
        """

        role_id = REQUEST.form['role_id']
        country_code = role_id.rsplit('-', 1)[-1]
        user_id = REQUEST.form['user_id']
        agent = self._get_ldap_agent(bind=True)
        if not self._allowed(agent, REQUEST, country_code):
            return None

        with agent.new_action():
            role_id_list = agent.add_to_role(role_id, 'user', user_id)

        role_msg = get_role_name(agent, role_id)
        msg = "User %r added to role %s. \n" % (user_id, role_msg)

        # for NRC roles only, test if the added user is member of a national
        # organisation
        if '-nrc-' in role_id:
            if not get_national_org(agent, user_id, role_id):
                msg += ("The user you added as an NRC does not have a "
                        "mandatory reference to an organisation for your "
                        "country. Please corect!")

        _set_session_message(REQUEST, 'info', msg)

        log.info("%s ADDED USER %r TO ROLE %r",
                 logged_in_user(REQUEST), user_id, role_id_list)

        if '-nrc-' in role_id:
            REQUEST.RESPONSE.redirect(self.absolute_url() +
                                      '/nrcs?nfp=%s#role_%s' %
                                      (country_code, role_id))
        elif '-awp-' in role_id:
            REQUEST.RESPONSE.redirect(self.absolute_url() +
                                      '/awps?nfp=%s#role_%s' %
                                      (country_code, role_id))