Skip to content

Commit

Permalink
[#8556] simplify more calls
Browse files Browse the repository at this point in the history
  • Loading branch information
brondsem authored and webjunkie01 committed Apr 4, 2024
1 parent 74e83f2 commit 1edc566
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Allura/allura/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def is_visible_to(self, user):
:rtype: bool
"""
return has_access(self, 'read')(user=user)
return has_access(self, 'read', user)

def subscribe_admins(self):
"""Subscribe all project Admins (for this Application's project) to the
Expand Down
6 changes: 3 additions & 3 deletions Allura/allura/controllers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ def repo_permissions(self, repo_path=None, username=None, **kw):
log.info("Can't find repo at %s on repo_path %s",
rest[0], repo_path)
return disallow
return dict(allow_read=has_access(c.app, 'read')(user=user),
allow_write=has_access(c.app, 'write')(user=user),
allow_create=has_access(c.app, 'create')(user=user))
return dict(allow_read=bool(has_access(c.app, 'read', user)),
allow_write=bool(has_access(c.app, 'write', user)),
allow_create=bool(has_access(c.app, 'create', user)))

@expose('jinja:allura:templates/pwd_expired.html')
@without_trailing_slash
Expand Down
2 changes: 1 addition & 1 deletion Allura/allura/ext/admin/admin_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self, project, config):

def is_visible_to(self, user):
'''Whether the user can view the app.'''
return has_access(c.project, 'create')(user=user)
return has_access(c.project, 'create', user)

@staticmethod
def installable_tools_for(project):
Expand Down
6 changes: 3 additions & 3 deletions Allura/allura/tests/model/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def test_artifact(self):
pr = M.ProjectRole.by_user(u, upsert=True)
ThreadLocalODMSession.flush_all()
REGISTRY.register(allura.credentials, allura.lib.security.Credentials())
assert not security.has_access(pg, 'delete')(user=u)
assert not security.has_access(pg, 'delete', u)
pg.acl.append(M.ACE.allow(pr._id, 'delete'))
ThreadLocalODMSession.flush_all()
assert security.has_access(pg, 'delete')(user=u)
assert security.has_access(pg, 'delete', u)
pg.acl.pop()
ThreadLocalODMSession.flush_all()
assert not security.has_access(pg, 'delete')(user=u)
assert not security.has_access(pg, 'delete', u)

def test_artifact_index(self):
pg = WM.Page(title='TestPage1')
Expand Down
2 changes: 1 addition & 1 deletion Allura/allura/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setup_method(self, method):

@patch('allura.lib.security.has_access')
def test_validate_project_15char_user(self, has_access):
has_access.return_value = TruthyCallable(lambda: True)
has_access.return_value = True
nbhd = M.Neighborhood()
self.provider.validate_project(
neighborhood=nbhd,
Expand Down
8 changes: 6 additions & 2 deletions ForgeBlog/forgeblog/tests/test_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ def test_role_assignments():
anon = M.User.anonymous()

def check_access(perm):
pred = security.has_access(c.app, perm)
return pred(user=admin), pred(user=user), pred(user=anon)
return (
security.has_access(c.app, perm, admin),
security.has_access(c.app, perm, user),
security.has_access(c.app, perm, anon),
)

assert check_access('configure') == (True, False, False)
assert check_access('read') == (True, True, True)
assert check_access('write') == (True, False, False)
Expand Down
8 changes: 6 additions & 2 deletions ForgeDiscussion/forgediscussion/tests/test_forum_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ def test_role_assignments():
anon = M.User.anonymous()

def check_access(perm):
pred = security.has_access(c.app, perm)
return pred(user=admin), pred(user=user), pred(user=anon)
return (
security.has_access(c.app, perm, admin),
security.has_access(c.app, perm, user),
security.has_access(c.app, perm, anon),
)

assert check_access('configure') == (True, False, False)
assert check_access('read') == (True, True, True)
assert check_access('unmoderated_post') == (True, True, False)
Expand Down
8 changes: 6 additions & 2 deletions ForgeFeedback/forgefeedback/tests/test_feedback_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ def test_role_assignments():
anon = M.User.anonymous()

def check_access(perm):
pred = security.has_access(c.app, perm)
return pred(user=admin), pred(user=user), pred(user=anon)
return (
security.has_access(c.app, perm, admin),
security.has_access(c.app, perm, user),
security.has_access(c.app, perm, anon),
)

assert check_access('read') == (True, True, True)
assert check_access('create') == (True, True, False)
assert check_access('update') == (True, False, False)
Expand Down
8 changes: 6 additions & 2 deletions ForgeFiles/forgefiles/tests/test_files_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ def test_role_assignments():
anon = M.User.anonymous()

def check_access(perm):
pred = security.has_access(c.app, perm)
return pred(user=admin), pred(user=user), pred(user=anon)
return (
security.has_access(c.app, perm, admin),
security.has_access(c.app, perm, user),
security.has_access(c.app, perm, anon),
)

assert check_access('read') == (True, True, True)
assert check_access('create') == (True, False, False)
assert check_access('update') == (True, False, False)
Expand Down
2 changes: 1 addition & 1 deletion ForgeShortUrl/forgeshorturl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, project, config):

def is_visible_to(self, user):
'''Whether the user can view the app.'''
return has_access(c.project, 'create')(user=user)
return has_access(c.project, 'create', user)

@property
@h.exceptionless([], log)
Expand Down
8 changes: 6 additions & 2 deletions ForgeTracker/forgetracker/tests/test_tracker_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def test_role_assignments():
anon = M.User.anonymous()

def check_access(perm):
pred = security.has_access(c.app, perm)
return pred(user=admin), pred(user=user), pred(user=anon)
return (
security.has_access(c.app, perm, admin),
security.has_access(c.app, perm, user),
security.has_access(c.app, perm, anon),
)

assert check_access('configure') == (True, False, False)
assert check_access('read') == (True, True, True)
assert check_access('update') == (True, False, False)
Expand Down
6 changes: 3 additions & 3 deletions ForgeTracker/forgetracker/tracker_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def globals(self):
return TM.Globals.query.get(app_config_id=self.config._id)

def has_access(self, user, topic):
return has_access(c.app, 'post')(user=user)
return has_access(c.app, 'post', user)

def handle_message(self, topic, message):
log.info('Message from %s (%s)',
Expand Down Expand Up @@ -834,7 +834,7 @@ def update_milestones(self, field_name=None, milestones=None, **kw):
@validate(validators=search_validators)
def search(self, q=None, query=None, project=None, columns=None, page=0, sort=None,
deleted=False, filter=None, **kw):
require(has_access(c.app, 'read'))
require_access(c.app, 'read')

if deleted and not has_access(c.app, 'delete'):
deleted = False
Expand Down Expand Up @@ -1961,7 +1961,7 @@ def __init__(self, root, field, milestone):
deleted=validators.StringBool(if_empty=False)))
def index(self, q=None, columns=None, page=0, query=None, sort=None,
deleted=False, filter=None, **kw):
require(has_access(c.app, 'read'))
require_access(c.app, 'read')
show_deleted = [False]
if deleted and has_access(c.app, 'delete'):
show_deleted = [False, True]
Expand Down
8 changes: 6 additions & 2 deletions ForgeWiki/forgewiki/tests/test_wiki_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def test_role_assignments():
anon = M.User.anonymous()

def check_access(perm):
pred = security.has_access(c.app, perm)
return pred(user=admin), pred(user=user), pred(user=anon)
return (
security.has_access(c.app, perm, admin),
security.has_access(c.app, perm, user),
security.has_access(c.app, perm, anon),
)

assert check_access('configure') == (True, False, False)
assert check_access('read') == (True, True, True)
assert check_access('create') == (True, False, False)
Expand Down
2 changes: 1 addition & 1 deletion ForgeWiki/forgewiki/wiki_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, project, config):
self.admin = WikiAdminController(self)

def has_access(self, user, topic):
return has_access(c.app, 'post')(user=user)
return has_access(c.app, 'post', user)

def handle_message(self, topic, message):
log.info('Message from %s (%s)',
Expand Down

0 comments on commit 1edc566

Please sign in to comment.