Merge pull request #219 from BanzaiMan/dev/hasari/granular_perms

Add granular permission levels to User
This commit is contained in:
Piotr Sarnacki 2013-11-07 09:26:35 -08:00
commit 389f5d6b87
3 changed files with 75 additions and 11 deletions

View File

@ -31,12 +31,34 @@ require 'travis/model'
"https://github.com/#{@get('login')}"
).property()
_rawPermissions: (->
Travis.ajax.get('/users/permissions')
).property()
permissions: (->
permissions = Ember.ArrayProxy.create(content: [])
Travis.ajax.get('/users/permissions', (data) => permissions.set('content', data.permissions))
@get('_rawPermissions').then (data) => permissions.set('content', data.permissions)
permissions
).property()
adminPermissions: (->
permissions = Ember.ArrayProxy.create(content: [])
@get('_rawPermissions').then (data) => permissions.set('content', data.admin)
permissions
).property()
pullPermissions: (->
permissions = Ember.ArrayProxy.create(content: [])
@get('_rawPermissions').then (data) => permissions.set('content', data.pull)
permissions
).property()
pushPermissions: (->
permissions = Ember.ArrayProxy.create(content: [])
@get('_rawPermissions').then (data) => permissions.set('content', data.push)
permissions
).property()
updateLocale: (locale) ->
@save()
Travis.setLocale(locale)

View File

@ -107,14 +107,19 @@ Travis.reopen
displayRegenerateKey: true
canRegenerateKey: (->
@get('displayRegenerateKey') && @get('hasPermission')
).property('hasPermission')
@get('displayRegenerateKey') && @get('hasAdminPermission')
).property('hasAdminPermission')
hasPermission: (->
if permissions = @get('currentUser.permissions')
permissions.contains parseInt(@get('repo.id'))
).property('currentUser.permissions.length', 'repo.id')
hasAdminPermission: (->
if permissions = @get('currentUser.adminPermissions')
permissions.contains parseInt(@get('repo.id'))
).property('currentUser.adminPermissions.length', 'repo.id')
statusImageUrl: (->
Travis.Urls.statusImage(@get('slug'))
).property('slug')
@ -174,21 +179,26 @@ Travis.reopen
permissions.contains parseInt(@get('repo.id'))
).property('currentUser.permissions.length', 'repo.id')
hasPushPermission: (->
if permissions = @get('currentUser.pushPermissions')
permissions.contains parseInt(@get('repo.id'))
).property('currentUser.pushPermissions.length', 'repo.id')
displayRequeueBuild: (->
@get('isBuildTab') && @get('build.isFinished')
).property('isBuildTab', 'build.isFinished')
canRequeueBuild: (->
@get('displayRequeueBuild') && @get('hasPermission')
).property('displayRequireBuild', 'hasPermission')
@get('displayRequeueBuild') && @get('hasPushPermission')
).property('displayRequireBuild', 'hasPushPermission')
displayRequeueJob: (->
@get('isJobTab') && @get('job.isFinished')
).property('isJobTab', 'job.isFinished')
canRequeueJob: (->
@get('displayRequeueJob') && @get('hasPermission')
).property('displayRequeueJob', 'hasPermission')
@get('displayRequeueJob') && @get('hasPushPermission')
).property('displayRequeueJob', 'hasPushPermission')
showDownloadLog: (->
@get('jobIdForLog')
@ -205,16 +215,16 @@ Travis.reopen
).property('jobIdForLog')
canCancelBuild: (->
@get('displayCancelBuild') && @get('hasPermission')
).property('displayCancelBuild', 'hasPermission')
@get('displayCancelBuild') && @get('hasPushPermission')
).property('displayCancelBuild', 'hasPushPermission')
displayCancelBuild: (->
@get('isBuildTab') && @get('build.canCancel')
).property('isBuildTab', 'build.canCancel')
canCancelJob: (->
@get('displayCancelJob') && @get('hasPermission')
).property('displayCancelJob', 'hasPermission')
@get('displayCancelJob') && @get('hasPushPermission')
).property('displayCancelJob', 'hasPushPermission')
displayCancelJob: (->
@get('isJobTab') && @get('job.canCancel')

View File

@ -0,0 +1,32 @@
record = null
module "Travis.User",
setup: ->
teardown: ->
Travis.User.resetData()
test '', ->
$.mockjax({
url: '/users/permissions',
responseTime: 10,
responseText: {
permissions: [1],
admin: [1],
pull: [2],
push: [3]
}
});
Travis.User.load [{ id: '1', login: 'test@travis-ci.org' }]
user = null
pushPermissions = null
adminPermissions = null
Ember.run ->
user = Travis.User.find(1)
pushPermissions = user.get('pushPermissions')
adminPermissions = user.get('adminPermissions')
wait().then ->
deepEqual(adminPermissions.toArray(), [1])
deepEqual(pushPermissions.toArray(), [3])