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

Develop #405

Merged
merged 80 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
daf7fbf
Add documentation on how to deploy to heroku in readme.md
medamineziraoui Apr 26, 2021
d27e3ad
Change node version in the development.md documentation file to 14.16
medamineziraoui Apr 26, 2021
50c1730
Merge branch 'develop' of github.com:Badsender-com/LePatron.email int…
medamineziraoui May 24, 2021
107652a
Fix Documentation how to deploy
medamineziraoui May 24, 2021
d0f7ca2
Delete useless editor readme
medamineziraoui May 24, 2021
f00a0c9
Add clever documentation
medamineziraoui Jun 4, 2021
5c90eb7
Update Deployment documentation
medamineziraoui Jun 7, 2021
fc76560
Init Schema conception
medamineziraoui Jun 10, 2021
a67ee6a
Integrate profile solution
medamineziraoui Jun 10, 2021
4d3d76f
Design Request: feat-add-profile-front
medamineziraoui Jun 11, 2021
78aa0bd
Remove design request
medamineziraoui Jun 11, 2021
ccfb51b
Merge pull request #384 from Badsender-com/feat-add-profile-backend-s…
DecampsRenan Jun 11, 2021
545329e
fix: remove infomaniak
DecampsRenan Jun 11, 2021
14e3360
fix: deployement doc url
DecampsRenan Jun 11, 2021
1bffd5a
Merge pull request #353 from Badsender-com/how-deploy-documentation
DecampsRenan Jun 11, 2021
cf2a068
chore: add license file
DecampsRenan Jun 11, 2021
bdc15d9
rework readme file
DecampsRenan Jun 11, 2021
c6a6ed3
chore: remove unused README
DecampsRenan Jun 11, 2021
358c46a
Merge pull request #386 from Badsender-com/chore/license-file
DecampsRenan Jun 11, 2021
b858c47
fix: removed unused fields
DecampsRenan Jun 11, 2021
b9c36c1
Merge pull request #387 from Badsender-com/chore/license-file
DecampsRenan Jun 11, 2021
1706ee8
chore: move templates files and remove uneeded files
DecampsRenan Jun 11, 2021
3464c09
chore: update README
DecampsRenan Jun 11, 2021
91fafdc
chore: readme description
DecampsRenan Jun 11, 2021
94d4153
fix: tools links
DecampsRenan Jun 11, 2021
55b9440
Complete conception for adding profile to group admin space
medamineziraoui Jun 14, 2021
e917621
Implement profile space in group admin
medamineziraoui Jun 14, 2021
0b6845a
Merge branch 'develop' into feat-add-profile-space-front
omar-bear Jun 16, 2021
6f44610
feat: init listing profils
omar-bear Jun 16, 2021
6634da9
feat: init listing profils
omar-bear Jun 16, 2021
827716f
Revert "feat: init listing profils"
omar-bear Jun 16, 2021
4ae94aa
Merge pull request #385 from Badsender-com/feat-add-profile-space-front
medamineziraoui Jun 16, 2021
1bc22f1
feat: init delete profile
omar-bear Jun 16, 2021
6449e35
Merge remote-tracking branch 'origin' into feat/listing-profiles
omar-bear Jun 16, 2021
4dabd6a
feat: fix sendinblue name
omar-bear Jun 16, 2021
f01e5df
Merge branch 'feat/listing-profiles' into feat/delete-profile
omar-bear Jun 17, 2021
4f50ed9
feat: add handleDelete function
omar-bear Jun 17, 2021
7a4d273
feat: init create profile form
omar-bear Jun 17, 2021
0fecf70
Refactor download function + fix api call for sendinblue
medamineziraoui Jun 18, 2021
70ea579
Add get HTML final result methode without archive
medamineziraoui Jun 19, 2021
f1270b9
Merge pull request #390 from Badsender-com/feat/listing-profiles
medamineziraoui Jun 19, 2021
63d220f
Merge pull request #391 from Badsender-com/feat/delete-profile
medamineziraoui Jun 19, 2021
aedbf40
Merge develop into feat-adding-listing-profile
medamineziraoui Jun 19, 2021
e3a0543
Api listing profile + connect api to frontend
medamineziraoui Jun 19, 2021
b9cd522
Merge develop into feat-connect-api-sendingblue
medamineziraoui Jun 20, 2021
e88fe9f
Add api for deleting a profile
medamineziraoui Jun 20, 2021
d1e5987
Resolve discussions
medamineziraoui Jun 20, 2021
d355da7
Merge pull request #393 from Badsender-com/feat-connect-api-sendingblue
medamineziraoui Jun 20, 2021
381f834
Merge develop into feat-adding-listing-profile
medamineziraoui Jun 20, 2021
1b77687
Merge pull request #394 from Badsender-com/feat-adding-listing-profile
medamineziraoui Jun 20, 2021
f1c58b1
Merge develop into feat-delete-profile-api
medamineziraoui Jun 20, 2021
5a7f848
Add await to delete profile service
medamineziraoui Jun 20, 2021
6ca5731
Merge pull request #395 from Badsender-com/feat-delete-profile-api
medamineziraoui Jun 20, 2021
e8d0271
Fix listing profile group
medamineziraoui Jun 20, 2021
b9ba64c
Merge pull request #396 from Badsender-com/fix-listing-profile-group
medamineziraoui Jun 20, 2021
f2c2fc6
Merge develop into feat/create-profile
medamineziraoui Jun 20, 2021
a076e90
Add profile feature
medamineziraoui Jun 21, 2021
474897d
fix: remove private var env
DecampsRenan Jun 25, 2021
bed641d
Merge pull request #398 from Badsender-com/feat/extract-env-vars
DecampsRenan Jun 25, 2021
3e237a6
Add front esp in editor
medamineziraoui Jun 25, 2021
7f3a977
Merge pull request #397 from Badsender-com/feat-create-profile-front
medamineziraoui Jun 28, 2021
1dde80e
feat-display-listing-profile-editor
medamineziraoui Jun 28, 2021
6bd8c65
Add success notification message + re-add editor loggers
medamineziraoui Jun 28, 2021
22350cd
Merge pull request #399 from Badsender-com/feat-display-listing-profi…
medamineziraoui Jun 28, 2021
666cab2
Add edit profile for superadmin
medamineziraoui Jun 28, 2021
aff868a
Add error message for readProfileForAdmin endpoint
medamineziraoui Jun 28, 2021
c6d9ad7
Merge pull request #400 from Badsender-com/feat-edit-profile
medamineziraoui Jun 28, 2021
98aca14
Add edit Mail api to ESP + Add alert and error codes
medamineziraoui Jun 29, 2021
39c76f1
Fix bugs front badsender
medamineziraoui Jun 29, 2021
2e8b94e
Remove useless console.log
medamineziraoui Jun 29, 2021
3371010
Resolve discussions
medamineziraoui Jun 29, 2021
a04d52b
Resolve discussions
medamineziraoui Jun 29, 2021
5a075e4
Add error logger
medamineziraoui Jun 29, 2021
e7cbbfe
Merge pull request #401 from Badsender-com/feat-edit-esp-mail-editor
medamineziraoui Jun 29, 2021
b359abe
Add error consoles
medamineziraoui Jun 29, 2021
fc68fd8
Merge pull request #402 from Badsender-com/feat-edit-esp-mail-editor
medamineziraoui Jun 29, 2021
6913bf0
Update gulpfile
medamineziraoui Jun 29, 2021
a21e478
Merge pull request #403 from Badsender-com/feat-edit-esp-mail-editor
medamineziraoui Jun 29, 2021
b4759d5
re-add proxy
medamineziraoui Jun 29, 2021
958fa87
Merge pull request #404 from Badsender-com/feat-edit-esp-mail-editor
medamineziraoui Jun 29, 2021
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
Prev Previous commit
Next Next commit
Add edit profile for superadmin
  • Loading branch information
