Search in sources :

Example 1 with ListIsoPermissionsCmd

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;
}
Also used : Account(com.cloud.legacymodel.user.Account) ListTemplatePermissionsCmd(com.cloud.api.command.user.template.ListTemplatePermissionsCmd) VirtualMachineTemplate(com.cloud.legacymodel.storage.VirtualMachineTemplate) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ArrayList(java.util.ArrayList) ListIsoPermissionsCmd(com.cloud.api.command.user.iso.ListIsoPermissionsCmd) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) LaunchPermissionVO(com.cloud.storage.LaunchPermissionVO)

Aggregations

ListIsoPermissionsCmd (com.cloud.api.command.user.iso.ListIsoPermissionsCmd)1 ListTemplatePermissionsCmd (com.cloud.api.command.user.template.ListTemplatePermissionsCmd)1 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)1 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)1 VirtualMachineTemplate (com.cloud.legacymodel.storage.VirtualMachineTemplate)1 Account (com.cloud.legacymodel.user.Account)1 LaunchPermissionVO (com.cloud.storage.LaunchPermissionVO)1 ArrayList (java.util.ArrayList)1