Skip to content
Snippets Groups Projects
Commit 74b1f73d authored by Othmane ROGLER's avatar Othmane ROGLER Committed by Francois AUBEUT
Browse files

feat(structures): make structures data shape multi level

* New migration to add parentId, ancestorsIds, childrenIds
* Update data structure of structure to reflect changes
* Little update to structure Factory function
* Add a helper function to check admin right on a structure (direct admin or ancestor admin)
* Update publications (structures, services), methods (structures, users, services) to reflect new rights logics
* Update test to reflect new rights logics
* Add one test for new getAllChilds method
* Add missing translations (i18n)
parent 65bc64b5
No related branches found
No related tags found
1 merge request!52274-add-introduction-for-a-structure
import { Roles } from 'meteor/alanning:roles';
import Structures from '../structures';
export const hasAdminRightOnStructure = ({ userId, structureId }) => {
const ids = [structureId];
const structure = Structures.findOne({ _id: structureId }, { fields: { ancestorsIds: 1 } });
if (structure && structure.ancestorsIds.length > 0) structure.ancestorsIds.forEach((ancestor) => ids.push(ancestor));
const isAdmin = ids.some((id) => Roles.userIsInRole(userId, 'adminStructure', id));
return isAdmin;
};
export const isAStructureWithSameNameExistWithSameParent = ({ name, parentId }) => {
const regExp = new RegExp(name, 'i');
const structuresWithSameNameOnSameLevel = Structures.find({ name: { $regex: regExp }, parentId });
return structuresWithSameNameOnSameLevel.count() > 0;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment