コード例 #1
0
ファイル: test_helpers.py プロジェクト: abhinavthomas/allura
def test_log_if_changed():
    artifact = Mock()
    artifact.value = 'test'
    # change
    h.log_if_changed(artifact, 'value', 'changed', 'updated value')
    assert artifact.value == 'changed'
    assert len(AuditLogMock.logs) == 1
    assert AuditLogMock.logs[0] == 'updated value'

    # don't change
    h.log_if_changed(artifact, 'value', 'changed', 'updated value')
    assert artifact.value == 'changed'
    assert len(AuditLogMock.logs) == 1
    assert AuditLogMock.logs[0] == 'updated value'
コード例 #2
0
def test_log_if_changed():
    artifact = Mock()
    artifact.value = 'test'
    # change
    h.log_if_changed(artifact, 'value', 'changed', 'updated value')
    assert artifact.value == 'changed'
    assert len(AuditLogMock.logs) == 1
    assert AuditLogMock.logs[0] == 'updated value'

    # don't change
    h.log_if_changed(artifact, 'value', 'changed', 'updated value')
    assert artifact.value == 'changed'
    assert len(AuditLogMock.logs) == 1
    assert AuditLogMock.logs[0] == 'updated value'
コード例 #3
0
def test_log_if_changed():
    artifact = Mock()
    artifact.value = "test"
    # change
    h.log_if_changed(artifact, "value", "changed", "updated value")
    assert artifact.value == "changed"
    assert len(AuditLogMock.logs) == 1
    assert AuditLogMock.logs[0] == "updated value"

    # don't change
    h.log_if_changed(artifact, "value", "changed", "updated value")
    assert artifact.value == "changed"
    assert len(AuditLogMock.logs) == 1
    assert AuditLogMock.logs[0] == "updated value"
コード例 #4
0
ファイル: project.py プロジェクト: apache/allura
    def update(self, name=None, css=None, homepage=None, project_template=None, icon=None, **kw):
        nbhd = self.neighborhood
        c.project = nbhd.neighborhood_project
        h.log_if_changed(nbhd, 'name', name,
                         'change neighborhood name to %s' % name)
        nbhd_redirect = kw.pop('redirect', '')
        h.log_if_changed(nbhd, 'redirect', nbhd_redirect,
                         'change neighborhood redirect to %s' % nbhd_redirect)
        h.log_if_changed(nbhd, 'homepage', homepage,
                         'change neighborhood homepage to %s' % homepage)
        h.log_if_changed(nbhd, 'css', css,
                         'change neighborhood css to %s' % css)
        h.log_if_changed(nbhd, 'project_template', project_template,
                         'change neighborhood project template to %s'
                         % project_template)
        allow_browse = kw.get('allow_browse', False)
        h.log_if_changed(nbhd, 'allow_browse', allow_browse,
                         'change neighborhood allow browse to %s'
                         % allow_browse)
        show_title = kw.get('show_title', False)
        h.log_if_changed(nbhd, 'show_title', show_title,
                         'change neighborhood show title to %s' % show_title)
        use_wiki_page_as_root = kw.get('use_wiki_page_as_root', False)
        h.log_if_changed(nbhd, 'use_wiki_page_as_root', use_wiki_page_as_root,
                         'change use wiki page as root to %s' % use_wiki_page_as_root)
        project_list_url = kw.get('project_list_url', '')
        h.log_if_changed(nbhd, 'project_list_url', project_list_url,
                         'change neighborhood project list url to %s'
                         % project_list_url)
        tracking_id = kw.get('tracking_id', '')
        h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                         'update neighborhood tracking_id')
        prohibited_tools = kw.get('prohibited_tools', '')

        result = True
        if prohibited_tools.strip() != '':
            for prohibited_tool in prohibited_tools.split(','):
                if prohibited_tool.strip() not in g.entry_points['tool']:
                    flash('Prohibited tools "%s" is invalid' %
                          prohibited_tool.strip(), 'error')
                    result = False

        if result:
            h.log_if_changed(nbhd, 'prohibited_tools', prohibited_tools,
                             'update neighborhood prohibited tools')

        anchored_tools = kw.get('anchored_tools', '')
        validate_tools = dict()
        result = True
        if anchored_tools.strip() != '':
            try:
                validate_tools = dict(
                    (tool.split(':')[0].lower(), tool.split(':')[1])
                    for tool in anchored_tools.replace(' ', '').split(','))
            except Exception:
                flash('Anchored tools "%s" is invalid' %
                      anchored_tools, 'error')
                result = False

        for tool in validate_tools.keys():
            if tool not in g.entry_points['tool']:
                flash('Anchored tools "%s" is invalid' %
                      anchored_tools, 'error')
                result = False
        if result:
            h.log_if_changed(nbhd, 'anchored_tools', anchored_tools,
                             'update neighborhood anchored tools')

        if icon is not None and icon != '':
            if self.neighborhood.icon:
                self.neighborhood.icon.delete()
                M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
            M.AuditLog.log('update neighborhood icon')
            c.project.save_icon(icon.filename, icon.file, content_type=icon.type)
        redirect('overview')
コード例 #5
0
    def update(self, name=None, css=None, homepage=None, project_template=None, icon=None, **kw):
        nbhd = self.neighborhood
        c.project = nbhd.neighborhood_project
        h.log_if_changed(nbhd, 'name', name,
                         'change neighborhood name to %s' % name)
        nbhd_redirect = kw.pop('redirect', '')
        h.log_if_changed(nbhd, 'redirect', nbhd_redirect,
                         'change neighborhood redirect to %s' % nbhd_redirect)
        h.log_if_changed(nbhd, 'homepage', homepage,
                         'change neighborhood homepage to %s' % homepage)
        h.log_if_changed(nbhd, 'css', css,
                         'change neighborhood css to %s' % css)
        h.log_if_changed(nbhd, 'project_template', project_template,
                         'change neighborhood project template to %s'
                         % project_template)
        allow_browse = kw.get('allow_browse', False)
        h.log_if_changed(nbhd, 'allow_browse', allow_browse,
                         'change neighborhood allow browse to %s'
                         % allow_browse)
        show_title = kw.get('show_title', False)
        h.log_if_changed(nbhd, 'show_title', show_title,
                         'change neighborhood show title to %s' % show_title)
        project_list_url = kw.get('project_list_url', '')
        h.log_if_changed(nbhd, 'project_list_url', project_list_url,
                         'change neighborhood project list url to %s'
                         % project_list_url)
        tracking_id = kw.get('tracking_id', '')
        h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                         'update neighborhood tracking_id')
        anchored_tools = kw.get('anchored_tools', '')
        validate_tools = dict()
        result = True
        if anchored_tools.strip() != '':
            try:
                validate_tools = dict(
                    (tool.split(':')[0].lower(), tool.split(':')[1])
                    for tool in anchored_tools.replace(' ', '').split(','))
            except Exception:
                flash('Anchored tools "%s" is invalid' %
                      anchored_tools, 'error')
                result = False

        for tool in validate_tools.keys():
            if tool not in g.entry_points['tool']:
                flash('Anchored tools "%s" is invalid' %
                      anchored_tools, 'error')
                result = False
        if result:
            h.log_if_changed(nbhd, 'anchored_tools', anchored_tools,
                             'update neighborhood anchored tools')

        if icon is not None and icon != '':
            if self.neighborhood.icon:
                self.neighborhood.icon.delete()
            M.AuditLog.log('update neighborhood icon')
            M.NeighborhoodFile.save_image(
                icon.filename, icon.file, content_type=icon.type,
                square=True, thumbnail_size=(48, 48),
                thumbnail_meta=dict(neighborhood_id=self.neighborhood._id))
        redirect('overview')