medamineziraoui committed Jun 28, 2021
commit 666cab246f7d723ad651c28b14938eae9216a88d
70 changes: 67 additions & 3 deletions packages/server/profile/profile.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ const asyncHandler = require('express-async-handler');
const profileService = require('./profile.service');
const mailingService = require('../mailing/mailing.service');
const groupService = require('../group/group.service');
const { NotFound } = require('http-errors');

module.exports = {
create: asyncHandler(create),
createProfile: asyncHandler(createProfile),
updateProfile: asyncHandler(updateProfile),
sendCampaignMail: asyncHandler(sendCampaignMail),
deleteProfile: asyncHandler(deleteProfile),
profileListEditor: asyncHandler(profileListEditor),
getCampaignMail: asyncHandler(getCampaignMail),
readProfile: asyncHandler(readProfile),
readProfileForAdmin: asyncHandler(readProfileForAdmin),
};

/**
Expand All @@ -27,11 +30,11 @@ module.exports = {
* @apiUse profile
*/

async function create(req, res) {
async function createProfile(req, res) {
const { user } = req;
const { name, type, apiKey, _company, ...additionalApiData } = req.body;

const response = await profileService.create({
const response = await profileService.createProfile({
user,
name,
type,
Expand All @@ -43,6 +46,39 @@ async function create(req, res) {
res.json(response);
}

/**
* @api {post} /profiles/:profileId profile edition
* @apiPermission admin
* @apiName UpdateProfile
* @apiGroup Profiles
*
* @apiParam (Body) {String} name profile name.
* @apiParam (Body) {String} type Profile type
* @apiParam (Body) {String} apiKey the provider key
* @apiParam (Body) {String} _company the ID of the group
* @apiParam (Body) {String} data the data to be used with the adequat ESP provider
*
* @apiUse profile
* @apiSuccess {profile} profile updated
*/

async function updateProfile(req, res) {
const { user } = req;
const { name, type, apiKey, _company, id, ...additionalApiData } = req.body;

const response = await profileService.updateProfile({
user,
id,
name,
type,
apiKey,
_company,
additionalApiData,
});

res.json(response);
}

/**
* @api {post} /profiles/send-campaign-mail send campaign mail to ESP
* @apiPermission admin
Expand Down Expand Up @@ -166,3 +202,31 @@ async function readProfile(req, res) {

res.send({ result: getProfileResult });
}

/**
* @api {get} /profiles/:profileId/admin Get profile detail for admin
* @apiPermission admin
* @apiName ProfileCampaign
* @apiGroup Profiles
*
* @apiParam {string} profileId
*
*/
async function readProfileForAdmin(req, res) {
const { user, params } = req;
const { profileId } = params;

if (!user.isAdmin) {
throw new NotFound();
}
await profileService.checkIfUserIsAuthorizedToAccessProfile({
user,
profileId,
});

console.log({ profileId });

const getProfileResult = await profileService.findOne(profileId);

res.send({ result: getProfileResult });
}
4 changes: 3 additions & 1 deletion packages/server/profile/profile.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ const profiles = require('./profile.controller.js');

const { GUARD_USER, GUARD_ADMIN } = require('../account/auth.guard.js');

router.post('/', GUARD_ADMIN, profiles.create);
router.post('/', GUARD_ADMIN, profiles.createProfile);
router.post('/:profileId', GUARD_ADMIN, profiles.updateProfile);
router.post(
'/:mailingId/send-campaign-mail',
GUARD_USER,
profiles.sendCampaignMail
);
router.delete('/:profileId', GUARD_ADMIN, profiles.deleteProfile);
router.get('/:profileId', GUARD_USER, profiles.readProfile);
router.get('/:profileId/admin', GUARD_ADMIN, profiles.readProfileForAdmin);
router.get(
'/:groupId/profile-list-for-editor',
GUARD_USER,
Expand Down
46 changes: 44 additions & 2 deletions packages/server/profile/profile.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const mailingService = require('../mailing/mailing.service.js');
const groupService = require('../group/group.service.js');

module.exports = {
create,
createProfile,
updateProfile,
sendCampaignMail,
findAllByGroup,
deleteProfile,
Expand All @@ -35,7 +36,13 @@ async function checkIfUserIsAuthorizedToAccessProfile({ user, profileId }) {
}
}

async function create({ name, type, apiKey, _company, additionalApiData }) {
async function createProfile({
name,
type,
apiKey,
_company,
additionalApiData,
}) {
const espProvider = new EspProvider({
apiKey,
type,
Expand All @@ -59,6 +66,41 @@ async function create({ name, type, apiKey, _company, additionalApiData }) {
});
}

async function updateProfile({
id,
name,
type,
apiKey,
_company,
additionalApiData,
}) {
await findOne(id);

const espProvider = new EspProvider({
apiKey,
type,
name,
_company,
additionalApiData,
});

const espConnectionResult = await espProvider.connectApi();
if (!espConnectionResult) {
throw new NotFound(ERROR_CODES.PROFILE_NOT_FOUND);
}

return Profiles.updateOne(
{ _id: Types.ObjectId(id) },
{
name,
type,
apiKey,
_company,
additionalApiData,
}
);
}

async function sendCampaignMail({
user,
espSendingMailData,
Expand Down
3 changes: 1 addition & 2 deletions packages/server/workspace/workspace.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const express = require('express');
const { guard, GUARD_GROUP_ADMIN } = require('../account/auth.guard');

const router = express.Router();
const Roles = require('../account/roles.js');

const workspacesController = require('./workspace.controller.js');

Expand All @@ -18,7 +17,7 @@ router.post('/', GUARD_GROUP_ADMIN, workspacesController.createWorkspace);

router.put(
'/:workspaceId',
guard([Roles.SUPER_ADMIN, Roles.GROUP_ADMIN]),
guard(GUARD_GROUP_ADMIN),
workspacesController.updateWorkspace
);

Expand Down
4 changes: 3 additions & 1 deletion packages/ui/components/group/profile-tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
BsProfilesTable,
},
data() {
return { profiles: [], loading: false };
return { profiles: [], loading: false, groupId: null };
},
async mounted() {
await this.fetchData();
Expand All @@ -22,6 +22,7 @@ export default {
$axios,
$route: { params },
} = this;
this.groupId = params.groupId;
this.loading = true;
const { items } = await $axios.$get(groupsProfiles(params));
this.profiles = items;
Expand Down Expand Up @@ -51,6 +52,7 @@ export default {
<v-card-text>
<bs-profiles-table
:profiles="profiles"
:group-id="groupId"
:loading="loading"
@delete="handleDelete"
/>
Expand Down
12 changes: 7 additions & 5 deletions packages/ui/components/profiles/esp/SENDINBLUEComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ export default {
props: {
disabled: { type: Boolean, default: false },
isLoading: { type: Boolean, default: false },
profileData: { type: Object, default: () => ({}) },
},
data() {
return {
submitStatus: null,
profile: {
name: '',
apiKey: '',
senderName: '',
senderMail: '',
replyTo: '',
id: this.profileData.id ?? '',
name: this.profileData.name ?? '',
apiKey: this.profileData.apiKey ?? '',
senderName: this.profileData.senderName ?? '',
senderMail: this.profileData.senderMail ?? '',
replyTo: this.profileData.replyTo ?? '',
type: 'SENDINBLUE',
},
};
Expand Down
48 changes: 10 additions & 38 deletions packages/ui/components/profiles/profile-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import { validationMixin } from 'vuelidate';
import SENDINBLUEComponent from '../../components/profiles/esp/SENDINBLUEComponent';
import ACTITOComponent from '../../components/profiles/esp/ACTITOComponent';
import { mapMutations } from 'vuex';
import { PAGE, SHOW_SNACKBAR } from '~/store/page';
import { groupsItem, getProfiles } from '~/helpers/api-routes';
import { groupsItem } from '~/helpers/api-routes';
import { ESP_TYPES } from '~/helpers/constants/esp-type';

export default {
Expand All @@ -16,6 +14,7 @@ export default {
mixins: [validationMixin],
props: {
title: { type: String, default: '' },
profile: { type: Object, default: () => ({}) },
},
data: () => {
return {
Expand All @@ -40,43 +39,12 @@ export default {
},
},
async mounted() {
if (this.profile.type) {
this.selectedEsp = this.profile.type;
}
await this.fetchGroup();
},
methods: {
...mapMutations(PAGE, { showSnackbar: SHOW_SNACKBAR }),
async createProfile(data) {
const { $axios, $route } = this;
const { groupId } = $route.params;
try {
console.log({ data });
this.loading = true;
await $axios.$post(getProfiles(), {
_company: groupId,
...data,
});
this.showSnackbar({
text: this.$t('snackbars.created'),
color: 'success',
});
this.$router.push(`/groups/${groupId}`);
} catch (error) {
switch (error?.response?.status) {
case 401:
this.showSnackbar({
text: this.$t('forms.profile.errors.apiKey.unauthorized'),
color: 'error',
});
break;
default:
this.showSnackbar({
text: this.$t('global.errors.errorOccured'),
color: 'error',
});
}
} finally {
this.loading = false;
}
},
handleEspChange(value) {
this.selectedEsp = value;
},
Expand All @@ -90,6 +58,9 @@ export default {
console.log(error);
}
},
handleSubmit(newProfile) {
this.$emit('submit', newProfile);
},
},
};
</script>
Expand Down Expand Up @@ -131,9 +102,10 @@ export default {
<client-only>
<component
:is="selectedEspName"
:profile-data="profile"
:disabled="!group.downloadMailingWithFtpImages"
:loading="loading"
@submit="createProfile($event)"
@submit="handleSubmit"
/>
</client-only>
</v-col>
Expand Down
8 changes: 6 additions & 2 deletions packages/ui/components/profiles/table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
props: {
profiles: { type: Array, default: () => [] },
loading: { type: Boolean, default: false },
groupId: { type: String, default: null },
},
data() {
return {
Expand Down Expand Up @@ -93,8 +94,11 @@ export default {
</template>
<template #item.actions="{ item }">
<profiles-actions-dropdown>
<profiles-actions-dropdown-item icon="edit" disabled>
{{ $t('profiles.edit') }}
<profiles-actions-dropdown-item
icon="delete"
:to="`/groups/${groupId}/profiles/${item.id}`"
>
{{ $t('global.edit') }}
</profiles-actions-dropdown-item>
<profiles-actions-dropdown-item
icon="delete"
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/helpers/api-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,7 @@ export function getProfiles() {
export function getProfileId(getProfileId) {
return `/profiles/${getProfileId}`;
}

export function getProfileForAdmin(getProfileId) {
return `/profiles/${getProfileId}/admin`;
}
1 change: 1 addition & 0 deletions packages/ui/helpers/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default {
mailing: 'Email | Emails',
newMailing: 'Add an email',
newProfile: 'Add an export profile',
editProfile: 'Edit export profile {name}',
profile: 'Profile | Profiles',
user: 'User | Users',
newUser: 'Add a user',
Expand Down
1 change: 1 addition & 0 deletions packages/ui/helpers/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default {
newUser: 'Ajouter un utilisateur',
newTeam: 'Ajouter un workspace',
newProfile: 'Ajouter un profil d\'exportation',
editProfile: 'Éditer le profil d\'exportation {name}',
profile: 'Profil | Profils',
newTag: 'Ajouter un tag',
backToMails: 'Retour aux emails',
Expand Down
Loading