use of com.cloud.api.command.user.iso.ListIsoPermissionsCmd in project cosmic by MissionCriticalCloud.
the class TemplateManagerImpl method listTemplatePermissions.
@Override
public List<String> listTemplatePermissions(final BaseListTemplateOrIsoPermissionsCmd cmd) {
final Account caller = CallContext.current().getCallingAccount();
final Long id = cmd.getId();
if (id.equals(Long.valueOf(1))) {
throw new PermissionDeniedException("unable to list permissions for " + cmd.getMediaType() + " with id " + id);
}
final VirtualMachineTemplate template = this._tmpltDao.findById(id);
if (template == null) {
throw new InvalidParameterValueException("unable to find " + cmd.getMediaType() + " with id " + id);
}
if (cmd instanceof ListTemplatePermissionsCmd) {
if (template.getFormat().equals(ImageFormat.ISO)) {
throw new InvalidParameterValueException("Please provide a valid template");
}
} else if (cmd instanceof ListIsoPermissionsCmd) {
if (!template.getFormat().equals(ImageFormat.ISO)) {
throw new InvalidParameterValueException("Please provide a valid iso");
}
}
if (!template.isPublicTemplate()) {
this._accountMgr.checkAccess(caller, null, true, template);
}
final List<String> accountNames = new ArrayList<>();
final List<LaunchPermissionVO> permissions = this._launchPermissionDao.findByTemplate(id);
if (permissions != null && !permissions.isEmpty()) {
for (final LaunchPermissionVO permission : permissions) {
final Account acct = this._accountDao.findById(permission.getAccountId());
accountNames.add(acct.getAccountName());
}
}
// also add the owner if not public
if (!template.isPublicTemplate()) {
final Account templateOwner = this._accountDao.findById(template.getAccountId());
accountNames.add(templateOwner.getAccountName());
}
return accountNames;
}
Aggregations