コード例 #6
0
 def update(self,
            name=None,
            css=None,
            homepage=None,
            project_template=None,
            icon=None,
            **kw):
     nbhd = self.neighborhood
     c.project = nbhd.neighborhood_project
     h.log_if_changed(nbhd, 'name', name,
                      'change neighborhood name to %s' % name)
     nbhd_redirect = kw.pop('redirect', '')
     h.log_if_changed(nbhd, 'redirect', nbhd_redirect,
                      'change neighborhood redirect to %s' % nbhd_redirect)
     h.log_if_changed(nbhd, 'homepage', homepage,
                      'change neighborhood homepage to %s' % homepage)
     h.log_if_changed(nbhd, 'css', css,
                      'change neighborhood css to %s' % css)
     h.log_if_changed(
         nbhd, 'project_template', project_template,
         'change neighborhood project template to %s' % project_template)
     allow_browse = kw.get('allow_browse', False)
     h.log_if_changed(
         nbhd, 'allow_browse', allow_browse,
         'change neighborhood allow browse to %s' % allow_browse)
     show_title = kw.get('show_title', False)
     h.log_if_changed(nbhd, 'show_title', show_title,
                      'change neighborhood show title to %s' % show_title)
     project_list_url = kw.get('project_list_url', '')
     h.log_if_changed(
         nbhd, 'project_list_url', project_list_url,
         'change neighborhood project list url to %s' % project_list_url)
     tracking_id = kw.get('tracking_id', '')
     h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                      'update neighborhood tracking_id')
     if icon is not None and icon != '':
         if self.neighborhood.icon:
             self.neighborhood.icon.delete()
         M.AuditLog.log('update neighborhood icon')
         M.NeighborhoodFile.save_image(
             icon.filename,
             icon.file,
             content_type=icon.type,
             square=True,
             thumbnail_size=(48, 48),
             thumbnail_meta=dict(neighborhood_id=self.neighborhood._id))
     redirect('overview')
コード例 #7
0
    def update(self,
               name=None,
               css=None,
               homepage=None,
               project_template=None,
               icon=None,
               **kw):
        # We need to get neighborhood from Mongo to populate Ming's session. If
        # neighborhood object is coming from cache (i.e.
        # neighborhood.cache.duration is set), then it will be absent in Ming's
        # session for current thread, thus all changes will not be flushed to
        # disk. See #7890 for details.
        nbhd = M.Neighborhood.query.get(_id=self.neighborhood._id)
        c.project = nbhd.neighborhood_project
        h.log_if_changed(nbhd, 'name', name,
                         'change neighborhood name to %s' % name)
        nbhd_redirect = kw.pop('redirect', '')
        h.log_if_changed(nbhd, 'redirect', nbhd_redirect,
                         'change neighborhood redirect to %s' % nbhd_redirect)
        h.log_if_changed(nbhd, 'homepage', homepage,
                         'change neighborhood homepage to %s' % homepage)
        h.log_if_changed(nbhd, 'css', css,
                         'change neighborhood css to %s' % css)
        h.log_if_changed(
            nbhd, 'project_template', project_template,
            'change neighborhood project template to %s' % project_template)
        allow_browse = kw.get('allow_browse', False)
        h.log_if_changed(
            nbhd, 'allow_browse', allow_browse,
            'change neighborhood allow browse to %s' % allow_browse)
        show_title = kw.get('show_title', False)
        h.log_if_changed(nbhd, 'show_title', show_title,
                         'change neighborhood show title to %s' % show_title)
        project_list_url = kw.get('project_list_url', '')
        h.log_if_changed(
            nbhd, 'project_list_url', project_list_url,
            'change neighborhood project list url to %s' % project_list_url)
        tracking_id = kw.get('tracking_id', '')
        h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                         'update neighborhood tracking_id')
        prohibited_tools = kw.get('prohibited_tools', '')

        result = True
        if prohibited_tools.strip() != '':
            for prohibited_tool in prohibited_tools.split(','):
                if prohibited_tool.strip() not in g.entry_points['tool']:
                    flash(
                        'Prohibited tools "%s" is invalid' %
                        prohibited_tool.strip(), 'error')
                    result = False

        if result:
            h.log_if_changed(nbhd, 'prohibited_tools', prohibited_tools,
                             'update neighborhood prohibited tools')

        anchored_tools = kw.get('anchored_tools', '')
        validate_tools = dict()
        result = True
        if anchored_tools.strip() != '':
            try:
                validate_tools = dict(
                    (tool.split(':')[0].lower(), tool.split(':')[1])
                    for tool in anchored_tools.replace(' ', '').split(','))
            except Exception:
                flash('Anchored tools "%s" is invalid' % anchored_tools,
                      'error')
                result = False

        for tool in validate_tools.keys():
            if tool not in g.entry_points['tool']:
                flash('Anchored tools "%s" is invalid' % anchored_tools,
                      'error')
                result = False
        if result:
            h.log_if_changed(nbhd, 'anchored_tools', anchored_tools,
                             'update neighborhood anchored tools')

        if icon is not None and icon != '':
            if self.neighborhood.icon:
                self.neighborhood.icon.delete()
            M.AuditLog.log('update neighborhood icon')
            M.NeighborhoodFile.save_image(
                icon.filename,
                icon.file,
                content_type=icon.type,
                square=True,
                thumbnail_size=(48, 48),
                thumbnail_meta=dict(neighborhood_id=self.neighborhood._id))
        redirect('overview')
