Skip to content
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

First federation steps #80

Merged
merged 14 commits into from
Oct 10, 2021
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
1 change: 1 addition & 0 deletions config/lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ module.exports.initHelmetHeaders = function (app) {
'fcm.googleapis.com',
'www.facebook.com',
'https://sentry.io',
`http://192.168.0.134/`,
],

// Allows control over Flash and other plugins.
Expand Down
7 changes: 5 additions & 2 deletions modules/offers/client/api/offers.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export async function getOffer(offerId) {
* @param {int} offerId - id of offer
* @returns Promise<Offer[]> - array of the found offers with limited info, mainly offer id and type.
*/
export async function queryOffers(query = {}) {
const { data } = await axios.get(`/api/offers?${new URLSearchParams(query)}`);
export async function queryOffers(query = {}, baseUrl = ``) {
const { data } = await axios.get(
`/api/offers?${new URLSearchParams(query)}`,
{ baseURL: baseUrl },
);
return data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ exports.delete = function (req, res) {
* List of Offers
*/
exports.list = function (req, res) {
if (!req.user) {
/* if (!req.user) {
return res.status(403).send({
message: errorService.getErrorMessageByKey('forbidden'),
});
}
} */

// Validate required bounding box query parameters
const coordinateKeys = [
Expand Down Expand Up @@ -608,7 +608,7 @@ exports.list = function (req, res) {
}
}

// Filter out users that do not share any circles with the authenticated user
/* // Filter out users that do not share any circles with the authenticated user
// and chose to not appear in those searches.
const showOnlyInMyCirclesQueries = [{ showOnlyInMyCircles: false }];
req.user.member?.forEach(function (membership) {
Expand All @@ -622,7 +622,7 @@ exports.list = function (req, res) {
$match: {
$or: showOnlyInMyCirclesQueries,
},
});
}); */

// Pick fields and convert to GeoJson Feature
query.push({
Expand Down
6 changes: 3 additions & 3 deletions modules/offers/server/policies/offers.server.policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ exports.invokeRolesPolicies = function () {
*/
exports.isAllowed = function (req, res, next) {
// No offers for non-authenticated nor for authenticated but un-published users
if (!req.user || (req.user && !req.user.public)) {
/* if (!req.user || (req.user && !req.user.public)) {
return res.status(403).send({
message: errorService.getErrorMessageByKey('forbidden'),
});
}
} */

// If an offer is being processed and the current user owns it, then allow any manipulation
if (req.offer && req.user && req.offer.user === req.user._id) {
return next();
}

// Check for user roles
const roles = req.user && req.user.roles ? req.user.roles : ['guest'];
const roles = ['user'];
acl.areAnyRolesAllowed(
roles,
req.route.path,
Expand Down
2 changes: 2 additions & 0 deletions modules/offers/server/routes/offers.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
*/
const offersPolicy = require('../policies/offers.server.policy');
const offers = require('../controllers/offers.server.controller');
const cors = require('cors');

module.exports = function (app) {
app.use(cors()); // this is not the place for this but it somehow works here, this adds cors headers
app
.route('/api/offers-by/:offerUserId')
.all(offersPolicy.isAllowed)
Expand Down
25 changes: 22 additions & 3 deletions modules/search/client/components/SearchMap.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,19 @@ export default function SearchMap({
}

const layerId = features[0]?.layer?.id;
// add also federated-host-maybe and no
const isFederated = features[0]?.properties?.offer === 'federated-host-yes';

switch (layerId) {
// Hosting or meeting offer
case unclusteredPointLayer.id:
if (features[0]?.id) {
setSelectedState(features[0]);
openOfferById(features[0].id);
if (!isFederated) {
openOfferById(features[0].id);
} else {
window.open('https://openhospitality.network'); // get this from elsewhere
}
}
break;
// Clusters
Expand Down Expand Up @@ -357,16 +363,29 @@ export default function SearchMap({

try {
// @TODO: cancellation when need to re-fetch
const dataFederated = await queryOffers(
{
filters,
...boundingBox,
},
`http://192.168.0.134/`,
);
const data = await queryOffers({
filters,
...boundingBox,
});
dataFederated.features.map(obj => {
const rObj = obj;
rObj.properties.offer = 'federated-host-yes';
return rObj;
});
data.features = data.features.concat(dataFederated.features);
setOffers(data);
} catch {
} catch (err) {
// @TODO Error handling
process.env.NODE_ENV === 'development' &&
// eslint-disable-next-line no-console
console.error('Could not load offers.');
console.error(err);
}
}

Expand Down
8 changes: 6 additions & 2 deletions modules/search/client/components/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ export const unclusteredPointLayer = {

// Host yes
'host-yes',
'#58ba58',
'#3E6B71',

// Host no
'host-maybe',
'#f2ae43',
'#ECEFF1',

// federated-host-yes
'federated-host-yes',
'#B0BEC5',

// Other:
'#ccc',
Expand Down