Example #1
0
  applyStep(state, step) {
    const { type, args } = step

    if (includes(DOCUMENT_TRANSFORMS, type)) {
      let { document, selection } = state
      let [ range, ...rest ] = args
      range = range.normalize(document)
      document = document[type](range, ...rest)
      selection = selection.normalize(document)
      state = state.merge({ document, selection })
      return state
    }

    else if (includes(SELECTION_TRANSFORMS, type)) {
      let { document, selection } = state
      selection = selection[type](...args)
      selection = selection.normalize(document)
      state = state.merge({ selection })
      return state
    }

    else if (includes(STATE_TRANSFORMS, type)) {
      state = state[type](...args)
      return state
    }
  }
 const buildPage = rawPage => {
   let path = getSlug(rawPage);
   let data = rawPage.node.frontmatter;
   data.isTrending = includes(trending, path);
   data.isPopular = includes(mostPopular, path);
   return { data, path };
 };
Example #3
0
export default async ({ actionName, authInfo }) => {
  const scopes = getScopesFromAuthInfo(authInfo);

  if (includes(scopes, SITE_ADMIN)) return getOrgsFilter(authInfo);
  if (includes(scopes, ALL)) return getOrgsFilter(authInfo);

  switch (actionName) {
    case 'view': {
      const tokenType = authInfo.token.tokenType;
      switch (tokenType) {
        case 'user':
          return getUserFilter(authInfo);
        case 'organisation':
          return getOrgsFilter(authInfo);
        default:
          throw new NoAccessError();
      }
    }
    case 'create':
      if (includes(scopes, MANAGE_ALL_USERS)) return getOrgsFilter(authInfo);
      throw new NoAccessError();
    case 'edit': {
      if (includes(scopes, MANAGE_ALL_USERS)) return getOrgsFilter(authInfo);
      return getUserFilter(authInfo);
    }
    default: {
      throw new NoAccessError();
    }
  }
};
const modelFiltersOrganisation = async ({ actionName, authInfo }) => {
  const orgCreationRestricted = boolean(defaultTo(process.env.RESTRICT_CREATE_ORGANISATION, true));
  const scopes = getScopesFromAuthInfo(authInfo);

  if (includes(scopes, SITE_ADMIN)) {
    return {};
  }

  switch (actionName) {
    case 'view': {
      const organisationIds = await getUserViewableOrgs(authInfo, scopes);
      return createFilterQuery(organisationIds);
    }
    case 'create': {
      if (orgCreationRestricted && !includes(scopes, SITE_CAN_CREATE_ORG)) {
        throw new NoAccessError();
      }
      checkCreationScope(authInfo, scopes);
      break;
    }
    case 'delete': {
      const organisationIds = await getUserDeletableOrgs(authInfo, scopes);
      return createFilterQuery(organisationIds);
    }
    case 'edit': {
      const organisationIds = await getUserEditableOrgs(authInfo, scopes);
      return createFilterQuery(organisationIds);
    }
    default: {
      throw new NoAccessError();
    }
  }
};
Example #5
0
function filterFlowName( flowName ) {
	const headstartFlows = [ 'blog', 'website' ];
	if ( includes( headstartFlows, flowName ) && 'headstart' === abtest( 'headstart' ) ) {
		return 'headstart';
	}

	const altThemesFlows = [ 'blog', 'website' ];
	if ( includes( altThemesFlows, flowName ) && 'notTested' === getABTestVariation( 'headstart' ) ) {
		if ( 'altThemes' === abtest( 'altThemes' ) ) {
			return ( 'blog' === flowName ) ? 'blog-altthemes' : 'website-altthemes';
		}
	}

	let isInPreviousTest = false;

	if ( getABTestVariation( 'headstart' ) && getABTestVariation( 'headstart' ) !== 'notTested' ) {
		isInPreviousTest = true;
	}

	if ( getABTestVariation( 'altThemes' ) && getABTestVariation( 'altThemes' ) !== 'notTested' ) {
		isInPreviousTest = true;
	}

	const freePlansTestFlows = [ 'blog', 'website', 'main' ];
	if ( includes( freePlansTestFlows, flowName ) && ! isInPreviousTest ) {
		return 'skipForFree' === abtest( 'freePlansDefault' ) ? 'upgrade' : flowName;
	}

	return flowName;
}
export default function (checks = [], callback) {
  if (includes(checks, 'app')) {
    checkApp();
  }
  if (includes(checks, 'meteor')) {
    checkMeteor(callback);
  }
}
Example #7
0
const mapStateToProps = (state) => {
  const user = userSelector(state);
  const owner = channelOwnerSelector(state);
  const moderators = channelModeratorsSelector(state);
  const showClearChatButton = equals(user, owner) || includes(moderators, user._id);
  const showSlowModeControl = equals(user, owner) || includes(moderators, user._id);
  return {showClearChatButton, showSlowModeControl};
};
Example #8
0
    it('automatically adds stdout to transports if stderr transport is configured and stdout isn\'t', function () {
        var ghostLogger = new GhostLogger({
            transports: ['stderr']
        });

        should.equal(includes(ghostLogger.transports, 'stderr'), true, 'stderr transport should exist');
        should.equal(includes(ghostLogger.transports, 'stdout'), true, 'stdout transport should exist');
    });
