diff --git a/firestore.rules b/firestore.rules index 24b3ab06b..87b4622a2 100644 --- a/firestore.rules +++ b/firestore.rules @@ -147,6 +147,13 @@ service cloud.firestore { allow delete: if isSuperAdmin(); } + /* + * TODO: Needs to be extended with rules for `create` and `delete`. + */ + match /objectiveContributors/{document} { + allow read: if isSignedIn(); + } + match /periods/{document} { allow read: if isSignedIn(); allow create: if isSuperAdmin() || isMemberOfParent(document, 'periods') || isAdminOfParent(document, 'periods'); diff --git a/src/store/actions/set_active_period_and_data.js b/src/store/actions/set_active_period_and_data.js index 529704370..3eef24055 100644 --- a/src/store/actions/set_active_period_and_data.js +++ b/src/store/actions/set_active_period_and_data.js @@ -7,6 +7,7 @@ export default firestoreAction( if (!periodId && !item) { unbindFirestoreRef('periods'); unbindFirestoreRef('objectives'); + unbindFirestoreRef('objectiveContributors'); unbindFirestoreRef('activePeriod'); return false; } @@ -28,14 +29,26 @@ export default firestoreAction( .where('parent', '==', parentRef) .orderBy('name'); + const objectiveContributorsRef = db + .collection('objectiveContributors') + .where('item', '==', parentRef); + const activeObjectivesList = await objectivesRef .get() .then((snapshot) => snapshot.docs.map((doc) => doc.ref)); - if (activeObjectivesList.length) { + const objectiveContributorsList = await objectiveContributorsRef + .get() + .then((snapshot) => snapshot.docs.map((doc) => doc.ref)); + + if (activeObjectivesList.length || objectiveContributorsList.length) { await bindFirestoreRef('objectives', objectivesRef, { maxRefDepth: 1 }); + await bindFirestoreRef('objectiveContributors', objectiveContributorsRef, { + maxRefDepth: 1, + }); } else { unbindFirestoreRef('objectives'); + unbindFirestoreRef('objectiveContributors'); } return true; diff --git a/src/store/index.js b/src/store/index.js index 5e550a7b7..bb2438bca 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -144,10 +144,13 @@ export const storeGetters = { }, /** - * Return `state.objectives` enriched with ID. + * Return `state.objectives` and external objectives from + * `state.objectiveContributors` enriched with ID. */ objectivesWithID: (state) => { - return state.objectives.map((o) => ({ + const externalObjectives = state.objectiveContributors.map((oc) => oc.objective); + + return state.objectives.concat(externalObjectives).map((o) => ({ ...o, id: o.id, })); @@ -294,6 +297,7 @@ export default new Vuex.Store({ activeObjective: null, periods: [], objectives: [], + objectiveContributors: [], kpis: [], subKpis: [], loginError: null,