diff --git a/firestore.rules b/firestore.rules index 24b3ab06b..4f9097868 100644 --- a/firestore.rules +++ b/firestore.rules @@ -69,7 +69,9 @@ service cloud.firestore { return userIsTeamMember; } - // Is a member from the parent of the Objective/KeyResult/Period/KPI + /** + * Return true if the current user is a member of `document.parent`. + */ function isMemberOfParent(document, type) { let userRef = /databases/$(database)/documents/users/$(request.auth.token.email); let doc = getAfter(/databases/$(database)/documents/$(type)/$(document)); @@ -149,9 +151,6 @@ service cloud.firestore { match /periods/{document} { allow read: if isSignedIn(); - allow create: if isSuperAdmin() || isMemberOfParent(document, 'periods') || isAdminOfParent(document, 'periods'); - allow update: if isSuperAdmin() || isMemberOfParent(document, 'periods') || isAdminOfParent(document, 'periods'); - allow delete: if isSuperAdmin(); } match /kpis/{document} { diff --git a/src/db/Period/Period.js b/src/db/Period/Period.js deleted file mode 100644 index 2cfd7fa27..000000000 --- a/src/db/Period/Period.js +++ /dev/null @@ -1,40 +0,0 @@ -import { db } from '@/config/firebaseConfig'; -import props from './props'; -import { - validateCreateProps, - validateUpdateProps, - createDocument, - updateDocument, -} from '../common'; -import Objective from '../Objective'; - -const collection = db.collection('periods'); - -const create = (data) => { - if (!validateCreateProps(props, data)) { - throw new Error('Invalid data'); - } - data.progression = 0; - return createDocument(collection, data); -}; - -const update = (id, data) => { - validateUpdateProps(props, data); - return updateDocument(collection.doc(id), data); -}; - -const archive = (id) => { - db.collection('objectives') - .where('period', '==', collection.doc(id)) - .get() - .then(({ docs }) => - docs.forEach(({ ref }) => { - Objective.archive(ref.id); - }) - ); - - update(id, { archived: true }); -}; -const restore = (id) => update(id, { archived: false }); - -export default { create, update, archive, restore }; diff --git a/src/db/Period/index.js b/src/db/Period/index.js deleted file mode 100644 index 5860d8d17..000000000 --- a/src/db/Period/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import Period from './Period'; - -export default Period; diff --git a/src/db/Period/props.js b/src/db/Period/props.js deleted file mode 100644 index 360ee0d11..000000000 --- a/src/db/Period/props.js +++ /dev/null @@ -1,18 +0,0 @@ -export default { - name: { - type: 'string', - required: true, - }, - parent: { - type: 'reference', - required: true, - }, - startDate: { - type: 'date', - required: true, - }, - endDate: { - type: 'date', - required: true, - }, -};