コード例 #8
0
    def update(self,
               name=None,
               css=None,
               homepage=None,
               project_template=None,
               icon=None,
               **kw):
        nbhd = self.neighborhood
        c.project = nbhd.neighborhood_project
        h.log_if_changed(nbhd, 'name', name,
                         'change neighborhood name to %s' % name)
        nbhd_redirect = kw.pop('redirect', '')
        h.log_if_changed(nbhd, 'redirect', nbhd_redirect,
                         'change neighborhood redirect to %s' % nbhd_redirect)
        h.log_if_changed(nbhd, 'homepage', homepage,
                         'change neighborhood homepage to %s' % homepage)
        h.log_if_changed(nbhd, 'css', css,
                         'change neighborhood css to %s' % css)
        h.log_if_changed(
            nbhd, 'project_template', project_template,
            'change neighborhood project template to %s' % project_template)
        allow_browse = kw.get('allow_browse', False)
        h.log_if_changed(
            nbhd, 'allow_browse', allow_browse,
            'change neighborhood allow browse to %s' % allow_browse)
        show_title = kw.get('show_title', False)
        h.log_if_changed(nbhd, 'show_title', show_title,
                         'change neighborhood show title to %s' % show_title)
        use_wiki_page_as_root = kw.get('use_wiki_page_as_root', False)
        h.log_if_changed(
            nbhd, 'use_wiki_page_as_root', use_wiki_page_as_root,
            'change use wiki page as root to %s' % use_wiki_page_as_root)
        project_list_url = kw.get('project_list_url', '')
        h.log_if_changed(
            nbhd, 'project_list_url', project_list_url,
            'change neighborhood project list url to %s' % project_list_url)
        tracking_id = kw.get('tracking_id', '')
        h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                         'update neighborhood tracking_id')
        prohibited_tools = kw.get('prohibited_tools', '')

        result = True
        if prohibited_tools.strip() != '':
            for prohibited_tool in prohibited_tools.split(','):
                if prohibited_tool.strip() not in g.entry_points['tool']:
                    flash(
                        'Prohibited tools "%s" is invalid' %
                        prohibited_tool.strip(), 'error')
                    result = False

        if result:
            h.log_if_changed(nbhd, 'prohibited_tools', prohibited_tools,
                             'update neighborhood prohibited tools')

        anchored_tools = kw.get('anchored_tools', '')
        validate_tools = dict()
        result = True
        if anchored_tools.strip() != '':
            try:
                validate_tools = dict(
                    (tool.split(':')[0].lower(), tool.split(':')[1])
                    for tool in anchored_tools.replace(' ', '').split(','))
            except Exception:
                flash('Anchored tools "%s" is invalid' % anchored_tools,
                      'error')
                result = False

        for tool in validate_tools.keys():
            if tool not in g.entry_points['tool']:
                flash('Anchored tools "%s" is invalid' % anchored_tools,
                      'error')
                result = False
        if result:
            h.log_if_changed(nbhd, 'anchored_tools', anchored_tools,
                             'update neighborhood anchored tools')

        if icon is not None and icon != '':
            if self.neighborhood.icon:
                self.neighborhood.icon.delete()
                M.ProjectFile.query.remove(
                    dict(project_id=c.project._id,
                         category=re.compile(r'^icon')))
            M.AuditLog.log('update neighborhood icon')
            c.project.save_icon(icon.filename,
                                icon.file,
                                content_type=icon.type)
        redirect('overview')