Example #9
0
    value: function computePopupStyle(positions) {
      var style = { position: 'absolute' };

      // Do not access window/document when server side rendering
      if (!isBrowser) return style;

      var offset = this.props.offset;
      var _window = window,
          pageYOffset = _window.pageYOffset,
          pageXOffset = _window.pageXOffset;
      var _document$documentEle = document.documentElement,
          clientWidth = _document$documentEle.clientWidth,
          clientHeight = _document$documentEle.clientHeight;


      if (_includes(positions, 'right')) {
        style.right = Math.round(clientWidth - (this.coords.right + pageXOffset));
        style.left = 'auto';
      } else if (_includes(positions, 'left')) {
        style.left = Math.round(this.coords.left + pageXOffset);
        style.right = 'auto';
      } else {
        // if not left nor right, we are horizontally centering the element
        var xOffset = (this.coords.width - this.popupCoords.width) / 2;
        style.left = Math.round(this.coords.left + xOffset + pageXOffset);
        style.right = 'auto';
      }

      if (_includes(positions, 'top')) {
        style.bottom = Math.round(clientHeight - (this.coords.top + pageYOffset));
        style.top = 'auto';
      } else if (_includes(positions, 'bottom')) {
        style.top = Math.round(this.coords.bottom + pageYOffset);
        style.bottom = 'auto';
      } else {
        // if not top nor bottom, we are vertically centering the element
        var yOffset = (this.coords.height + this.popupCoords.height) / 2;
        style.top = Math.round(this.coords.bottom + pageYOffset - yOffset);
        style.bottom = 'auto';

        var _xOffset = this.popupCoords.width + 8;
        if (_includes(positions, 'right')) {
          style.right -= _xOffset;
        } else {
          style.left -= _xOffset;
        }
      }

      if (offset) {
        if (_isNumber(style.right)) {
          style.right -= offset;
        } else {
          style.left -= offset;
        }
      }

      return style;
    }
Example #10
0
 var labelElement = Label.create(label, function (elProps) {
   return {
     className: cx(
     // all label components should have the label className
     !_includes(elProps.className, 'label') && 'label',
     // add 'left|right corner'
     _includes(labelPosition, 'corner') && labelPosition)
   };
 });
Example #11
0
 hasBinding(name: string, noGlobals?) {
   if (!name) return false;
   if (this.hasOwnBinding(name)) return true;
   if (this.parentHasBinding(name, noGlobals)) return true;
   if (this.hasUid(name)) return true;
   if (!noGlobals && includes(Scope.globals, name)) return true;
   if (!noGlobals && includes(Scope.contextVariables, name)) return true;
   return false;
 }
Example #12
0
  }).then(rendered => {
    t.true(rendered.hasOwnProperty('validation'), 'Validation JS generated');
    t.true(rendered.hasOwnProperty('html'), 'HTML generated');

    t.is(typeof rendered.validation, 'string', 'Validation is a string');
    t.is(typeof rendered.html, 'string', 'HTML is a string');

    t.true(includes(rendered.html, 'class="I-am-a-test this-must__still_be123-here required--save">Plugin required save', 'label gets save required classes if class after for'));
    t.true(includes(rendered.html, 'class="I-am-a-test this-must__still_be123-here required--publish" for="', 'label gets save required classes if class before for'));
  });
