Skip to content

Commit

Permalink
Merge pull request #3441 from apinf/feature/0.55.0
Browse files Browse the repository at this point in the history
Feature/0.55.0
  • Loading branch information
matleppa authored Mar 23, 2018
2 parents ada20c7 + adc8b7f commit df11b5d
Show file tree
Hide file tree
Showing 70 changed files with 1,240 additions and 415 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
sudo: required
dist: trusty
group: deprecated-2017Q4
sudo: false

language: node_js
node_js:
Expand Down Expand Up @@ -30,8 +28,11 @@ services:
- docker

before_install:
- pwd
- ls -la
# Install meteor locally on CI
- if [ ! -e "$HOME/.meteor/meteor" ]; then cat $HOME/.travis_install_meteor | sed s/--progress-bar/-sL/g | /bin/sh; fi
- if [ ! -e "$HOME/.meteor/meteor" ]; then cat .travis_install_meteor | sed s/--progress-bar/-sL/g | /bin/sh; fi


before_script:
- yarn
Expand Down
2 changes: 1 addition & 1 deletion apinf_packages/about/client/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h3>
Apinf
</dt>
<dd>
0.54.0
0.55.0
</dd>
<dt>
API Umbrella
Expand Down
8 changes: 5 additions & 3 deletions apinf_packages/api_catalog/client/api_catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import 'locale-compare-polyfill';
// Npm packages imports
import _ from 'lodash';

// APInf imports
import localisedSorting from '/apinf_packages/core/helper_functions/string_utils';

