mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Support adding groups to projects via share modal
This commit is contained in:
parent
d996ed6e47
commit
b0895cc6aa
2 changed files with 32 additions and 16 deletions
|
@ -4,7 +4,7 @@ define [
|
||||||
App.controller "ShareProjectModalController", ($scope, $modalInstance, $timeout, projectMembers, $modal, $http) ->
|
App.controller "ShareProjectModalController", ($scope, $modalInstance, $timeout, projectMembers, $modal, $http) ->
|
||||||
$scope.inputs = {
|
$scope.inputs = {
|
||||||
privileges: "readAndWrite"
|
privileges: "readAndWrite"
|
||||||
email: ""
|
contacts: []
|
||||||
}
|
}
|
||||||
$scope.state = {
|
$scope.state = {
|
||||||
error: null
|
error: null
|
||||||
|
@ -54,32 +54,40 @@ define [
|
||||||
$timeout -> # Give email list a chance to update
|
$timeout -> # Give email list a chance to update
|
||||||
return if $scope.inputs.contacts.length == 0
|
return if $scope.inputs.contacts.length == 0
|
||||||
|
|
||||||
console.warn "Ignoring groups for now"
|
members = $scope.inputs.contacts
|
||||||
emails = $scope.inputs.contacts.filter (contact) -> contact.type == "user"
|
|
||||||
emails = emails.map (contact) -> contact.email
|
|
||||||
$scope.inputs.contacts = []
|
$scope.inputs.contacts = []
|
||||||
$scope.state.error = null
|
$scope.state.error = null
|
||||||
$scope.state.inflight = true
|
$scope.state.inflight = true
|
||||||
|
|
||||||
console.log "Adding emails", emails
|
console.log "Adding members", members
|
||||||
|
|
||||||
do addNextMember = () ->
|
do addNextMember = () ->
|
||||||
if emails.length == 0 or !$scope.canAddCollaborators
|
if members.length == 0 or !$scope.canAddCollaborators
|
||||||
$scope.state.inflight = false
|
$scope.state.inflight = false
|
||||||
$scope.$apply()
|
$scope.$apply()
|
||||||
return
|
return
|
||||||
|
|
||||||
email = emails.shift()
|
member = members.shift()
|
||||||
projectMembers
|
if member.type == "user"
|
||||||
.addMember(email, $scope.inputs.privileges)
|
request = projectMembers.addMember(member.email, $scope.inputs.privileges)
|
||||||
|
else if member.type == "group"
|
||||||
|
request = projectMembers.addGroup(member.id, $scope.inputs.privileges)
|
||||||
|
|
||||||
|
request
|
||||||
.success (data) ->
|
.success (data) ->
|
||||||
if data?.user # data.user is false if collaborator limit is hit.
|
if data.users?
|
||||||
$scope.project.members.push data.user
|
users = data.users
|
||||||
setTimeout () ->
|
else if data.user?
|
||||||
# Give $scope a chance to update $scope.canAddCollaborators
|
users = [data.user]
|
||||||
# with new collaborator information.
|
else
|
||||||
addNextMember()
|
users = []
|
||||||
, 0
|
|
||||||
|
$scope.project.members.push users...
|
||||||
|
setTimeout () ->
|
||||||
|
# Give $scope a chance to update $scope.canAddCollaborators
|
||||||
|
# with new collaborator information.
|
||||||
|
addNextMember()
|
||||||
|
, 0
|
||||||
.error () ->
|
.error () ->
|
||||||
$scope.state.inflight = false
|
$scope.state.inflight = false
|
||||||
$scope.state.error = "Sorry, something went wrong :("
|
$scope.state.error = "Sorry, something went wrong :("
|
||||||
|
|
|
@ -17,5 +17,13 @@ define [
|
||||||
privileges: privileges
|
privileges: privileges
|
||||||
_csrf: window.csrfToken
|
_csrf: window.csrfToken
|
||||||
})
|
})
|
||||||
|
|
||||||
|
addGroup: (group_id, privileges) ->
|
||||||
|
$http.post("/project/#{ide.project_id}/group", {
|
||||||
|
group_id: group_id
|
||||||
|
privileges: privileges
|
||||||
|
_csrf: window.csrfToken
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
Loading…
Reference in a new issue