Example #13
0
  }).then(rendered => {
    t.true(rendered.hasOwnProperty('validation'), 'Validation JS generated');
    t.true(rendered.hasOwnProperty('html'), 'HTML generated');

    t.is(typeof rendered.validation, 'string', 'Validation is a string');
    t.is(typeof rendered.html, 'string', 'HTML is a string');

    t.true(includes(rendered.html, 'class="required--save">Input required save', 'label gets save required classes'));
    t.true(includes(rendered.html, 'name="input-required-save--text" aria-required="true" required', 'input gets required--save'));
  });
Example #14
0
  }).then(rendered => {
    t.true(rendered.hasOwnProperty('validation'), 'Validation JS generated');
    t.true(rendered.hasOwnProperty('html'), 'HTML generated');

    t.is(typeof rendered.validation, 'string', 'Validation is a string');
    t.is(typeof rendered.html, 'string', 'HTML is a string');

    t.true(includes(rendered.html, errorMsg, 'error adds error message'));
    t.true(includes(rendered.html, 'name="email-field--email" aria-invalid="true"', 'error adds aria-invalid'));
  });
Example #15
0
	/**
	 * Returns true if the term matches the given query, or false otherwise.
	 *
	 * @param  {Object}  query Query object
	 * @param  {Object}  term  Item to consider
	 * @return {Boolean}       Whether term matches query
	 */
	matches( query, term ) {
		if ( ! query.search ) {
			return true;
		}

		const search = query.search.toLowerCase();
		return (
			( term.name && includes( term.name.toLowerCase(), search ) ) ||
			( term.slug && includes( term.slug.toLowerCase(), search ) )
		);
	}
Example #16
0
    describe(name + "/" + testSuite.title, function() {
      jest.addMatchers({
        toEqualFile,
      });

      for (const task of testSuite.tests) {
        if (
          includes(suiteOpts.ignoreTasks, task.title) ||
          includes(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)
        ) {
          continue;
        }

        it(
          task.title,
          !task.disabled &&
            function() {
              function runTask() {
                run(task);
              }

              defaults(task.options, {
                sourceMap: !!(task.sourceMappings || task.sourceMap),
              });

              extend(task.options, taskOpts);

              if (dynamicOpts) dynamicOpts(task.options, task);

              const throwMsg = task.options.throws;
              if (throwMsg) {
                // internal api doesn't have this option but it's best not to pollute
                // the options object with useless options
                delete task.options.throws;

                assert.throws(runTask, function(err) {
                  return (
                    throwMsg === true || err.message.indexOf(throwMsg) >= 0
                  );
                });
              } else {
                if (task.exec.code) {
                  const result = run(task);
                  if (result && typeof result.then === "function") {
                    return result;
                  }
                } else {
                  runTask();
                }
              }
            },
        );
      }
    });
Example #17
0
    constructor(options) {
        options = options || {};

        this.name = options.name || 'Log';
        this.env = options.env || 'development';
        this.domain = options.domain || 'localhost';
        this.transports = options.transports || ['stdout'];
        this.level = process.env.LEVEL || options.level || 'info';
        this.logBody = options.logBody || false;
        this.mode = process.env.MODE || options.mode || 'short';
        this.path = options.path || process.cwd();
        this.loggly = options.loggly || {};
        this.gelf = options.gelf || {};

        // stdout has to be on the first position in the transport,  because if the GhostLogger itself logs, you won't see the stdout print
        if (this.transports.indexOf('stdout') !== -1 && this.transports.indexOf('stdout') !== 0) {
            this.transports.splice(this.transports.indexOf('stdout'), 1);
            this.transports = ['stdout'].concat(this.transports);
        }

        // special env variable to enable long mode and level info
        if (process.env.LOIN) {
            this.level = 'info';
            this.mode = 'long';
        }

        // ensure we have a trailing slash
        if (!this.path.match(/\/$|\\$/)) {
            this.path = this.path + '/';
        }

        this.rotation = options.rotation || {
            enabled: false,
            period: '1w',
            count: 100
        };

        this.streams = {};
        this.setSerializers();

        if (includes(this.transports, 'stderr') && !includes(this.transports, 'stdout')) {
            this.transports.push('stdout');
        }

        this.transports.forEach((transport) => {
            let transportFn = `set${upperFirst(transport)}Stream`;

            if (!this[transportFn]) {
                throw new Error(`${upperFirst(transport)} is an invalid transport`);
            }

            this[transportFn]();
        });
    }
