mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 22:37:10 +00:00
Merge pull request #2244 from overleaf/em-ownership-transfer-frontend
Project ownership transfer for regular users GitOrigin-RevId: 70782be0b1c59980dce0ad61ff2a7fbc1dbf0566
This commit is contained in:
parent
dbefd0366a
commit
dad0b56813
5 changed files with 93 additions and 9 deletions
|
@ -88,6 +88,7 @@ script(type='text/ng-template', id='shareProjectModalTemplate')
|
|||
.col-xs-7.form-control-static {{ member.email }}
|
||||
.col-xs-3
|
||||
select.privileges.form-control.input-sm(name="privileges" ng-model="form.privileges")
|
||||
option(value="owner") #{translate("owner")}
|
||||
option(value="readAndWrite") #{translate("can_edit")}
|
||||
option(value="readOnly") #{translate("read_only")}
|
||||
.col-xs-2.form-control-static.text-center(ng-hide="form.isModified()")
|
||||
|
@ -254,3 +255,22 @@ script(type="text/ng-template", id="shareAutocompleteTemplate")
|
|||
|
|
||||
span(ng-bind-html="$highlight(data.name)")
|
||||
span.subdued.small(ng-show="data.member_count") ({{ data.member_count }} members)
|
||||
|
||||
script(type="text/ng-template", id="ownershipTransferConfirmTemplate")
|
||||
.modal-header
|
||||
button.close(
|
||||
type="button"
|
||||
data-dismiss="modal"
|
||||
ng-click="cancel()"
|
||||
) ×
|
||||
h3 #{translate("change_project_owner")}
|
||||
.modal-body
|
||||
p !{translate('project_ownership_transfer_confirmation_1', { user: '<strong>{{ member.email }}</strong>', project: '<strong>{{ project.name }}</strong>' })}
|
||||
p #{translate('project_ownership_transfer_confirmation_2')}
|
||||
.modal-footer
|
||||
.modal-footer-left
|
||||
i.fa.fa-refresh.fa-spin(ng-show="state.inflight")
|
||||
span.text-danger.error(ng-show="state.error") #{translate("generic_something_went_wrong")}
|
||||
.modal-footer-right
|
||||
button.btn.btn-default(ng-click="cancel()") #{translate("cancel")}
|
||||
button.btn.btn-success(ng-click="confirm()") #{translate("change_owner")}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
define(['base'], App => {
|
||||
App.controller('OwnershipTransferConfirmModalController', function(
|
||||
$scope,
|
||||
$window,
|
||||
$modalInstance,
|
||||
projectMembers
|
||||
) {
|
||||
$scope.state = {
|
||||
inflight: false,
|
||||
error: false
|
||||
}
|
||||
|
||||
$scope.confirm = function() {
|
||||
const userId = $scope.member._id
|
||||
transferOwnership(userId)
|
||||
}
|
||||
|
||||
$scope.cancel = function() {
|
||||
$modalInstance.dismiss()
|
||||
}
|
||||
|
||||
function transferOwnership(userId) {
|
||||
$scope.state.inflight = true
|
||||
$scope.state.error = false
|
||||
projectMembers
|
||||
.transferOwnership(userId)
|
||||
.then(() => {
|
||||
$scope.state.inflight = false
|
||||
$scope.state.error = false
|
||||
$window.location.reload()
|
||||
})
|
||||
.catch(() => {
|
||||
$scope.state.inflight = false
|
||||
$scope.state.error = true
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
|
@ -1,6 +1,7 @@
|
|||
define(['base'], App => {
|
||||
App.controller('ShareProjectModalMemberRowController', function(
|
||||
$scope,
|
||||
$modal,
|
||||
projectMembers
|
||||
) {
|
||||
$scope.form = {
|
||||
|
@ -13,13 +14,11 @@ define(['base'], App => {
|
|||
submit() {
|
||||
const userId = $scope.member._id
|
||||
const privilegeLevel = $scope.form.privileges
|
||||
$scope.monitorRequest(
|
||||
projectMembers
|
||||
.setMemberPrivilegeLevel(userId, privilegeLevel)
|
||||
.then(() => {
|
||||
$scope.member.privileges = privilegeLevel
|
||||
})
|
||||
)
|
||||
if (privilegeLevel === 'owner') {
|
||||
openOwnershipTransferConfirmModal(userId)
|
||||
} else {
|
||||
setPrivilegeLevel(userId, privilegeLevel)
|
||||
}
|
||||
},
|
||||
|
||||
reset() {
|
||||
|
@ -27,5 +26,23 @@ define(['base'], App => {
|
|||
$scope.clearError()
|
||||
}
|
||||
}
|
||||
|
||||
function setPrivilegeLevel(userId, privilegeLevel) {
|
||||
$scope.monitorRequest(
|
||||
projectMembers
|
||||
.setMemberPrivilegeLevel(userId, privilegeLevel)
|
||||
.then(() => {
|
||||
$scope.member.privileges = privilegeLevel
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function openOwnershipTransferConfirmModal(userId) {
|
||||
$modal.open({
|
||||
templateUrl: 'ownershipTransferConfirmTemplate',
|
||||
controller: 'OwnershipTransferConfirmModalController',
|
||||
scope: $scope
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -2,6 +2,7 @@ define([
|
|||
'ide/share/controllers/ShareController',
|
||||
'ide/share/controllers/ShareProjectModalController',
|
||||
'ide/share/controllers/ShareProjectModalMemberRowController',
|
||||
'ide/share/controllers/OwnershipTransferConfirmModalController',
|
||||
'ide/share/services/projectMembers',
|
||||
'ide/share/services/projectInvites'
|
||||
], function() {})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
define(['base'], App =>
|
||||
define(['base'], App => {
|
||||
App.factory('projectMembers', (ide, $http) => ({
|
||||
removeMember(member) {
|
||||
return $http({
|
||||
|
@ -37,5 +37,13 @@ define(['base'], App =>
|
|||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
transferOwnership(userId) {
|
||||
return $http.post(`/project/${ide.project_id}/transfer-ownership`, {
|
||||
user_id: userId,
|
||||
_csrf: window.csrfToken
|
||||
})
|
||||
}
|
||||
})))
|
||||
}))
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue