Skip to content

Commit

Permalink
Merge branch 'release/20.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fabmiz committed Mar 24, 2020
2 parents 4dea8bd + 9e851fe commit 742f12a
Show file tree
Hide file tree
Showing 106 changed files with 2,777 additions and 891 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [20.3.0] - 2020-03-23
### Added
- Ability to create/edit draft registration metadata to the Registries Submission workflow.
- Metadata to review page

## [20.2.1] - 2020-03-04
### Changed
- log registration submit errors to sentry
Expand Down Expand Up @@ -90,6 +95,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `OsfLayout::RegistriesSideNav::Label`
- `OsfLayout::RegistriesSideNav::XLink`
- `PageLink`
- `Debouncer`
- Mirage
- Factories
- `institutional-user`
Expand All @@ -100,6 +106,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- added `dashboard` nested route
- `guid-node`
- added `drafts` nested route
- `registries/drafts/draft`
- added `metadata` nested route
- Engines
- Components
- `drafts/draft/-components/register`
Expand Down Expand Up @@ -1564,7 +1572,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Quick Files

[Unreleased]: https://github.com/CenterForOpenScience/ember-osf-web/compare/20.2.1...develop
[Unreleased]: https://github.com/CenterForOpenScience/ember-osf-web/compare/20.3.0...develop
[20.3.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/20.3.0
[20.2.1]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/20.2.1
[20.2.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/20.2.0
[20.1.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/20.1.0
Expand Down
2 changes: 1 addition & 1 deletion app/guid-node/drafts/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Route from '@ember/routing/route';

export default class GuidNodeDraftsRegister extends Route {
model() {
this.replaceWith('registries.drafts.draft.page', this.modelFor('guid-node.drafts'), 'review');
this.replaceWith('registries.drafts.draft.review', this.modelFor('guid-node.drafts'));
}
}
2 changes: 1 addition & 1 deletion app/guid-node/registrations/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class GuidNodeRegistrations extends Controller {

@task
getRegistrationSchemas = task(function *(this: GuidNodeRegistrations) {
let schemas = yield this.store.findAll('registration-schema',
let schemas = yield this.store.query('registration-schema',
{
adapterOptions: {
query: {
Expand Down
37 changes: 35 additions & 2 deletions app/models/draft-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@ import DS from 'ember-data';

import { RegistrationResponse } from 'ember-osf-web/packages/registration-schema';

import NodeModel from './node';
import RegistrationProviderModel from 'ember-osf-web/models/registration-provider';
import InstitutionModel from './institution';
import LicenseModel from './license';
import NodeModel, { NodeCategory, NodeLicense } from './node';
import OsfModel from './osf-model';
import RegistrationSchemaModel, { RegistrationMetadata } from './registration-schema';
import SubjectModel from './subject';
import UserModel from './user';

const { attr, belongsTo } = DS;
const { attr, belongsTo, hasMany } = DS;

export enum DraftMetadataProperties {
Title = 'title',
Description = 'description',
Category = 'category',
AffiliatedInstitutions = 'affiliatedInstitutions',
License = 'license',
NodeLicenseProperty = 'nodeLicense',
Subjects = 'subjects',
Tags = 'tags',
}

export default class DraftRegistrationModel extends OsfModel {
@attr('fixstring') registrationSupplement!: string;
Expand All @@ -16,6 +31,12 @@ export default class DraftRegistrationModel extends OsfModel {
@attr('date') datetimeInitiated!: Date;
@attr('date') datetimeUpdated!: Date;

@attr('fixstring') title!: string;
@attr('fixstring') description!: string;
@attr('fixstringarray') tags!: string[];
@attr('node-license') nodeLicense!: NodeLicense | null;
@attr('node-category') category!: NodeCategory;

@belongsTo('node', { inverse: 'draftRegistrations' })
branchedFrom!: DS.PromiseObject<NodeModel> & NodeModel;

Expand All @@ -24,6 +45,18 @@ export default class DraftRegistrationModel extends OsfModel {

@belongsTo('registration-schema', { inverse: null })
registrationSchema!: DS.PromiseObject<RegistrationSchemaModel> & RegistrationSchemaModel;

@belongsTo('registration-provider', { inverse: null })
provider!: DS.PromiseObject<RegistrationProviderModel> & RegistrationProviderModel;

@hasMany('institution', { inverse: null, async: true })
affiliatedInstitutions!: DS.PromiseManyArray<InstitutionModel>;

@hasMany('subject', { inverse: null, async: true })
subjects!: DS.PromiseObject<SubjectModel[]> & SubjectModel[];

@belongsTo('license', { inverse: null, async: true })
license!: DS.PromiseObject<LicenseModel> & LicenseModel;
}

declare module 'ember-data/types/registries/model' {
Expand Down
2 changes: 1 addition & 1 deletion app/packages/registration-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { getPages } from './get-pages';
export { getSchemaBlockGroups } from './get-schema-block-group';
export { SchemaBlock, SchemaBlockType } from './schema-block';
export { SchemaBlockGroup } from './schema-block-group';
export { buildValidation } from './validations';
export { buildValidation, buildMetadataValidations } from './validations';
export {
FileReference,
RegistrationResponse,
Expand Down
145 changes: 121 additions & 24 deletions app/packages/registration-schema/validations.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
import { assert } from '@ember/debug';
import { set } from '@ember/object';
import { ValidationObject, ValidatorFunction } from 'ember-changeset-validations';
import { validatePresence } from 'ember-changeset-validations/validators';
import NodeModel from 'ember-osf-web/models/node';

import DraftRegistration, { DraftMetadataProperties } from 'ember-osf-web/models/draft-registration';
import NodeModel, { NodeLicense } from 'ember-osf-web/models/node';
import { RegistrationResponse } from 'ember-osf-web/packages/registration-schema';
import { SchemaBlockGroup } from 'ember-osf-web/packages/registration-schema/schema-block-group';
import { validateFileList } from 'ember-osf-web/validators/validate-response-format';

// TODO: find a way to use intl to translate error messages
export const NodeLicenseFields: Record<keyof NodeLicense, string> = {
copyrightHolders: 'Copyright Holders',
year: 'Year',
};

function getErrorType(groupType?: string) {
let validationErrorType = 'blank';
switch (groupType) {
case 'short-text-input':
break;
case 'long-text-input':
break;
case 'file-input':
validationErrorType = 'mustSelectFileMinOne';
break;
case 'single-select-input':
validationErrorType = 'mustSelect';
break;
case 'multi-select-input':
validationErrorType = 'mustSelectMinOne';
break;
default:
break;
}
return validationErrorType;
}

export function buildValidation(groups: SchemaBlockGroup[], node?: NodeModel) {
const ret: ValidationObject<RegistrationResponse> = {};
Expand All @@ -17,38 +45,20 @@ export function buildValidation(groups: SchemaBlockGroup[], node?: NodeModel) {
const responseKey = group.registrationResponseKey;
assert(`no response key for group ${group.schemaBlockGroupKey}`, Boolean(responseKey));
const { inputBlock } = group;
let type = 'blank';
switch (group.groupType) {
case 'contributors-input':
// No validation for contributors input.
return;
case 'short-text-input':
break;
case 'long-text-input':
break;
case 'file-input':
type = 'mustSelectFileMinOne';
if (group.groupType === 'file-input') {
validationForResponse.push(
validateFileList(responseKey as string, node),
);
break;
case 'single-select-input':
type = 'mustSelect';
break;
case 'multi-select-input':
type = 'mustSelectMinOne';
break;
default:
break;
}
if (inputBlock.required) {
// TODO: remove check for contributors-input
if (inputBlock.required && inputBlock.blockType !== 'contributors-input') {
validationForResponse.push(
validatePresence({
presence: true,
ignoreBlank: true,
allowBlank: false,
allowNone: false,
type,
type: getErrorType(group.groupType),
}),
);
}
Expand All @@ -57,3 +67,90 @@ export function buildValidation(groups: SchemaBlockGroup[], node?: NodeModel) {
});
return ret;
}

export function validateNodeLicense() {
return async (_: unknown, __: unknown, ___: unknown, changes: DraftRegistration, content: DraftRegistration) => {
let validateLicenseTarget = await content.license;
let validateNodeLicenseTarget = content.nodeLicense;
if (changes.license) {
validateLicenseTarget = changes.license;
}
if (changes.nodeLicense) {
validateNodeLicenseTarget = changes.nodeLicense;
}
if (!validateLicenseTarget || validateLicenseTarget.get('requiredFields').length === 0) {
return true;
}
const missingFieldsList: Array<keyof NodeLicense> = [];
for (const item of validateLicenseTarget.get('requiredFields')) {
if (!validateNodeLicenseTarget || !validateNodeLicenseTarget[item]) {
missingFieldsList.push(item);
}
}
if (missingFieldsList.length === 0) {
return true;
}
const missingFields = missingFieldsList.map(field => NodeLicenseFields[field]).join(', ');
return {
context: {
type: 'node_license_missing_fields',
translationArgs: {
missingFields,
numOfFields: missingFieldsList.length,
},
},
};
};
}

export function validateNodeLicenseYear() {
return (_: unknown, __: unknown, ___: unknown, changes: any, content: DraftRegistration) => {
let validateYearTarget: string = '';
if (content.nodeLicense && content.nodeLicense.year) {
validateYearTarget = content.nodeLicense.year;
}
if (changes.nodeLicense && changes.nodeLicense.year) {
validateYearTarget = changes.nodeLicense.year;
}
const regex = /^((?!(0))[0-9]{4})$/;
if (validateYearTarget && !validateYearTarget.match(regex)) {
return {
context: {
type: 'year_format',
},
};
}
return true;
};
}

export function validateSubjects() {
return (_: unknown, __: unknown, ___: unknown, ____: unknown, content: DraftRegistration) => {
const subjects = content.hasMany('subjects').value();
if (!subjects || subjects.length === 0) {
return {
context: {
type: 'min_subjects',
},
};
}
return true;
};
}

export function buildMetadataValidations() {
const validationObj: ValidationObject<DraftRegistration> = {};
const notBlank: ValidatorFunction[] = [validatePresence({
presence: true,
ignoreBlank: true,
allowBlank: false,
allowNone: false,
type: 'blank',
})];
set(validationObj, DraftMetadataProperties.Title, notBlank);
set(validationObj, DraftMetadataProperties.Description, notBlank);
set(validationObj, DraftMetadataProperties.License, notBlank);
set(validationObj, DraftMetadataProperties.Subjects, validateSubjects());
set(validationObj, DraftMetadataProperties.NodeLicenseProperty, [validateNodeLicense(), validateNodeLicenseYear()]);
return validationObj;
}
14 changes: 6 additions & 8 deletions app/utils/page-param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import slugify from 'ember-osf-web/utils/slugify';
* pageNumber: pageIndex + 1
*/

export const DefaultPage: number = 1;

export function getDefaultParam() {
return DefaultPage;
export function getPageSlug(pageNumber: number, pageHeading?: string) {
const slug = pageHeading ? slugify(pageHeading) : '';
return slug ? `${pageNumber}-${slug}` : `${pageNumber}`;
}

export function getPageIndex(pageParam: string): number | undefined {
Expand All @@ -20,21 +19,20 @@ export function getPageParam(
pageIndex: number,
pageHeading?: string,
) {
const slug = pageHeading ? slugify(pageHeading) : '';
const pageNumber = pageIndex + 1;
return slug ? `${pageNumber}-${slug}` : `${pageNumber}`;
return getPageSlug(pageNumber, pageHeading);
}

export function getNextPageParam(
pageIndex: number,
pageHeading: string,
pageHeading?: string,
) {
return getPageParam(pageIndex + 1, pageHeading);
}

export function getPrevPageParam(
pageIndex: number,
pageHeading: string,
pageHeading?: string,
) {
if (pageIndex === 0) {
return undefined;
Expand Down
12 changes: 6 additions & 6 deletions app/validators/node-license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export default class NodeLicenseValidator extends BaseValidator {
return this.createErrorMessage('node_license_invalid', value, options);
}

const missingFields = license.requiredFields
const missingFieldsList = license.requiredFields
.filter(field => !value[field])
.sort()
.map(field => this.intl.t(`app_components.license_picker.fields.${field}`))
.join(', ');

if (missingFields.length) {
return this.createErrorMessage('node_license_missing_fields', value, { missingFields });
.map(field => this.intl.t(`app_components.license_picker.fields.${field}`));
const missingFields = missingFieldsList.join(', ');
if (missingFieldsList.length) {
return this.createErrorMessage('node_license_missing_fields',
value, { missingFields, numOfFields: missingFieldsList.length });
}

return true;
Expand Down
8 changes: 4 additions & 4 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const {
OSF_COOKIE_DOMAIN: cookieDomain = 'localhost',
OSF_URL: url = 'http://localhost:5000/',
OSF_API_URL: apiUrl = 'http://localhost:8000',
OSF_API_VERSION: apiVersion = '2.19',
OSF_API_VERSION: apiVersion = '2.20',
OSF_RENDER_URL: renderUrl = 'http://localhost:7778/render',
OSF_FILE_URL: waterbutlerUrl = 'http://localhost:7777/',
OSF_HELP_URL: helpUrl = 'http://localhost:4200/help',
Expand Down Expand Up @@ -262,9 +262,9 @@ module.exports = function(environment) {
'registries.start': 'ember_registries_submission_start',
'registries.drafts': 'ember_registries_submission_drafts',
'registries.drafts.index': 'ember_registries_submission_drafts',
'registries.drafts.draft.metadata': 'ember_registries_submission_metadata',
'registries.drafts.draft.form': 'ember_registries_submission_drafts',
'registries.drafts.draft.review': 'ember_registries_submission_drafts',
'registries.drafts.draft.metadata': 'ember_edit_draft_registration_page',
'registries.drafts.draft.page': 'ember_edit_draft_registration_page',
'registries.drafts.draft.review': 'ember_edit_draft_registration_page',
'registries.forms': 'ember_registries_submission_forms',
'registries.forms.help': 'ember_registries_submission_forms',
'meetings.index': 'ember_meetings_page',
Expand Down
2 changes: 1 addition & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = function(defaults) {
importBootstrapCSS: false,
},
'ember-composable-helpers': {
only: ['compose', 'contains', 'flatten', 'range', 'queue'],
only: ['compose', 'contains', 'flatten', 'range', 'queue', 'map-by'],
},
'ember-cli-password-strength': {
bundleZxcvbn: !IS_PROD,
Expand Down
Loading

0 comments on commit 742f12a

Please sign in to comment.