Skip to content

Commit

Permalink
[feature] Add new field platformTarget (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle authored Jan 28, 2025
1 parent 7d26b08 commit b648ca7
Show file tree
Hide file tree
Showing 20 changed files with 389 additions and 8 deletions.
11 changes: 9 additions & 2 deletions app/client/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,22 @@ table {
}

#openshift-env-list {
width: 395px;
width: 335px;
height: 38px;
margin-top: 5px !important;
margin-right: 5px;
}

#theme-list {
margin-top: 5px !important;
width: 395px;
margin-right: 5px;
width: 225px;
height: 38px;
}

#platform-target-list {
margin-top: 5px !important;
width: 225px;
height: 38px;
}

Expand Down
18 changes: 18 additions & 0 deletions app/imports/api/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ export const themesSchema = new SimpleSchema({

themesSchema.messageBox = messageBox;

export const platformTargetsSchema = new SimpleSchema({
name: {
type: String,
label: "Nom de la plateforme cible",
custom: isRequired,
}
}, { check });

platformTargetsSchema.messageBox = messageBox;

export const professorSchema = new SimpleSchema({
// _id use to update a tag
_id: {
Expand Down Expand Up @@ -225,6 +235,7 @@ Sites.tagged_search = function (text="", tags=[]) {
const OpenshiftEnvs = new Mongo.Collection('openshiftenvs');
const Categories = new Mongo.Collection('categories');
const Themes = new Mongo.Collection('themes');
const PlatformTargets = new Mongo.Collection('platformtargets');
const Tags = new Mongo.Collection('tags');
const Professors = new Mongo.Collection('professors');
const AppLogs = new Mongo.Collection('AppLogs');
Expand All @@ -247,6 +258,12 @@ Themes.deny({
remove() { return true; },
});

PlatformTargets.deny({
insert() { return true; },
update() { return true; },
remove() { return true; },
});

Tags.deny({
insert() { return true; },
update() { return true; },
Expand Down Expand Up @@ -275,6 +292,7 @@ export {
OpenshiftEnvs,
Categories,
Themes,
PlatformTargets,
Tags,
Professors,
AppLogs
Expand Down
59 changes: 59 additions & 0 deletions app/imports/api/methods/platform-target.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import SimpleSchema from "simpl-schema";
import { throwMeteorError } from "../error";
import { PlatformTargets, platformTargetsSchema } from "../collections";
import { AppLogger } from "../logger";
import { rateLimiter } from "./rate-limiting";
import { VeritasValidatedMethod, Admin } from "./role";

const checkUniquePlatformTargetName = async (platformTarget) => {
if (await PlatformTargets.find({ name: platformTarget.name }).countAsync() > 0) {
throwMeteorError("name", "Nom de la plateforme cible existe déjà !");
}
};

const insertPlatformTarget = new VeritasValidatedMethod({
name: "insertPlatformTarget",
role: Admin,
async validate(newPlatformTarget) {
await checkUniquePlatformTargetName(newPlatformTarget);
platformTargetsSchema.validate(newPlatformTarget);
},
async run(newPlatformTarget) {
let platformTargetDocument = {
name: newPlatformTarget.name,
};

let newPlatformTargetId = await PlatformTargets.insertAsync(platformTargetDocument);
let newPlatformTargetAfterInsert = await PlatformTargets.findOneAsync({ _id: newPlatformTargetId });

AppLogger.getLog().info(
`Insert platformTarget ID ${newPlatformTargetId}`,
{ before: "", after: newPlatformTargetAfterInsert },
this.userId
);

return newPlatformTargetAfterInsert;
},
});

const removePlatformTarget = new VeritasValidatedMethod({
name: "removePlatformTarget",
role: Admin,
validate: new SimpleSchema({
platformTargetId: { type: String },
}).validator(),
async run({ platformTargetId }) {
let platformTarget = await PlatformTargets.findOneAsync({ _id: platformTargetId });
await PlatformTargets.removeAsync({ _id: platformTargetId });

AppLogger.getLog().info(
`Delete platformTarget ID ${platformTargetId}`,
{ before: platformTarget, after: "" },
this.userId
);
},
});

rateLimiter([insertPlatformTarget, removePlatformTarget]);

export { insertPlatformTarget, removePlatformTarget };
2 changes: 2 additions & 0 deletions app/imports/api/methods/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ const insertSite = new VeritasValidatedMethod({
openshiftEnv: newSite.openshiftEnv,
categories: newSite.categories,
theme: newSite.theme,
platformTarget: newSite.platformTarget,
languages: newSite.languages,
unitId: newSite.unitId,
unitName: unitName,
Expand Down Expand Up @@ -278,6 +279,7 @@ const updateSite = new VeritasValidatedMethod({
openshiftEnv: newSite.openshiftEnv,
categories: newSite.categories,
theme: newSite.theme,
platformTarget: newSite.platformTarget,
languages: newSite.languages,
unitId: newSite.unitId,
unitName: unitName,
Expand Down
1 change: 1 addition & 0 deletions app/imports/api/methods/tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function createSite(userId, categories, tags, professors) {
openshiftEnv: "www",
categories: categories,
theme: "wp-theme-2018",
platformTarget: "openshift-4",
languages: ["en", "fr"],
unitId: "13030",
unitName: "ISAS-FSD",
Expand Down
48 changes: 48 additions & 0 deletions app/imports/api/methods/tests/platform-target.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import assert from "assert";
import { PlatformTargets } from "../../collections";
import { insertPlatformTarget, removePlatformTarget } from "../platform-target";
import { createUser } from "../../../../tests/helpers";
import { loadFixtures } from "../../../../server/fixtures";
import { resetDatabase } from "../../../../server/fixtures-test";

if (Meteor.isServer) {
describe("meteor methods platformTarget", function () {
before(async function () {
await resetDatabase();
await loadFixtures();
});

it("insert platformTarget", async () => {
let userId = await createUser();

const context = { userId };
const args = {
name: "openshift-4"
};

await insertPlatformTarget._execute(context, args);

let nb = await PlatformTargets.find({}).countAsync();
let platformTarget = await PlatformTargets.findOneAsync({ name: "openshift-4" });

assert.strictEqual(nb, 1);
assert.strictEqual(platformTarget.name, "openshift-4");
});

it("remove platformTarget", async () => {
let userId = await createUser();
let platformTarget = await PlatformTargets.findOneAsync({ name: "openshift-4" });

const context = { userId };
const args = { platformTargetId: platformTarget._id };

let nbBefore = await PlatformTargets.find({}).countAsync();
assert.strictEqual(nbBefore, 1);

await removePlatformTarget._execute(context, args);

let nbAfter = await PlatformTargets.find({}).countAsync();
assert.strictEqual(nbAfter, 0);
});
});
}
2 changes: 2 additions & 0 deletions app/imports/api/methods/tests/sites.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ if (Meteor.isServer) {
openshiftEnv: "www",
categories: await Categories.find({ name: "Restauration" }).fetchAsync(),
theme: "wp-theme-2018",
platformTarget: "openshift-4",
languages: ["en", "fr"],
unitId: "13030",
unitName: "ISAS-FSD",
Expand Down Expand Up @@ -103,6 +104,7 @@ if (Meteor.isServer) {
openshiftEnv: "www",
categories: await Categories.find({ name: "Restauration" }).fetchAsync(),
theme: "wp-theme-2018",
platformTarget: "openshift-4",
languages: ["en", "fr"],
unitId: "13030",
unitName: "ISAS-FSD",
Expand Down
6 changes: 6 additions & 0 deletions app/imports/api/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Sites,
OpenshiftEnvs,
Themes,
PlatformTargets,
Tags,
Categories,
AppLogs,
Expand Down Expand Up @@ -34,6 +35,11 @@ if (Meteor.isServer) {
return [themeCursor];
});

Meteor.publish("platformTarget.list", function () {
let platformTargetCursor = PlatformTargets.find({}, { sort: { name: 1 } });
return [platformTargetCursor];
});

Meteor.publish("category.list", function () {
let categoryCursor = Categories.find({}, { sort: { name: 1 } });
return [categoryCursor];
Expand Down
7 changes: 7 additions & 0 deletions app/imports/api/schemas/sitesSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export const sitesSchema = new SimpleSchema({
max: 100,
min: 3,
},
platformTarget: {
type: String,
label: "Plateforme cible",
optional: false,
max: 100,
min: 3,
},
languages: {
type: Array,
label: "Langues",
Expand Down
5 changes: 5 additions & 0 deletions app/imports/api/schemas/sitesWPInfraOutsideSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export const sitesWPInfraOutsideSchema = new SimpleSchema({
label: "Thème",
optional: true,
},
platformTarget: {
type: String,
label: "Plateforme cible",
optional: true,
},
languages: {
type: Array,
label: "Langues",
Expand Down
Loading

0 comments on commit b648ca7

Please sign in to comment.