Example #18
0
exports.enabled = function(facade){
  if (!facade.enabled(this.name)) {
    return false;
  }
  // Pass through event for unbundled analytics.js integration if
  // - this event came from the browser
  // - this integration is explicitly unbundled in analytics.js
  if (facade.channel() === 'client' && includes(facade.proxy('_metadata.unbundled'), this.name)) {
    return true
  }
  return includes(this.channels, facade.channel());
};
Example #19
0
function filterFlowName( flowName ) {
	const defaultFlows = [ 'main', 'website' ];

	if ( includes( defaultFlows, flowName ) && abtest( 'freeTrialsInSignup' ) === 'enabled' ) {
		return 'free-trial';
	}

	if ( includes( defaultFlows, flowName ) && abtest( 'domainsWithPlansOnly' ) === 'plansOnly' ) {
		return 'domains-with-premium';
	}

	return flowName;
}
  mapProps: ({ horizontalAlignment, verticalAlignment, ...restProps }) => {
    const { classNames, props } = createScreenSizeClassNames(flexParentProps, restProps);

    return {
      props,
      classNames: {
        ...classNames,
        [`align-${horizontalAlignment}`]: includes(FLEX_HORIZONTAL_ALIGNMENTS, horizontalAlignment),
        [`align-${verticalAlignment}`]: includes(FLEX_VERTICAL_ALIGNMENTS, verticalAlignment),
      },
      style: { display: 'flex' },
    };
  },
Example #21
0
function filterFlowName( flowName ) {
	const defaultFlows = [ 'main', 'website' ];

	if ( includes( defaultFlows, flowName ) && abtest( 'freeTrialsInSignup' ) === 'enabled' ) {
		return 'free-trial';
	}

	if ( includes( defaultFlows, flowName ) && abtest( 'personalPlan' ) === 'show' ) {
		return 'personal';
	}

	return flowName;
}
Example #22
0
function filterFlowName( flowName ) {
	const headstartFlows = [ 'blog', 'website' ];
	if ( includes( headstartFlows, flowName ) && 'headstart' === abtest( 'headstart' ) ) {
		return 'headstart';
	}

	const altThemesFlows = [ 'blog', 'website' ];
	if ( includes( altThemesFlows, flowName ) && 'notTested' === getABTestVariation( 'headstart' ) ) {
		if ( 'altThemes' === abtest( 'altThemes' ) ) {
			return ( 'blog' === flowName ) ? 'blog-altthemes' : 'website-altthemes';
		}
	}
	return flowName;
}
 const organisationSettings = user.organisationSettings.map((organisationSetting) => {
   const orgId = organisationSetting.organisation.toString();
   const isAdmin = includes(organisationSetting.scopes, ALL);
   const isObserver = includes(organisationSetting.scopes, OBSERVER);
   const orgRoles = orgRolesMap[orgId];
   const roles = [
     ...(orgRoles && isAdmin ? [orgRoles.adminId] : []),
     ...(orgRoles && isObserver ? [orgRoles.observerId] : []),
   ];
   return {
     ...organisationSetting.toObject(),
     roles,
   };
 });
Example #24
0
const assertTest = function(stdout, stderr, opts) {
  const expectStderr = opts.stderr.trim();
  stderr = stderr.trim();

  if (opts.stderr) {
    if (opts.stderrContains) {
      expect(includes(stderr, expectStderr)).toBeTruthy();
    } else {
      expect(stderr).toBe(expectStderr);
    }
  } else if (stderr) {
    throw new Error("stderr:\n" + stderr + "\n\nstdout:\n" + stdout);
  }

  const expectStdout = opts.stdout.trim();
  stdout = stdout.trim();
  stdout = stdout.replace(/\\/g, "/");

  if (opts.stdout) {
    if (opts.stdoutContains) {
      expect(includes(stdout, expectStdout)).toBeTruthy();
    } else {
      expect(stdout).toBe(expectStdout);
    }
  } else if (stdout) {
    throw new Error("stdout:\n" + stdout);
  }

  if (opts.outFiles) {
    const actualFiles = readDir(path.join(tmpLoc));

    Object.keys(actualFiles).forEach(function(filename) {
      if (!opts.inFiles.hasOwnProperty(filename)) {
        const expected = opts.outFiles[filename];
        const actual = actualFiles[filename];

        expect(expected).not.toBeUndefined();

        if (expected) {
          expect(actual).toBe(expected);
        }
      }
    });

    Object.keys(opts.outFiles).forEach(function(filename) {
      expect(actualFiles).toHaveProperty(filename);
    });
  }
};
 renderList() {
   if (includes(this.props.omit, 'list')) return <span />
   return (
     <List
       title={this.props.plural}
       singular={this.props.singular}
       name={this.props.listQuery || this.props.plural.toLowerCase()}
       basePath={this.props.path}
       fields={this.props.listFields}
       allowSearch={this.props.allowSearch}
       canCreate={!includes(this.props.omit, 'create')}
       canUpdate={!includes(this.props.omit, 'update')}
     />
   )
 }
  requestGiveSearch(type){
    this.searchParams.type = type;

    if(!this.searchParams.keyword && includes(['ministries', '', undefined], this.searchParams.type)) {
      this.searchResults = ministries;
    }else if(!this.searchParams.keyword &&
      !this.searchParams.first_name &&
      !this.searchParams.last_name
      && this.searchParams.type === 'people'){
      this.searchResults = null;
    }else{
      this.loadingResults = true;
      this.searchError = false;
      this.designationsService.productSearch(this.searchParams)
        .subscribe((results) => {
          this.searchResults = results;
          this.loadingResults = false;
          this.analyticsFactory.search(this.searchParams, results);
        }, (error) => {
          this.searchResults = null;
          this.searchError = true;
          this.loadingResults = false;
          this.$log.error('Error loading search results', error);
        });

      if(this.searchParams.type){
        this.analyticsFactory.setEvent('search filter');
      }
    }
  }
