Ejemplo n.º 1
0
    def comment_spam_status(self, REQUEST):
        """
        Set comment spam status
        Status: True/False
        If it's an AJAX request return a message,
        else redirect user to the admin page
        """

        id_comment = REQUEST.form.get('id', '')
        status = str2bool(REQUEST.form.get('status', False))
        user = REQUEST.AUTHENTICATED_USER.getUserName()
        status_set = False
        translate = self.getPortalI18n().get_translation

        if self._set_comment_spam_status(id_comment, status):
            status_set = True

        if is_ajax(REQUEST):
            if status_set:
                return json_response({'status': 'success'}, REQUEST.RESPONSE)
            else:
                return json_response({'status': 'error',
                                      'message': translate(MESSAGE_ERROROCCURRED)},
                                    REQUEST.RESPONSE)
        else:
            if status_set:
                self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES, date=self.utGetTodayDate())
            else:
                self.setSessionErrorsTrans(MESSAGE_ERROROCCURRED)
            return REQUEST.RESPONSE.redirect('%s/index_html' % self.absolute_url())

        return False
Ejemplo n.º 2
0
    def comment_spam_status(self, REQUEST):
        """
        Set comment spam status
        Status: True/False
        If it's an AJAX request return a message,
        else redirect user to the admin page
        """

        id_comment = REQUEST.form.get('id', '')
        status = str2bool(REQUEST.form.get('status', False))
        status_set = False
        translate = self.getPortalI18n().get_translation

        if self._set_comment_spam_status(id_comment, status):
            status_set = True

        if is_ajax(REQUEST):
            if status_set:
                return json_response({'status': 'success'}, REQUEST.RESPONSE)
            else:
                return json_response(
                    {
                        'status': 'error',
                        'message': translate(MESSAGE_ERROROCCURRED)
                    }, REQUEST.RESPONSE)
        else:
            if status_set:
                self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                         date=self.utGetTodayDate())
            else:
                self.setSessionErrorsTrans(MESSAGE_ERROROCCURRED)
            return REQUEST.RESPONSE.redirect('%s/index_html' %
                                             self.absolute_url())

        return False
Ejemplo n.º 3
0
    def map_group_to_role(self, group, roles=[], location='',
            send_mail='', REQUEST=None):
        """ """
        def on_error(error_str):
            if REQUEST is not None:
                self.setSessionErrorsTrans(error_str)
                return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
            else:
                raise ValueError(error_str)

        if group == '':
            return on_error('No group selected')
        if roles == []:
            return on_error('No roles selected')

        if location == '/':
            location == ''
        try:
            ob = self.getSite().unrestrictedTraverse(location)
        except KeyError:
            return on_error('Invalid location path')
        ob.acl_satellite.add_group_roles(group, roles)

        if REQUEST is not None:
            manager_id = REQUEST.AUTHENTICATED_USER.getUserName()
            notify(RoleAssignmentEvent(ob, manager_id, group,
                                       roles, [], is_group=True,
                                       send_mail=send_mail))
            self.setSessionInfoTrans("Role(s) succesfully assigned")
            if is_ajax(REQUEST):
                url = REQUEST['HTTP_REFERER'] + '&s=assign_to_groups'
            else:
                url = REQUEST['HTTP_REFERER']
            return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 4
0
 def addUserRoles(self, name=[], roles=[], location="", user_location="", send_mail="", REQUEST=None):
     """ """
     super(plugLDAPUserFolder, self).addUserRoles(name, roles, location, user_location, send_mail, REQUEST)
     if REQUEST is not None:
         if is_ajax(REQUEST):
             url = REQUEST["HTTP_REFERER"] + ("?id=%s&s=assign_to_users" % self.id)
         else:
             url = REQUEST["HTTP_REFERER"] + "?id=" + self.id
         return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 5
0
 def revokeUserRoles(self, user, location, REQUEST=None):
     """ """
     super(plugLDAPUserFolder, self).revokeUserRoles(user, location, REQUEST)
     if REQUEST is not None:
         self.setSessionInfoTrans("Role(s) revoked")
         if is_ajax(REQUEST):
             url = REQUEST['HTTP_REFERER'] + '&s=manage_all'
         else:
             url = REQUEST['HTTP_REFERER']
         return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 6
0
 def revokeUserRoles(self, user, location, REQUEST=None):
     """ """
     super(plugLDAPUserFolder,
           self).revokeUserRoles(user, location, REQUEST)
     if REQUEST is not None:
         self.setSessionInfoTrans("Role(s) revoked")
         if is_ajax(REQUEST):
             url = REQUEST['HTTP_REFERER'] + '&s=manage_all'
         else:
             url = REQUEST['HTTP_REFERER']
         return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 7