Template.apiCatalog.onCreated(function () {
// Get reference to template instance
const instance = this;
Expand Down Expand Up @@ -213,15 +216,14 @@ Template.apiCatalog.helpers({
apis () {
// Get apis collection via Pagination
const apis = Template.instance().pagination.getPage();
// Get the language
const language = TAPi18n.getLanguage();

// Get the sort via Pagination
const sort = Template.instance().pagination.sort();
// When sorted by name
if (sort.name) {
// use custom sort function with i18n support
apis.sort((a, b) => {
return a.name.localeCompare(b.name, language) * sort.name;
return localisedSorting(a.name, b.name, sort.name);
});
}
return apis;
Expand Down
17 changes: 11 additions & 6 deletions apinf_packages/api_docs/client/manage/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,18 @@ Template.manageApiDocumentationModal.events({
Modal.hide('manageApiDocumentationModal');
},
'click #cancel-button': function (event, templateInstance) {
// Get fileId value
const fileId = Session.get('fileId');
const apiDocs = ApiDocs.findOne();

// If file is uploaded and a user clicks on "Cancel" button
if (fileId) {
// Remove uploaded file from collection
templateInstance.removeDocumentationFile(fileId);
// Make sure File isn't uploaded
if (!apiDocs || !apiDocs.fileId) {
// Get fileId value
const fileId = Session.get('fileId');

// If file is uploaded and a user clicks on "Cancel" button
if (fileId) {
// Remove uploaded file from collection
templateInstance.removeDocumentationFile(fileId);
}
}
},
'click #add-link': function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Template.swaggerUiContent.onRendered(function () {
const ui = SwaggerUIBundle({
url: api.documentationUrl(),
dom_id: '#swagger-ui',
defaultModelsExpandDepth: 0,
// Provides custom configs for Swagger
configs: this.configs,
presets: [
Expand Down
12 changes: 7 additions & 5 deletions apinf_packages/api_docs/client/view/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
{{_ "apiDocumentation_buttonText_closeEditor" }}
</button>
{{ else }}
<button
class="btn btn-xs btn-info editor">
<i class="fa fa-file-text-o"></i>&nbsp;
{{_ "apiDocumentation_buttonText_openEditor" }}
</button>
{{# if developmentFeatures }}
<button
class="btn btn-xs btn-info editor">
<i class="fa fa-file-text-o"></i>&nbsp;
{{_ "apiDocumentation_buttonText_openEditor" }}
</button>
{{/ if }}
{{/ if }}
<button
id="manage-api-documentation"
Expand Down
2 changes: 2 additions & 0 deletions apinf_packages/api_docs/client/view/documentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Template.apiDocumentation.onCreated(function () {

// Subscribe to code generator settings
instance.subscribe('singleSetting', 'sdkCodeGenerator');
// Subscribe to development Features settings
instance.subscribe('singleSetting', 'developmentFeatures');
});

Template.apiDocumentation.onRendered(() => {
Expand Down
41 changes: 41 additions & 0 deletions apinf_packages/apis/client/authorized_user/form/autoform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright 2017 Apinf Oy
This file is covered by the EUPL license.
You may obtain a copy of the licence at
https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11 */

// Meteor contributed packages imports
import { AutoForm } from 'meteor/aldeed:autoform';
import { TAPi18n } from 'meteor/tap:i18n';
import { sAlert } from 'meteor/juliancwirko:s-alert';

AutoForm.hooks({
authorizedUserForm: {
onSuccess () {
// Get success message translation
const message = TAPi18n.__('authorizedUserForm_success_message');

// Alert user of success
sAlert.success(message);
},
onError (formType, error) {
// Get error type string from error object
const errorType = error.error;

if (errorType === 'user-not-registered') {
// Get error message translation
const message = TAPi18n.__('authorizedUserForm_errorText_userNotRegistered');

// Display error
sAlert.error(message, { timeout: 'none' });
}

if (errorType === 'user-already-exist') {
// Get error message translation
const message = TAPi18n.__('authorizedUserForm_errorText_alreadyAuthorized');

// Display error
sAlert.error(message, { timeout: 'none' });
}
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ <h4>
{{# autoForm
schema=emailSchema
id="authorizedUserForm"
class="form-inline" }}
class="form-inline"
type="method"
meteormethod="addAuthorizedUser"
}}
<fieldset>
{{> afQuickField name='email' }}
{{> afQuickField name='apiId' value=apiId type="hidden" }}
<p>
{{_ "apiUserAuthorizationForm_helpText_usernameEmail" }}
</p>
{{> afQuickField name='user' }}
{{> afQuickField name='apiId' value=api._id type="hidden" }}
</fieldset>

<button type="submit" class="btn btn-primary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,7 @@ import { Template } from 'meteor/templating';
import emailSchema from './schema';

Template.apiUserAuthorizationForm.helpers({
apiId () {
// Get API ID
const apiId = Template.instance().data.api._id;

return apiId;
},
emailSchema () {
return emailSchema;
},
});

Template.apiUserAuthorizationForm.events({
'submit #authorizedUserForm': function (event) {
// Prevent form from reloading page
event.preventDefault();
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ const emailSchema = new SimpleSchema({
type: String,
regEx: SimpleSchema.RegEx.Id,
},
email: {
user: {
type: String,
regEx: SimpleSchema.RegEx.Email,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Template } from 'meteor/templating';
import { Modal } from 'meteor/peppelg:bootstrap-3-modal';

// Collection imports
import Apis from '/apinf_packages/apis/collection';
import Apis from '/apinf_packages/apis/collection/index';

Template.apiRemoveAuthorizedUser.events({
'click #confirm-remove': function (event, templateInstance) {
Expand Down
2 changes: 1 addition & 1 deletion apinf_packages/apis/client/profile/header/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1 id="api-header">
{{# if api.organization }}
<p class="view-api-meta-details">
<i class="fa fa-address-card" aria-hidden="true"></i>
<a href="{{ pathFor 'organizationProfile' slug=api.organization.slug }}">
<a href="{{ pathFor 'organizationProfile' orgSlug=api.organization.slug }}">
{{ api.organization.name }}
</a>
</p>
Expand Down
18 changes: 18 additions & 0 deletions apinf_packages/apis/client/profile/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import { Template } from 'meteor/templating';
// Collection imports
import Apis from '/apinf_packages/apis/collection';

Template.viewApiPageHeader.onRendered(() => {
// Get current url hash value
const hashTabValue = location.hash.substr(1);

// If url contain hash value
if (hashTabValue) {
// Show tab
$(`.nav-tabs a[href='#${hashTabValue}']`).tab('show');
}
});

Template.viewApiPageHeader.helpers({
userShouldSeeBacklogTab () {
// Get API id
Expand Down Expand Up @@ -40,3 +51,10 @@ Template.viewApiPageHeader.helpers({
return false;
},
});

Template.viewApiPageHeader.events({
'click #api-navigation-tabs li > a': (event) => {
// Show hash value in url
window.location = `${event.currentTarget.hash}`;
},
});
2 changes: 1 addition & 1 deletion apinf_packages/apis/client/profile/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div> <!-- /api-backend-details -->

<div id="api-documentation" class="tab-pane fade">
{{> apiDocumentation api=api apiDoc=apiDoc }}
{{> apiDocumentation api=api apiDoc=apiDoc developmentFeatures=developmentFeatures }}
</div> <!-- /api-documentation -->

<div id="api-metadata" class="tab-pane fade">
Expand Down
7 changes: 7 additions & 0 deletions apinf_packages/apis/client/profile/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Apis from '/apinf_packages/apis/collection';
import Branding from '/apinf_packages/branding/collection';
import Feedback from '/apinf_packages/feedback/collection';
import ProxyBackends from '/apinf_packages/proxy_backends/collection';
import Settings from '/apinf_packages/settings/collection';

Template.viewApi.onCreated(function () {
// Get reference to template instance
Expand Down Expand Up @@ -140,4 +141,10 @@ Template.viewApi.helpers({
}
return false;
},
developmentFeatures () {
// Get settings
const settings = Settings.findOne();

return settings.developmentFeatures;
},
});
34 changes: 29 additions & 5 deletions apinf_packages/apis/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,8 @@ CatalogV1.addCollection(Apis, {
const duplicateApi = Apis.findOne({ name: bodyParams.name });

if (duplicateApi) {
const detailLine = 'Duplicate: API with same name exists.';
const idValue = `${duplicateApi._id}`;
return errorMessagePayload(400, detailLine, 'id', idValue);
const detailLine = 'Duplicate: API with same name already exists.';
return errorMessagePayload(400, detailLine, 'id', duplicateApi._id);
}

// Description must not exceed field length in DB
Expand Down Expand Up @@ -467,8 +466,10 @@ CatalogV1.addCollection(Apis, {
}
}

// Add manager IDs list into
const apiData = Object.assign({ managerIds: [userId] }, bodyParams);
// Get formed slug
const slugData = Meteor.call('formSlugFromApiName', bodyParams.name);
// Add manager IDs list into and slug
const apiData = Object.assign({ managerIds: [userId] }, bodyParams, slugData);

// Insert API data into collection
const apiId = Apis.insert(apiData);
Expand Down Expand Up @@ -586,6 +587,16 @@ CatalogV1.addCollection(Apis, {
return errorMessagePayload(403, 'You do not have permission for editing this API.');
}

// If API name given, check if API with same name already exists
if (bodyParams.name) {
const duplicateApi = Apis.findOne({ name: bodyParams.name });

if (duplicateApi) {
const detailLine = 'Duplicate: API with same name already exists.';
return errorMessagePayload(400, detailLine, 'id', duplicateApi._id);
}
}

// validate values
const validateFields = {
description: bodyParams.description,
Expand Down Expand Up @@ -695,6 +706,19 @@ CatalogV1.addCollection(Apis, {
// Note! Meteor.userId is not available!
bodyParams.updated_by = userId;

// If API name given
if (bodyParams.name) {
// Get Formed slug
const slugData = Meteor.call('formSlugFromApiName', bodyParams.name);
// Check slugData
if (slugData) {
// Include slug
bodyParams.slug = slugData.slug;
// Include friendlySlugs
bodyParams.friendlySlugs = slugData.friendlySlugs;
}
}

// Update API document
const result = Apis.update(apiId, { $set: bodyParams });
// Check if API update failed
Expand Down
Loading

0 comments on commit df11b5d

Please sign in to comment.