Example #27
0
traverse.hasType = function(
  tree: Object,
  type: Object,
  blacklistTypes: Array<string>,
): boolean {
  // the node we're searching in is blacklisted
  if (includes(blacklistTypes, tree.type)) return false;

  // the type we're looking for is the same as the passed node
  if (tree.type === type) return true;

  const state = {
    has: false,
    type: type,
  };

  traverse(
    tree,
    {
      noScope: true,
      blacklist: blacklistTypes,
      enter: hasBlacklistedType,
    },
    null,
    state,
  );

  return state.has;
};
Example #28
0
    combinedArgs.forEach((arg) => {
      const [flag] = arg.split("=");

      switch (flag) {
        case "-d":
          nodeFlags.push("--debug"); break;

        case "debug": case "--debug": case "--debug-brk":
          nodeFlags.push(arg); break;

        case "--gc": case "--expose-gc":
          nodeFlags.push("--expose-gc"); break;

        case "--nolazy":
          nodeFlags.push("--nolazy"); break;

        // TODO
        // case "-c": case "--child":
        //   forceChild = true;

        default:
          if (includes(v8Flags, arg) || arg.indexOf("--trace") === 0) {
            nodeFlags.push(arg);
          } else {
            cmd.push(arg);
          }
      }
    });
Example #29
0
  handleOptionClick(optionId, value, topologyId) {
    let nextOptions = [value];
    const { activeOptions, options } = this.props;
    const selectedOption = options.find(o => o.get('id') === optionId);

    if (selectedOption.get('selectType') === 'union') {
      // Multi-select topology options (such as k8s namespaces) are handled here.
      // Users can select one, many, or none of these options.
      // The component builds an array of the next selected values that are sent to the action.
      const opts = activeOptions.toJS();
      const selected = selectedOption.get('id');
      const selectedActiveOptions = opts[selected] || [];
      const isSelectedAlready = includes(selectedActiveOptions, value);

      if (isSelectedAlready) {
        // Remove the option if it is already selected
        nextOptions = selectedActiveOptions.filter(o => o !== value);
      } else {
        // Add it to the array if it's not selected
        nextOptions = selectedActiveOptions.concat(value);
      }
      // Since the user is clicking an option, remove the highlighting from the none option,
      // unless they are removing the last option. In that case, default to the none label.
      // Note that since the other ids are potentially user-controlled (eg. k8s namespaces),
      // the only string we can use for the none option is the empty string '',
      // since that can't collide.
      if (nextOptions.length === 0) {
        nextOptions = [''];
      } else {
        nextOptions = nextOptions.filter(o => o !== '');
      }
    }
    this.trackOptionClick(optionId, nextOptions);
    this.props.changeTopologyOption(optionId, nextOptions, topologyId);
  }
Example #30
0
export function isSubscribedByOwnerAndSlug( state, owner, slug ) {
	const list = getListByOwnerAndSlug( state, owner, slug );
	if ( ! list ) {
		return false;
	}
	return includes( state.reader.lists.subscribedLists, list.ID );
}