Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #530 from jpkrohling/HAWKULAR-60-TransferOrganizat…
Browse files Browse the repository at this point in the history
…ionOwner

HAWKULAR-60 - Transfer of organization
  • Loading branch information
mtho11 committed Oct 7, 2015
2 parents 18b7f39 + 93cbe3e commit 7680cf7
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>No members.</h1>
<span ng-show="membership.member.id === controller.organization.owner.id">Owner</span>

<span ng-show="membership.member.id !== controller.organization.owner.id">
<span ng-show="controller.isAllowedToTransferOrganization">
<span ng-show="controller.isAllowedToChangeRoleOfMembers">
<select
ng-model="membership.role"
ng-change="controller.changeRole(membership)"
Expand All @@ -64,7 +64,7 @@ <h1>No members.</h1>
</select>
</span>

<span ng-show="!controller.isAllowedToTransferOrganization">
<span ng-show="!controller.isAllowedToChangeRoleOfMembers">
{{membership.role.name}}
</span>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="modal-header">
<button type="button" class="close" dismiss="modal" aria-label="Close" ng-click="transferModal.cancel()">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Transfer ownership</h4>
</div>

<div class="modal-body">
Are you sure you want to transfer the ownership of
{{transferModal.organization.name}}
to
{{transferModal.transferTo.name}}?
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" dismiss="modal" ng-click="transferModal.cancel()"
id="transferOrgCancelBtn">
Cancel
</button>
<button type="button" class="btn btn-danger" id="transferOrgTransferBtn" ng-click="transferModal.transfer()">
Transfer
</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ module HawkularAccounts {
}

export interface IOrganization extends IPersona {
owner: IPersona;
$update(options:{},
success?:(success:IOrganization) => void,
failure?:(error:IErrorPayload) => void);
}