0
    def map_group_to_role(self,
                          group,
                          roles=[],
                          location='',
                          send_mail='',
                          REQUEST=None):
        """ """
        def on_error(error_str):
            if REQUEST is not None:
                self.setSessionErrorsTrans(error_str)
                return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
            else:
                raise ValueError(error_str)

        if group == '':
            return on_error('No group selected')
        if roles == []:
            return on_error('No roles selected')

        if location == '/' or location == '':
            loc, location = 'all', ''
        else:
            loc = 'other'
        try:
            ob = self.getSite().unrestrictedTraverse(location)
        except KeyError:
            return on_error('Invalid location path')
        ob.acl_satellite.add_group_roles(group, roles)
        if send_mail:
            site = self.getSite()
            auth_tool = site.getAuthenticationTool()
            for user_id in self.group_member_ids(group):
                email = auth_tool.getUsersEmails([user_id])[0]
                site.sendAccountModifiedEmail(user_email,
                                              roles,
                                              loc,
                                              ob,
                                              username=user_id)

        if REQUEST is not None:
            from Products.NaayaCore.AuthenticationTool.events import RoleAssignmentEvent
            manager_id = REQUEST.AUTHENTICATED_USER.getUserName()
            notify(
                RoleAssignmentEvent(ob, manager_id, "group: %s" % group, roles,
                                    []))
            self.setSessionInfoTrans("Role(s) succesfully assigned")
            if is_ajax(REQUEST):
                url = REQUEST['HTTP_REFERER'] + '&s=assign_to_groups'
            else:
                url = REQUEST['HTTP_REFERER']
            return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 8
0
def clear_log_file(site, REQUEST=None, RESPONSE=None):
    """
    Truncate log file
    OBS: Not used

    """
    from naaya.core.utils import is_ajax
    if is_ajax(REQUEST):
        abs_path = get_log_dir(site)
        log_file = open(LOG_FILENAME, 'r+')
        log_file.truncate()
        log_file.close()
        return "SUCCESS"
    else:
        REQUEST.RESPONSE.redirect(site.absolute_url())
Ejemplo n.º 9
0
def clear_log_file(site, REQUEST=None, RESPONSE=None):
    """
    Truncate log file
    OBS: Not used

    """
    from naaya.core.utils import is_ajax
    if is_ajax(REQUEST):
        abs_path = get_log_dir(site)
        log_file = open(LOG_FILENAME, 'r+')
        log_file.truncate()
        log_file.close()
        return "SUCCESS"
    else:
        REQUEST.RESPONSE.redirect(site.absolute_url())
Ejemplo n.º 10
0
    def revoke_group_role(self, group_id, role, location, REQUEST=None):
        """ """
        ob = self.getSite().unrestrictedTraverse(location)
        ob.acl_satellite.remove_group_roles(group_id, [role])

        if REQUEST is not None:
            manager_id = REQUEST.AUTHENTICATED_USER.getUserName()
            notify(RoleAssignmentEvent(ob, manager_id, group_id,
                                       [], [role], is_group=True,
                                       send_mail='Administrator'==role))
            self.setSessionInfoTrans("Role(s) revoked")
            if is_ajax(REQUEST):
                url = REQUEST['HTTP_REFERER'] + '&s=manage_all'
            else:
                url = REQUEST['HTTP_REFERER']
            return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 11
0
    def revoke_group_role(self, group_id, role, location, REQUEST=None):
        """ """
        ob = self.getSite().unrestrictedTraverse(location)
        ob.acl_satellite.remove_group_roles(group_id, [role])

        if REQUEST is not None:
            from Products.NaayaCore.AuthenticationTool.events import RoleAssignmentEvent

            manager_id = REQUEST.AUTHENTICATED_USER.getUserName()
            notify(RoleAssignmentEvent(ob, manager_id, "group: %s" % group_id, [], [role]))
            self.setSessionInfoTrans("Role(s) revoked")
            if is_ajax(REQUEST):
                url = REQUEST["HTTP_REFERER"] + "&s=manage_all"
            else:
                url = REQUEST["HTTP_REFERER"]
            return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 12
0
    def revoke_group_role(self, group_id, role, location, REQUEST=None):
        """ """
        ob = self.getSite().unrestrictedTraverse(location)
        ob.acl_satellite.remove_group_roles(group_id, [role])

        if REQUEST is not None:
            from Products.NaayaCore.AuthenticationTool.events import RoleAssignmentEvent
            manager_id = REQUEST.AUTHENTICATED_USER.getUserName()
            notify(
                RoleAssignmentEvent(ob, manager_id, "group: %s" % group_id, [],
                                    [role]))
            self.setSessionInfoTrans("Role(s) revoked")
            if is_ajax(REQUEST):
                url = REQUEST['HTTP_REFERER'] + '&s=manage_all'
            else:
                url = REQUEST['HTTP_REFERER']
            return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 13
0
    def comment_del(self, REQUEST):
        """
        Delete a comment.
        """

        id_comment = REQUEST.form.get('id', '')
        user = REQUEST.AUTHENTICATED_USER.getUserName()

        self._comment_del(id_comment)

        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(user)

        if is_ajax(REQUEST):
            return json_response({'status': 'success'}, REQUEST.RESPONSE)
        else:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES, date=self.utGetTodayDate())
            return REQUEST.RESPONSE.redirect('%s/index_html' % self.absolute_url())
