Skip to content

Commit

Permalink
Change perms when moving annotations btwn groups
Browse files Browse the repository at this point in the history
Fixes #2713.
  • Loading branch information
seanh committed Nov 16, 2015
1 parent 4d97941 commit fc6bb1b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions h/static/scripts/directive/annotation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ AnnotationController = [
# switching groups. See GH #2689 for context
if !model.id
model.group = groups.focused().id
if permissions.isShared(vm.annotation.permissions, vm.annotation.group)
model.permissions = permissions.shared(model.group)

this
]
Expand Down
37 changes: 37 additions & 0 deletions h/static/scripts/directive/test/annotation-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,43 @@ describe 'annotation', ->
$rootScope.$broadcast(events.GROUP_FOCUSED)
assert.equal(annotation.group, 'new-group')

it "updates perms when moving new annotations to the focused group", ->
# id must be null so that AnnotationController considers this a new
# annotation.
annotation.id = null
annotation.group = 'old-group'
annotation.permissions = {read: [annotation.group]}

# This is a shared annotation.
fakePermissions.isShared.returns(true)
createDirective()

# Make permissions.shared() behave like we expect it to.
fakePermissions.shared = (groupId) ->
return {read: [groupId]}

fakeGroups.focused = sinon.stub().returns({id: 'new-group'})
$rootScope.$broadcast(events.GROUP_FOCUSED)

assert.deepEqual(annotation.permissions.read, ['new-group'])

it "does not change perms when moving new private annotations", ->
# id must be null so that AnnotationController considers this a new
# annotation.
annotation.id = null
annotation.group = 'old-group'
annotation.permissions = {read: ['acct:bill@localhost']}
createDirective()

# This is a private annotation.
fakePermissions.isShared.returns(false)

fakeGroups.focused = sinon.stub().returns({id: 'new-group'})
$rootScope.$broadcast(events.GROUP_FOCUSED)

assert.deepEqual(annotation.permissions.read, ['acct:bill@localhost'],
'The annotation should still be private')


describe("AnnotationController", ->

Expand Down

0 comments on commit fc6bb1b

Please sign in to comment.