export interface IInvitation {
Expand Down Expand Up @@ -64,7 +68,10 @@ module HawkularAccounts {
organization: IOrganization;
member: IPersona;
role: IRole;
$update(options:{},
$update(options?:{},
success?:(success:ISuccessPayload) => void,
failure?:(error:IErrorPayload) => void);
$get(options?:{},
success?:(success:ISuccessPayload) => void,
failure?:(error:IErrorPayload) => void);
}
Expand Down
127 changes: 115 additions & 12 deletions console/src/main/scripts/plugins/accounts/ts/organizationMembership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module HawkularAccounts {
public isAllowedToInvite:boolean = false;
public isAllowedToListPending:boolean = false;
public isAllowedToTransferOrganization:boolean = false;
public isAllowedToChangeRoleOfMembers:boolean = false;
public membershipsToUpdate:{ [id: string]: PersistenceState; } = {};

constructor(private $log:ng.ILogService,
Expand All @@ -52,27 +53,18 @@ module HawkularAccounts {
private HawkularAccount:any,
private NotificationsService:INotificationsService) {

$log.debug('Loading memberships for this organization');
this.loading = true;
this.foundOrganization = false;
this.loadData();
this.possibleRoles = [
new Role('Monitor'),
new Role('Operator'),
new Role('Maintainer'),
new Role('Deployer'),
new Role('Administrator'),
new Role('Auditor'),
new Role('SuperUser')
];
}

public loadData():void {
this.loading = true;
let organizationId = this.$routeParams.organizationId;
this.loadOrganization(organizationId);
this.loadPermissionToInvite(organizationId);
this.loadPermissionToListPending(organizationId);
this.loadPermissionToTransferOrganization(organizationId);
this.loadPermissionToChangeRoleOfMembers(organizationId);
this.loadPossibleRoles();

this.$rootScope.$on('OrganizationLoaded', () => {
this.loadMemberships(organizationId);
Expand All @@ -83,6 +75,30 @@ module HawkularAccounts {
this.loadPendingInvitations(organizationId);
}
});

this.$rootScope.$on('PermissionToTransferOrganizationLoaded', () => {
if (this.isAllowedToTransferOrganization) {
this.possibleRoles.push(new Role('Owner'));
}
});

this.$rootScope.$on('OwnershipChanged', () => {
this.loadPossibleRoles();
});
}

public loadPossibleRoles():void {
let organizationId = this.$routeParams.organizationId;
this.possibleRoles = [
new Role('Monitor'),
new Role('Operator'),
new Role('Maintainer'),
new Role('Deployer'),
new Role('Administrator'),
new Role('Auditor'),
new Role('SuperUser')
];
this.loadPermissionToTransferOrganization(organizationId);
}

public loadOrganization(organizationId:string):void {
Expand Down Expand Up @@ -156,6 +172,7 @@ module HawkularAccounts {
this.loadPermission(organizationId, operationName,
(response:IPermissionResponse) => {
this.isAllowedToTransferOrganization = response.permitted;
this.$scope.$emit('PermissionToTransferOrganizationLoaded');
this.$log.debug(`Finished checking if we can transfer this organization. Response: ${response.permitted}`);
},
(error:IErrorPayload) => {
Expand All @@ -164,6 +181,19 @@ module HawkularAccounts {
);
}

public loadPermissionToChangeRoleOfMembers(organizationId:string):void {
const operationName:string = 'organization-change-role-of-members';
this.loadPermission(organizationId, operationName,
(response:IPermissionResponse) => {
this.isAllowedToChangeRoleOfMembers = response.permitted;
this.$log.debug(`Finished checking if we can change the role of members. Response: ${response.permitted}`);
},
(error:IErrorPayload) => {
this.$log.debug(`Error checking if we can change the role of members. Response: ${error.data.message}`);
}
);
}

public loadPermission(
resourceId:string,
operationName:string,
Expand Down Expand Up @@ -193,18 +223,69 @@ module HawkularAccounts {
}

public changeRole(membership:IOrganizationMembership):void {
if (membership.role === null) {
return;
}

if (membership.role.name === 'Owner') {
this.transferOwnership(membership);
return;
}

this.membershipsToUpdate[membership.id] = PersistenceState.PERSISTING;

membership.$update(null, (response:ISuccessPayload) => {
this.membershipsToUpdate[membership.id] = PersistenceState.SUCCESS;
// just for a moment, until we re-evaluate if the user still has the permission
this.isAllowedToChangeRoleOfMembers = false;
this.loadPermissionToChangeRoleOfMembers(this.organization.id);

}, (error:IErrorPayload) => {
this.membershipsToUpdate[membership.id] = PersistenceState.ERROR;
this.$log.debug(`Error changing role for membership. Response: ${error.data.message}`);
});

}

public transferOwnership(membership:IOrganizationMembership):void {
if (!this.isAllowedToTransferOrganization) {
this.NotificationsService.error('You don\'t have the permissions to transfer this organization.');
return;
}

let transferOrgModal = this.$modal.open({
controller: 'HawkularAccounts.OrganizationTransferModalController as transferModal',
templateUrl: 'plugins/accounts/html/organization-transfer-modal.html',
resolve: {
organization: () => this.organization,
transferTo: () => membership.member
}
});

transferOrgModal.result.then(() => {
this.organization.owner = membership.member;
this.membershipsToUpdate[membership.id] = PersistenceState.PERSISTING;
this.organization.$update(null, (response:IOrganization) => {
this.$scope.$emit('OwnershipChanged');
this.membershipsToUpdate[membership.id] = PersistenceState.SUCCESS;
this.organization = response;

// now, we refresh the memberships we have, to make sure we have the most up to date IDs
this.memberships = [];
this.loading = true;
this.loadMemberships(this.organization.id);
}, (error:IErrorPayload) => {
this.membershipsToUpdate[membership.id] = PersistenceState.ERROR;
this.$log.debug(`Error changing role for membership. Response: ${error.data.message}`);
});
}, () => {
// the modal was dismissed, get the original data for this membership
membership.$get();
});
}
}


export class OrganizationInviteModalController {
public static $inject = ['$log', '$routeParams', '$modalInstance', 'HawkularAccount', 'NotificationsService'];
public invitation:IInvitationRequest;
Expand Down Expand Up @@ -240,6 +321,28 @@ module HawkularAccounts {
}
}

export class OrganizationTransferModalController {
public static $inject = ['$log', '$routeParams', '$modalInstance', 'organization', 'transferTo'];

constructor(private $log:ng.ILogService,
private $routeParams:any,
private $modalInstance:any,
private organization:IOrganization,
private transferTo:IPersona) {
this.$log.debug('Organization received: ');
this.$log.debug(organization);
}

public cancel():void {
this.$modalInstance.dismiss('cancel');
}

public transfer():void {
this.$modalInstance.close('transfer');
}
}

_module.controller('HawkularAccounts.OrganizationMembershipController', OrganizationMembershipController);
_module.controller('HawkularAccounts.OrganizationInviteModalController', OrganizationInviteModalController);
_module.controller('HawkularAccounts.OrganizationTransferModalController', OrganizationTransferModalController);
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<version.com.google.guava>16.0.1</version.com.google.guava>
<version.commons.io>2.4</version.commons.io>
<version.gnu.getopt>1.0.13</version.gnu.getopt>
<version.org.hawkular.accounts>1.0.16.Final-SRC-revision-e5062a8f93d7f38c4e83c29d945155ca6e38300b</version.org.hawkular.accounts>
<version.org.hawkular.accounts>1.0.16.Final-SRC-revision-3f499fed1a9fbc506ee6f72bd346a87e87621dc3</version.org.hawkular.accounts>
<version.org.hawkular.agent>0.10.1.Final-SRC-revision-978a81e1a3f688e1505950d2c67d3c615c0b313d</version.org.hawkular.agent>
<version.org.hawkular.alerts>0.5.0.Final-SRC-revision-4b0914c22cc1bf101b339149daa6f52aa383634f</version.org.hawkular.alerts>
<version.org.hawkular.bus>0.7.0.Final</version.org.hawkular.bus>
Expand Down

0 comments on commit 7680cf7

Please sign in to comment.