Ejemplo n.º 14
0
 def addUserRoles(self,
                  name=[],
                  roles=[],
                  location='',
                  user_location='',
                  send_mail='',
                  REQUEST=None):
     """ """
     super(plugLDAPUserFolder,
           self).addUserRoles(name, roles, location, user_location,
                              send_mail, REQUEST)
     if REQUEST is not None:
         if is_ajax(REQUEST):
             url = (REQUEST['HTTP_REFERER'] +
                    ('?id=%s&s=assign_to_users' % self.id))
         else:
             url = REQUEST['HTTP_REFERER'] + '?id=' + self.id
         return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 15
0
def clear_log_file(site, REQUEST=None, RESPONSE=None):
    """
    Truncate log file
    OBS: Not used

    """
    raise NotImplementedError

    from naaya.core.utils import is_ajax
    if is_ajax(REQUEST):
        get_log_dir(site)   # TODO: is this needed?
        # TODO: redo this
        log_file = open(LOG_FILENAME, 'r+')
        log_file.truncate()
        log_file.close()
        return "SUCCESS"
    else:
        REQUEST.RESPONSE.redirect(site.absolute_url())
Ejemplo n.º 16
0
    def revoke_group_role(self, group_id, role, location, REQUEST=None):
        """ """
        ob = self.getSite().unrestrictedTraverse(location)
        ob.acl_satellite.remove_group_roles(group_id, [role])

        if REQUEST is not None:
            manager_id = REQUEST.AUTHENTICATED_USER.getUserName()
            notify(
                RoleAssignmentEvent(ob,
                                    manager_id,
                                    group_id, [], [role],
                                    is_group=True,
                                    send_mail='Administrator' == role))
            self.setSessionInfoTrans("Role(s) revoked")
            if is_ajax(REQUEST):
                url = REQUEST['HTTP_REFERER'] + '&s=manage_all'
            else:
                url = REQUEST['HTTP_REFERER']
            return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 17
0
    def map_group_to_role(self,
                          group,
                          roles=[],
                          location='',
                          send_mail='',
                          REQUEST=None):
        """ """
        def on_error(error_str):
            if REQUEST is not None:
                self.setSessionErrorsTrans(error_str)
                return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
            else:
                raise ValueError(error_str)

        if group == '':
            return on_error('No group selected')
        if roles == []:
            return on_error('No roles selected')

        if location == '/':
            location == ''
        try:
            ob = self.getSite().unrestrictedTraverse(location)
        except KeyError:
            return on_error('Invalid location path')
        ob.acl_satellite.add_group_roles(group, roles)

        if REQUEST is not None:
            manager_id = REQUEST.AUTHENTICATED_USER.getUserName()
            notify(
                RoleAssignmentEvent(ob,
                                    manager_id,
                                    group,
                                    roles, [],
                                    is_group=True,
                                    send_mail=send_mail))
            self.setSessionInfoTrans("Role(s) succesfully assigned")
            if is_ajax(REQUEST):
                url = REQUEST['HTTP_REFERER'] + '&s=assign_to_groups'
            else:
                url = REQUEST['HTTP_REFERER']
            return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 18
0
    def map_group_to_role(self, group, roles=[], location="", send_mail="", REQUEST=None):
        """ """

        def on_error(error_str):
            if REQUEST is not None:
                self.setSessionErrorsTrans(error_str)
                return REQUEST.RESPONSE.redirect(REQUEST["HTTP_REFERER"])
            else:
                raise ValueError(error_str)

        if group == "":
            return on_error("No group selected")
        if roles == []:
            return on_error("No roles selected")

        if location == "/" or location == "":
            loc, location = "all", ""
        else:
            loc = "other"
        try:
            ob = self.getSite().unrestrictedTraverse(location)
        except KeyError:
            return on_error("Invalid location path")
        ob.acl_satellite.add_group_roles(group, roles)
        if send_mail:
            site = self.getSite()
            auth_tool = site.getAuthenticationTool()
            user_id_list = self.group_member_ids(group)
            for user_email in auth_tool.getUsersEmails(user_id_list):
                site.sendAccountModifiedEmail(user_email, roles, loc, ob)

        if REQUEST is not None:
            from Products.NaayaCore.AuthenticationTool.events import RoleAssignmentEvent

            manager_id = REQUEST.AUTHENTICATED_USER.getUserName()
            notify(RoleAssignmentEvent(ob, manager_id, "group: %s" % group, roles, []))
            self.setSessionInfoTrans("Role(s) succesfully assigned")
            if is_ajax(REQUEST):
                url = REQUEST["HTTP_REFERER"] + "&s=assign_to_groups"
            else:
                url = REQUEST["HTTP_REFERER"]
            return REQUEST.RESPONSE.redirect(url)
Ejemplo n.º 19
0
    def comment_del(self, REQUEST):
        """
        Delete a comment.
        """

        id_comment = REQUEST.form.get('id', '')
        user = REQUEST.AUTHENTICATED_USER.getUserName()

        self._comment_del(id_comment)

        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(user)

        if is_ajax(REQUEST):
            return json_response({'status': 'success'}, REQUEST.RESPONSE)
        else:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                     date=self.utGetTodayDate())
            return REQUEST.RESPONSE.redirect('%s/index_html' %
                                             self.absolute_url())