Skip to content

Fix for anonym user case and log out on Organization profile #3386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions apinf_packages/bookmarks/client/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Template.bookmark.events({
const apiId = (this.api) ? this.api._id : this._id;

// Store the user ID of the current user clicking the button
const currentUserId = Meteor.user()._id;
const currentUserId = Meteor.userId();

// Toggle (add/remove) the bookmark with method toogleBookmarkApi
Meteor.call('toggleBookmarkApi', apiId, currentUserId);
Expand All @@ -43,7 +43,7 @@ Template.bookmark.helpers({
// Make sure bookmark subscription is ready
if (instance.bookmarksSubscription.ready()) {
// Get current user bookmark (should be only one API Bookmarks result available)
userBookmark = ApiBookmarks.findOne({ userId: Meteor.user()._id, apiIds: apiId });
userBookmark = ApiBookmarks.findOne({ userId: Meteor.userId(), apiIds: apiId });
}
// Return true if user has an API bookmark
return !!(userBookmark);
Expand Down
4 changes: 2 additions & 2 deletions apinf_packages/organizations/client/add/autoform.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ AutoForm.hooks({
FlowRouter.go('organizations');
} else {
// Redirect to newly added organization
FlowRouter.go('organizationProfile', { slug });
FlowRouter.go('organizationProfile', { orgSlug: slug });
}
});
} else {
Expand All @@ -67,7 +67,7 @@ AutoForm.hooks({
const slug = instance.updateDoc.$set.slug;

// Redirect to newly added organization
FlowRouter.go('organizationProfile', { slug });
FlowRouter.go('organizationProfile', { orgSlug: slug });
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<template name="organizationCard">
<div class="panel organization-card">
<div class="panel-heading organization-card-heading text-center">
<a href="{{ pathFor 'organizationProfile' slug=organization.slug }}">
<a href="{{ pathFor 'organizationProfile' orgSlug=organization.slug }}">
<h3>
{{ organization.name }}
</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</td>
<td class="col-sm-9">
<h4 class="organization-catalog-table-title">
<a href="{{ pathFor 'organizationProfile' slug=organization.slug }}">
<a href="{{ pathFor 'organizationProfile' orgSlug=organization.slug }}">
{{ organization.name }}
</a>
</h4>
Expand Down
4 changes: 2 additions & 2 deletions apinf_packages/organizations/client/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ FlowRouter.route('/organizations', {
},
});

FlowRouter.route('/organizations/:slug/', {
FlowRouter.route('/organizations/:orgSlug/', {
name: 'organizationProfile',
action (params) {
// Get organization slug
const slug = params.slug;
const slug = params.orgSlug;

// Get Organization
Meteor.call('getOrganizationProfile', slug, (error, organizationProfile) => {
Expand Down
36 changes: 17 additions & 19 deletions apinf_packages/organizations/client/profile/apis/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Template.organizationApis.onCreated(function () {

if (organization) {
// Get pagination count for organization APIs
const perPage = parseInt(instance.data.organization.apisPerPage, 10);
const perPage = parseInt(organization.apisPerPage, 10);

// Set initial settings of pagination
instance.pagination = new Meteor.Pagination(Apis, {
Expand All @@ -41,25 +41,25 @@ Template.organizationApis.onCreated(function () {

// Watching on changes of managed APIs after connection to/disconnection from
instance.autorun(() => {
if (Template.currentData().organization) {
// reactive solution to update pagination with template instant data
const updatedApisPerPage = Template.currentData().organization.apisPerPage || 10;
// Get ids of managed APIs of organization
const apiIds = organization.managedApiIds();

// Get ids of managed APIs of organization
const apiIds = organization.managedApiIds();

// Get settings of current filter
const currentFilters = instance.pagination.filters();
// Get settings of current filter
const currentFilters = instance.pagination.filters();

// Filter by managed APIs
currentFilters._id = { $in: apiIds };
// Filter by managed APIs
currentFilters._id = { $in: apiIds };

// Set updated filter
instance.pagination.filters(currentFilters);
// Set updated filter
instance.pagination.filters(currentFilters);
});

// Set update perpage
instance.pagination.perPage(updatedApisPerPage);
}
instance.autorun(() => {
const updatedOrganization = Template.currentData().organization;
// reactive solution to update pagination with template instant data
const updatedApisPerPage = updatedOrganization.apisPerPage || 4;
// Set update perpage
instance.pagination.perPage(updatedApisPerPage);
});

// Watching for changes of lifecycle parameter
Expand Down Expand Up @@ -93,9 +93,7 @@ Template.organizationApis.onCreated(function () {
// Make sure sorting is set
if (sortByParameter) {
// Sort by name is ascending other cases are descending sort
const sortDirection = sortByParameter === 'name' ? 1 : -1;
// Set sorting
sort[sortByParameter] = sortDirection;
sort[sortByParameter] = sortByParameter === 'name' ? 1 : -1;
} else {
// Sort by name is default
sort.name = 1;
Expand Down
33 changes: 23 additions & 10 deletions apinf_packages/organizations/client/profile/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11 */

// Meteor packages imports
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';

// Meteor contributed packages imports
Expand All @@ -15,25 +16,37 @@ import Organizations from '/apinf_packages/organizations/collection/';
Template.organizationProfile.onCreated(function () {
// Get reference to template instance
const instance = this;
instance.organization = new ReactiveVar();

// Using to get updated subscription
instance.autorun(() => {
// Get the Organization slug from the route
const organizationSlug = FlowRouter.getParam('slug');
const organizationSlug = FlowRouter.getParam('orgSlug');

if (organizationSlug) {
// Subscribe to Organization document
instance.subscribe('organizationComposite', organizationSlug);
// Subscribe to OrganizationAPIs link documents
instance.subscribe('organizationApiLinksByOrganizationSlug', organizationSlug);
}
});

instance.autorun(() => {
// Get path parameter
const slug = FlowRouter.getParam('orgSlug');

// Subscribe to Organization document
instance.subscribe('organizationComposite', organizationSlug);
// Subscribe to OrganizationAPIs link documents
instance.subscribe('organizationApiLinksByOrganizationSlug', organizationSlug);
// Get related Organization
const organization = Organizations.findOne({ slug });

if (organization) {
// Store it
this.organization.set(organization);
}
});
});

Template.organizationProfile.helpers({
organization () {
// Get the Organization slug from the route
const slug = FlowRouter.getParam('slug');

// Get Organization, based on slug
return Organizations.findOne({ slug });
return Template.instance().organization.get();
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ AutoForm.hooks({
// Show success message to user
sAlert.success(message);
// Redirect to newly added organization
FlowRouter.go('organizationProfile', { slug });
FlowRouter.go('organizationProfile', { orgSlug: slug });
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Meteor.startup(() => {
// Set organization cover id to organization collection on success
OrganizationCover.resumable.on('fileSuccess', (file) => {
// Get slug
const slug = FlowRouter.getParam('slug');
const slug = FlowRouter.getParam('orgSlug');

// Get organization by slug
const organization = Organizations.findOne({ slug });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Meteor.startup(() => {
// Set organization logo id to organization collection on success
OrganizationLogo.resumable.on('fileSuccess', (file) => {
// Get slug
const slug = FlowRouter.getParam('slug');
const slug = FlowRouter.getParam('orgSlug');

// Get organization by slug
const organization = Organizations.findOne({ slug });
Expand Down
2 changes: 1 addition & 1 deletion apinf_packages/setup/client/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Roles } from 'meteor/alanning:roles';
const additionalSetupRequired = function () {
if (Meteor.user()) {
// Get user ID
const userId = Meteor.user()._id;
const userId = Meteor.userId();

const userIsAdmin = Roles.userIsInRole(userId, 'admin');

Expand Down