コード例 #9
0
    def update(self,
               name=None,
               css=None,
               homepage=None,
               project_template=None,
               icon=None,
               **kw):
        nbhd = self.neighborhood
        c.project = nbhd.neighborhood_project
        h.log_if_changed(nbhd, 'name', name,
                         'change neighborhood name to %s' % name)
        nbhd_redirect = kw.pop('redirect', '')
        h.log_if_changed(nbhd, 'redirect', nbhd_redirect,
                         'change neighborhood redirect to %s' % nbhd_redirect)
        h.log_if_changed(nbhd, 'homepage', homepage,
                         'change neighborhood homepage to %s' % homepage)
        h.log_if_changed(nbhd, 'css', css,
                         'change neighborhood css to %s' % css)
        h.log_if_changed(
            nbhd, 'project_template', project_template,
            'change neighborhood project template to %s' % project_template)
        allow_browse = kw.get('allow_browse', False)
        h.log_if_changed(
            nbhd, 'allow_browse', allow_browse,
            'change neighborhood allow browse to %s' % allow_browse)
        show_title = kw.get('show_title', False)
        h.log_if_changed(nbhd, 'show_title', show_title,
                         'change neighborhood show title to %s' % show_title)
        project_list_url = kw.get('project_list_url', '')
        h.log_if_changed(
            nbhd, 'project_list_url', project_list_url,
            'change neighborhood project list url to %s' % project_list_url)
        tracking_id = kw.get('tracking_id', '')
        h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                         'update neighborhood tracking_id')
        anchored_tools = kw.get('anchored_tools', '')
        validate_tools = dict()
        result = True
        if anchored_tools.strip() != '':
            try:
                validate_tools = dict(
                    (tool.split(':')[0].lower(), tool.split(':')[1])
                    for tool in anchored_tools.replace(' ', '').split(','))
            except Exception:
                flash('Anchored tools "%s" is invalid' % anchored_tools,
                      'error')
                result = False

        for tool in validate_tools.keys():
            if tool not in g.entry_points['tool']:
                flash('Anchored tools "%s" is invalid' % anchored_tools,
                      'error')
                result = False
        if result:
            h.log_if_changed(nbhd, 'anchored_tools', anchored_tools,
                             'update neighborhood anchored tools')

        if icon is not None and icon != '':
            if self.neighborhood.icon:
                self.neighborhood.icon.delete()
            M.AuditLog.log('update neighborhood icon')
            M.NeighborhoodFile.save_image(
                icon.filename,
                icon.file,
                content_type=icon.type,
                square=True,
                thumbnail_size=(48, 48),
                thumbnail_meta=dict(neighborhood_id=self.neighborhood._id))
        redirect('overview')
コード例 #10
0
ファイル: project.py プロジェクト: Bitergia/allura
 def update(self, name=None, css=None, homepage=None, project_template=None, icon=None, **kw):
     nbhd = self.neighborhood
     c.project = nbhd.neighborhood_project
     h.log_if_changed(nbhd, 'name', name,
                     'change neighborhood name to %s' % name)
     nbhd_redirect = kw.pop('redirect', '')
     h.log_if_changed(nbhd, 'redirect', nbhd_redirect,
                     'change neighborhood redirect to %s' % nbhd_redirect)
     h.log_if_changed(nbhd, 'homepage', homepage,
                     'change neighborhood homepage to %s' % homepage)
     h.log_if_changed(nbhd, 'css', css,
                     'change neighborhood css to %s' % css)
     h.log_if_changed(nbhd, 'project_template', project_template,
                     'change neighborhood project template to %s'
                     % project_template)
     allow_browse = kw.get('allow_browse', False)
     h.log_if_changed(nbhd, 'allow_browse', allow_browse,
                     'change neighborhood allow browse to %s'
                     % allow_browse)
     show_title = kw.get('show_title', False)
     h.log_if_changed(nbhd, 'show_title', show_title,
                     'change neighborhood show title to %s' % show_title)
     project_list_url = kw.get('project_list_url', '')
     h.log_if_changed(nbhd, 'project_list_url', project_list_url,
                     'change neighborhood project list url to %s'
                     % project_list_url)
     tracking_id = kw.get('tracking_id', '')
     h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                     'update neighborhood tracking_id')
     if icon is not None and icon != '':
         if self.neighborhood.icon:
             self.neighborhood.icon.delete()
         M.AuditLog.log('update neighborhood icon')
         M.NeighborhoodFile.save_image(
             icon.filename, icon.file, content_type=icon.type,
             square=True, thumbnail_size=(48, 48),
             thumbnail_meta=dict(neighborhood_id=self.neighborhood._id))
     redirect('overview')
