Skip to content
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
37 changes: 36 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
## [14.12.3](https://github.com/makeomatic/ms-users/compare/v14.12.2...v14.12.3) (2020-11-23)
## [14.12.3-rc.5](https://github.com/makeomatic/ms-users/compare/v14.12.3-rc.4...v14.12.3-rc.5) (2020-11-23)


### Bug Fixes

* remove invite after accept ([287f7b3](https://github.com/makeomatic/ms-users/commit/287f7b3b55877b40c6a3f9e130658c8eb240b1c8))

## [14.12.3-rc.4](https://github.com/makeomatic/ms-users/compare/v14.12.3-rc.3...v14.12.3-rc.4) (2020-11-20)


### Bug Fixes

* allow any types for user permission ([be0d9dc](https://github.com/makeomatic/ms-users/commit/be0d9dc24f3a0c644945c9a0a02b04de7fe03dc1))

## [14.12.3-rc.3](https://github.com/makeomatic/ms-users/compare/v14.12.3-rc.2...v14.12.3-rc.3) (2020-11-18)


### Bug Fixes

* edit emal types in validate config ([43896ba](https://github.com/makeomatic/ms-users/commit/43896ba2ba856568e2e77479e9c8e0af3b4899c2))
* fix test config ([0db5127](https://github.com/makeomatic/ms-users/commit/0db5127bc650ab0f47732ac793ab7e86ab6f2a45))
* omit required email types in validation config ([f2b16de](https://github.com/makeomatic/ms-users/commit/f2b16dee5bf9c096a1e92c9f7de75f023a38578a))

## [14.12.3-rc.2](https://github.com/makeomatic/ms-users/compare/v14.12.3-rc.1...v14.12.3-rc.2) (2020-11-18)


### Bug Fixes

* added new props form email config in validation scheme ([6625eb6](https://github.com/makeomatic/ms-users/commit/6625eb6bad53243037044a96a013b162375041fe))

## [14.12.3-rc.1](https://github.com/makeomatic/ms-users/compare/v14.12.2...v14.12.3-rc.1) (2020-11-16)

### Bug Fixes

* edited actions for the organization members and invites ([#481](https://github.com/makeomatic/ms-users/issues/481)) ([a3f2627](https://github.com/makeomatic/ms-users/commit/a3f26273633a67a2d04c79b8b027427b5bbb12c8))
*
## [14.12.3](https://github.com/makeomatic/ms-users/compare/v14.12.2...v14.12.3) (2020-11-23)

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ms-users",
"description": "Core of the microservice for handling users",
"main": "./lib/index.js",
"version": "14.12.3",
"version": "14.12.3-rc.5",
"scripts": {
"compile": "rimraf ./lib; babel -d ./lib --copy-files ./src",
"pretest": "yarn compile",
Expand Down
86 changes: 27 additions & 59 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,71 +180,16 @@
],
"properties": {
"paths": {
"type": "object",
"required": [
"activate",
"reset"
],
"properties": {
"activate": {
"type": "string"
},
"reset": {
"type": "string"
}
}
"$ref": "#/definitions/emailTypes"
},
"senders": {
"required": [
"activate",
"reset",
"password"
],
"type": "object",
"properties": {
"activate": {
"type": "string"
},
"reset": {
"type": "string"
},
"password": {
"type": "string"
}
}
"$ref": "#/definitions/emailTypes"
},
"subjects": {
"required": [
"activate",
"reset",
"password"
],
"type": "object",
"properties": {
"activate": {
"type": "string"
},
"reset": {
"type": "string"
},
"password": {
"type": "string"
}
}
"$ref": "#/definitions/emailTypes"
},
"templates": {
"type": "object",
"properties": {
"activate": {
"type": "string"
},
"reset": {
"type": "string"
},
"password": {
"type": "string"
}
}
"$ref": "#/definitions/emailTypes"
},
"email": {
"oneOf": [{
Expand Down Expand Up @@ -799,6 +744,29 @@
}
}
}
},
"emailTypes": {
"type": "object",
"properties": {
"activate": {
"type": "string"
},
"reset": {
"type": "string"
},
"password": {
"type": "string"
},
"organizationUserInvite": {
"type": "string"
},
"organizationUserRegister": {
"type": "string"
},
"organizationUserAdd": {
"type": "string"
}
}
}
}
}
16 changes: 15 additions & 1 deletion schemas/organization.invites.send.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@
"permissions",
"email"
],
"$ref": "common.json#/definitions/organizationMember"
"type": "object",
"properties": {
"email": {
"type": "string"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"permissions": {
"type": "array"
}
}
}
}
}
15 changes: 15 additions & 0 deletions schemas/organization.members.get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "object",
"required": [
"organizationId",
"username"
],
"properties": {
"organizationId": {
"type": "string"
},
"username": {
"type": "string"
}
}
}
8 changes: 0 additions & 8 deletions schemas/organization.members.permission.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@
"properties": {
"$set": {
"type": "array",
"items": {
"type": "string",
"minLength": 1
},
"minItems": 1
},
"$remove": {
"type": "array",
"items": {
"type": "string",
"minLength": 1
},
"minItems": 1
}
}
Expand Down
19 changes: 19 additions & 0 deletions schemas/organization.members.update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "object",
"required": [
"organizationId",
"username",
"data"
],
"properties": {
"organizationId": {
"type": "string"
},
"username": {
"type": "string"
},
"data": {
"$ref": "common.json#/definitions/metadata"
}
}
}
8 changes: 7 additions & 1 deletion src/actions/organization/invites/accept.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
ErrorInvitationExpiredOrUsed,
TOKEN_METADATA_FIELD_METADATA,
inviteId,
organizationInvite,
} = require('../../../constants');
const addOrganizationMembers = require('../../../utils/organization/add-organization-members');

Expand Down Expand Up @@ -44,11 +45,16 @@ async function acceptOrganizationMember({ params }) {
member.permissions = memberInviteMetadata.permissions;
member.password = password;

return addOrganizationMembers.call(this, {
const response = await addOrganizationMembers.call(this, {
organizationId,
audience,
members: [member],
});

await this.tokenManager.remove({ id: inviteId(organizationId, member.email), action: USERS_ACTION_ORGANIZATION_INVITE });
await this.redis.srem(organizationInvite(organizationId), member.email);

return response;
}

acceptOrganizationMember.allowed = checkOrganizationExists;
Expand Down
9 changes: 5 additions & 4 deletions src/actions/organization/invites/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const Promise = require('bluebird');
const { checkOrganizationExists } = require('../../../utils/organization');
const { organizationInvite, inviteId, USERS_ACTION_ORGANIZATION_INVITE, TOKEN_METADATA_FIELD_METADATA } = require('../../../constants');

const mapUser = ({ id, created, metadata }) => {
const mapUser = ({ id, created, metadata } = {}) => {
if (!id || id === '') return false;
const [, userId] = id.split(':');

return {
Expand All @@ -17,7 +18,7 @@ function getTokenInfo(email) {
return this.tokenManager.info({
id: inviteId(this.organizationId, email),
action: USERS_ACTION_ORGANIZATION_INVITE,
});
}).catch((e) => this.log.error('resolve token info error: %o', e));
}

/**
Expand All @@ -33,11 +34,11 @@ function getTokenInfo(email) {
async function listOrganizationInvite({ params }) {
const { organizationId } = params;
const invitesIds = await this.redis.smembers(organizationInvite(organizationId));
const getInvitesInfo = invitesIds.map(getTokenInfo, { tokenManager: this.tokenManager, organizationId });
const getInvitesInfo = invitesIds.map(getTokenInfo, { log: this.log, tokenManager: this.tokenManager, organizationId });
const invites = await Promise.all(getInvitesInfo);

return {
data: invites.map(mapUser),
data: invites.map(mapUser).filter((f) => f),
};
}

Expand Down
13 changes: 12 additions & 1 deletion src/actions/organization/invites/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const { checkOrganizationExists } = require('../../../utils/organization');
const {
ORGANIZATIONS_NAME_FIELD,
ORGANIZATIONS_ID_FIELD,
USERS_ACTION_ORGANIZATION_INVITE,
} = require('../../../constants');
const getUserId = require('../../../utils/userData/get-user-id');

/**
* @api {amqp} <prefix>.invites.send Send invitation
Expand All @@ -26,18 +28,27 @@ const {
async function sendOrganizationInvite({ params }) {
const { member, organizationId } = params;
const organization = await getInternalData.call(this, organizationId);
let userExist = false;

try {
await getUserId.call(this, member.email);
userExist = true;
} catch (e) {
this.log.info('invited user not exist');
}

return sendInviteMail.call(this, {
email: member.email,
ctx: {
skipPassword: userExist,
firstName: member.firstName,
lastName: member.lastName,
permissions: member.permissions,
email: member.email,
organizationId: organization[ORGANIZATIONS_ID_FIELD],
organization: organization[ORGANIZATIONS_NAME_FIELD],
},
});
}, USERS_ACTION_ORGANIZATION_INVITE);
}

sendOrganizationInvite.allowed = checkOrganizationExists;
Expand Down
47 changes: 47 additions & 0 deletions src/actions/organization/members/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { ActionTransport } = require('@microfleet/core');
const redisKey = require('../../../utils/key');
const getUserId = require('../../../utils/userData/get-user-id');
const { getMemberData } = require('../../../utils/organization/get-organization-members');
const { checkOrganizationExists } = require('../../../utils/organization');
const {
ORGANIZATIONS_MEMBERS,
USERS_METADATA,
ErrorUserNotMember,
} = require('../../../constants');

/**
* @api {amqp} <prefix>.members.Get Get organization member
* @apiVersion 1.0.0
* @apiName members.get
* @apiGroup Organizations
*
* @apiDescription This should be used to get member.
*
* @apiParam (Payload) {String} organizationId - organization id.
* @apiParam (Payload) {String} username - member email.
*/
async function getMember({ params }) {
const { redis, config } = this;
const { organizationId, username } = params;
const { audience } = config.organizations;

const userId = await getUserId.call(this, username);
const memberKey = redisKey(organizationId, ORGANIZATIONS_MEMBERS, userId);
const memberMetadataKey = redisKey(userId, USERS_METADATA, audience);
const userInOrganization = await redis.hget(memberMetadataKey, organizationId);
if (!userInOrganization) {
throw ErrorUserNotMember;
}

const member = await getMemberData.call(this, memberKey);

return {
data: {
attributes: member,
},
};
}

getMember.allowed = checkOrganizationExists;
getMember.transports = [ActionTransport.amqp, ActionTransport.internal];
module.exports = getMember;
Loading