Sha256: 73b29daeedd80c28bd9baded6fe8e5ee1226daef6b1e4f237e783217b24dfd2f

Contents?: true

Size: 1.69 KB

Versions: 27

Compression:

Stored size: 1.69 KB

Contents

import { propsToCamelCase } from 'foremanReact/common/helpers';

export const REMOTE_EXECUTION = 'remoteExecution';
export const KATELLO_AGENT = 'katelloAgent';

export const defaultRemoteActionMethod = ({ hostDetails }) => {
  const {
    content_facet_attributes: contentFacetAttributes,
  } = hostDetails;
  const contentFacet = propsToCamelCase(contentFacetAttributes ?? {});
  const katelloAgentAvailable = (contentFacet.katelloAgentInstalled &&
    contentFacet.katelloAgentEnabled);
  if (contentFacet.remoteExecutionByDefault || !katelloAgentAvailable) {
    return REMOTE_EXECUTION;
  }
  return KATELLO_AGENT;
};

export const hostIsNotRegistered = ({ hostDetails }) => {
  const {
    subscription_facet_attributes: subscriptionFacetAttributes,
  } = hostDetails;
  return !subscriptionFacetAttributes?.uuid;
};

export const hostIsRegistered = ({ hostDetails }) => !hostIsNotRegistered({ hostDetails });

export const userPermissionsFromHostDetails = ({ hostDetails }) => {
  const {
    permissions: hostPermissions,
    content_facet_attributes: cfAttributes = {},
  } = hostDetails;
  return { ...hostPermissions, ...cfAttributes?.permissions };
};

// requiredPermissions is an array
// userPermissions is an object, e.g. { view_hosts: true }
export const hasRequiredPermissions = (requiredPermissions = [], userPermissions = {}) => {
  const permittedActions = Object.keys(userPermissions).filter(key => userPermissions[key]);
  return requiredPermissions.every(permission => permittedActions.includes(permission));
};

export const missingRequiredPermissions = (requiredPermissions = [], userPermissions) =>
  !hasRequiredPermissions(requiredPermissions, userPermissions);

export default defaultRemoteActionMethod;

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
katello-4.9.2 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.8.4 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.9.1 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.8.3 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.9.0 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.7.6 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.8.2 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.9.0.rc2 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.9.0.rc1 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.8.1 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.7.5 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.8.0 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.8.0.rc2 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.7.4 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.8.0.rc1 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.7.3 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.7.2 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.7.1 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.6.2.1 webpack/components/extensions/HostDetails/hostDetailsHelpers.js
katello-4.6.2 webpack/components/extensions/HostDetails/hostDetailsHelpers.js