コード例 #11
0
ファイル: project.py プロジェクト: abhinavthomas/allura
    def update(self, name=None, css=None, homepage=None, project_template=None, icon=None, **kw):
        # We need to get neighborhood from Mongo to populate Ming's session. If
        # neighborhood object is coming from cache (i.e.
        # neighborhood.cache.duration is set), then it will be absent in Ming's
        # session for current thread, thus all changes will not be flushed to
        # disk. See #7890 for details.
        nbhd = M.Neighborhood.query.get(_id=self.neighborhood._id)
        c.project = nbhd.neighborhood_project
        h.log_if_changed(nbhd, 'name', name,
                         'change neighborhood name to %s' % name)
        nbhd_redirect = kw.pop('redirect', '')
        h.log_if_changed(nbhd, 'redirect', nbhd_redirect,
                         'change neighborhood redirect to %s' % nbhd_redirect)
        h.log_if_changed(nbhd, 'homepage', homepage,
                         'change neighborhood homepage to %s' % homepage)
        h.log_if_changed(nbhd, 'css', css,
                         'change neighborhood css to %s' % css)
        h.log_if_changed(nbhd, 'project_template', project_template,
                         'change neighborhood project template to %s'
                         % project_template)
        allow_browse = kw.get('allow_browse', False)
        h.log_if_changed(nbhd, 'allow_browse', allow_browse,
                         'change neighborhood allow browse to %s'
                         % allow_browse)
        show_title = kw.get('show_title', False)
        h.log_if_changed(nbhd, 'show_title', show_title,
                         'change neighborhood show title to %s' % show_title)
        project_list_url = kw.get('project_list_url', '')
        h.log_if_changed(nbhd, 'project_list_url', project_list_url,
                         'change neighborhood project list url to %s'
                         % project_list_url)
        tracking_id = kw.get('tracking_id', '')
        h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                         'update neighborhood tracking_id')
        prohibited_tools = kw.get('prohibited_tools', '')

        result = True
        if prohibited_tools.strip() != '':
            for prohibited_tool in prohibited_tools.split(','):
                if prohibited_tool.strip() not in g.entry_points['tool']:
                    flash('Prohibited tools "%s" is invalid' %
                          prohibited_tool.strip(), 'error')
                    result = False

        if result:
            h.log_if_changed(nbhd, 'prohibited_tools', prohibited_tools,
                             'update neighborhood prohibited tools')

        anchored_tools = kw.get('anchored_tools', '')
        validate_tools = dict()
        result = True
        if anchored_tools.strip() != '':
            try:
                validate_tools = dict(
                    (tool.split(':')[0].lower(), tool.split(':')[1])
                    for tool in anchored_tools.replace(' ', '').split(','))
            except Exception:
                flash('Anchored tools "%s" is invalid' %
                      anchored_tools, 'error')
                result = False

        for tool in validate_tools.keys():
            if tool not in g.entry_points['tool']:
                flash('Anchored tools "%s" is invalid' %
                      anchored_tools, 'error')
                result = False
        if result:
            h.log_if_changed(nbhd, 'anchored_tools', anchored_tools,
                             'update neighborhood anchored tools')

        if icon is not None and icon != '':
            if self.neighborhood.icon:
                self.neighborhood.icon.delete()
            M.AuditLog.log('update neighborhood icon')
            M.NeighborhoodFile.save_image(
                icon.filename, icon.file, content_type=icon.type,
                square=True, thumbnail_size=(48, 48),
                thumbnail_meta=dict(neighborhood_id=self.neighborhood._id))
        redirect('overview')