Skip to content

Commit 5d62cd8

Browse files
committed
Removed tenant
1 parent ae2a20a commit 5d62cd8

File tree

13 files changed

+23
-58
lines changed

13 files changed

+23
-58
lines changed

database.rules.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
"rules": {
33
"users": {
44
"$user": {
5-
".write": "auth !== null && auth.token.email_verified === true && data.child('tenant').val() === auth.token.tenant && ((auth.token.isAdmin === true && data.child('isAdmin').val() === false) || auth.uid === $user)",
6-
".read": "auth !== null && auth.token.email_verified === true && data.child('tenant').val() === auth.token.tenant && ((auth.token.isAdmin === true && data.child('isAdmin').val() === false) || auth.uid === $user)"
5+
".write": "auth !== null && auth.token.email_verified === true && ((auth.token.isAdmin === true && data.child('isAdmin').val() === false) || auth.uid === $user)",
6+
".read": "auth !== null && auth.token.email_verified === true && ((auth.token.isAdmin === true && data.child('isAdmin').val() === false) || auth.uid === $user)"
77
},
8-
".read": "auth !== null && auth.token.email_verified === true && auth.token.isAdmin === true && query.orderByChild === 'tenant' && query.equalTo === auth.token.tenant",
9-
".indexOn": ["tenant"]
8+
".read": "auth !== null && auth.token.email_verified === true && auth.token.isAdmin === true"
109
}
1110
}
1211
}

functions/requests/routes/users.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ const uploadImageToBucket = async uploadedImage => {
2424
});
2525
};
2626

27-
const createUserAuth = async (email, password, tenant, isAdmin) => {
27+
const createUserAuth = async (email, password, isAdmin) => {
2828
const { uid } = await admin.auth().createUser({ email, password });
2929

3030
await admin.auth().setCustomUserClaims(uid, {
31-
isAdmin,
32-
tenant
31+
isAdmin
3332
});
3433

3534
return uid;
@@ -39,7 +38,6 @@ const createUserOnDb = async (
3938
name,
4039
email,
4140
location,
42-
tenant,
4341
logoUrl,
4442
userId,
4543
createdAt,
@@ -49,7 +47,6 @@ const createUserOnDb = async (
4947
name,
5048
email,
5149
location,
52-
tenant,
5350
logoUrl,
5451
createdAt,
5552
isAdmin
@@ -84,15 +81,15 @@ router.post('/', (request, response) => {
8481
});
8582

8683
busboy.on('finish', async () => {
87-
const { name, email, password, location, tenant, createdAt } = fieldData;
84+
const { name, email, password, location, createdAt } = fieldData;
8885

8986
const isAdmin = JSON.parse(fieldData.isAdmin);
9087

9188
let id;
9289

9390
try {
9491
console.log('Creating user in auth and setting custom claims');
95-
id = await createUserAuth(email, password, tenant, isAdmin);
92+
id = await createUserAuth(email, password, isAdmin);
9693
console.log('Created user auth and setting custom claims');
9794
} catch (error) {
9895
console.error(
@@ -122,7 +119,6 @@ router.post('/', (request, response) => {
122119
name,
123120
email,
124121
location,
125-
tenant,
126122
logoUrl,
127123
id,
128124
createdAt,
@@ -139,7 +135,6 @@ router.post('/', (request, response) => {
139135
name,
140136
location,
141137
email,
142-
tenant,
143138
logoUrl,
144139
isAdmin
145140
});
@@ -178,10 +173,9 @@ router.delete('/:id', async (request, response) => {
178173
return response.status(200).json({});
179174
});
180175

181-
const modifyUserAuth = (userId, isAdmin, tenant) => {
176+
const modifyUserAuth = (userId, isAdmin) => {
182177
return admin.auth().setCustomUserClaims(userId, {
183-
isAdmin,
184-
tenant
178+
isAdmin
185179
});
186180
};
187181

@@ -235,13 +229,13 @@ router.patch('/:id', (request, response) => {
235229
});
236230

237231
busboy.on('finish', async () => {
238-
const { name, location, createdAt, tenant } = fieldData;
232+
const { name, location, createdAt } = fieldData;
239233

240234
const isAdmin = JSON.parse(fieldData.isAdmin);
241235

242236
const { id } = request.params;
243237

244-
const setUserClaims = modifyUserAuth(id, isAdmin, tenant);
238+
const setUserClaims = modifyUserAuth(id, isAdmin);
245239

246240
let removeLogo = Promise.resolve();
247241
let uploadImage = Promise.resolve();
@@ -279,7 +273,6 @@ router.patch('/:id', (request, response) => {
279273
id,
280274
name,
281275
location,
282-
tenant,
283276
logoUrl,
284277
isAdmin,
285278
createdAt

functions/setupProject.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ rl.question('Enter the path to the service account key file: ', path => {
2727
emailVerified: true
2828
});
2929

30-
const tenant = uuid();
31-
3230
await admin.auth().setCustomUserClaims(uid, {
33-
isAdmin: true,
34-
tenant
31+
isAdmin: true
3532
});
3633

3734
console.log('Created admin account in authentication');
@@ -43,7 +40,6 @@ rl.question('Enter the path to the service account key file: ', path => {
4340
.ref(`users/${uid}`)
4441
.set({
4542
isAdmin: true,
46-
tenant,
4743
name: 'Test Name',
4844
location: 'Test Location',
4945
createdAt: new Date().toDateString(),

src/components/UserForm/UserForm.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ describe('<UserForm /> rendering', () => {
1616
file: null,
1717
id: 'test id',
1818
logoUrl: 'some logoUrl',
19-
tenant: 'some tenantId',
2019
createdAt: new Date().toDateString()
2120
};
2221
});
@@ -114,7 +113,6 @@ describe('<LoginForm /> actions', () => {
114113
location: 'Montevideo, Uruguay',
115114
id: 'test id',
116115
logoUrl: 'some logoUrl',
117-
tenant: 'some tenantId',
118116
isAdmin: false,
119117
file: null,
120118
createdAt: new Date().toDateString()

src/components/UserForm/__snapshots__/UserForm.test.js.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ exports[`<UserForm /> rendering should render without crashing 1`] = `
132132
"location": "Montevideo, Uruguay",
133133
"logoUrl": "some logoUrl",
134134
"name": "Mateo",
135-
"tenant": "some tenantId",
136135
}
137136
}
138137
/>

src/components/UserForm/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ UserForm.propTypes = {
404404
name: PropTypes.string.isRequired,
405405
location: PropTypes.string.isRequired,
406406
logoUrl: PropTypes.string,
407-
tenant: PropTypes.string,
408407
createdAt: PropTypes.string.isRequired
409408
}),
410409
action: PropTypes.func.isRequired

src/pages/Users/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ const Users = () => {
158158
? usersList.filter(el => {
159159
const clonedElem = { ...el };
160160
delete clonedElem.id;
161-
delete clonedElem.tenant;
162161
delete clonedElem.isAdmin;
163162
delete clonedElem.logoUrl;
164163
return Object.values(clonedElem).some(field =>

src/state/actions/auth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ export const fetchUserData = () => {
122122

123123
export const checkUserData = () => {
124124
return (dispatch, getState) => {
125-
const { tenant } = getState().auth.userData;
125+
const { id } = getState().auth.userData;
126126

127-
if (!tenant) {
127+
if (!id) {
128128
dispatch(fetchUserData());
129129
}
130130
};

src/state/actions/users.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@ export const fetchUsers = () => {
4141

4242
dispatch(USERS_FETCH_DATA_INIT());
4343

44-
const { tenant, id } = getState().auth.userData;
44+
const { id } = getState().auth.userData;
4545

4646
let users;
4747

4848
try {
49-
const ref = firebase.database().ref('users');
50-
5149
users = (
52-
await ref
53-
.orderByChild('tenant')
54-
.equalTo(tenant)
50+
await firebase
51+
.database()
52+
.ref('users')
5553
.once('value')
5654
).val();
5755
} catch (error) {
@@ -108,11 +106,9 @@ export const createUser = ({
108106
createdAt,
109107
isAdmin
110108
}) => {
111-
return async (dispatch, getState) => {
109+
return async dispatch => {
112110
dispatch(USERS_CREATE_USER_INIT());
113111

114-
const { tenant } = getState().auth.userData;
115-
116112
const user = firebase.auth().currentUser;
117113

118114
const userToken = await user.getIdToken();
@@ -131,7 +127,6 @@ export const createUser = ({
131127
body.append('location', location);
132128
body.append('email', email);
133129
body.append('password', uuid());
134-
body.append('tenant', tenant);
135130
body.append('createdAt', createdAt);
136131
body.append('isAdmin', isAdmin);
137132

@@ -188,11 +183,9 @@ export const modifyUser = ({
188183
isEditing,
189184
isProfile
190185
}) => {
191-
return async (dispatch, getState) => {
186+
return async dispatch => {
192187
dispatch(USERS_MODIFY_USER_INIT());
193188

194-
const { tenant } = getState().auth.userData;
195-
196189
const user = firebase.auth().currentUser;
197190

198191
const userToken = await user.getIdToken();
@@ -209,7 +202,6 @@ export const modifyUser = ({
209202

210203
body.append('name', name);
211204
body.append('location', location);
212-
body.append('tenant', tenant);
213205
body.append('createdAt', createdAt);
214206
body.append('isAdmin', isAdmin);
215207

src/state/reducers/auth/auth.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ describe('Auth reducer', () => {
2828
const initialState = {
2929
userData: {
3030
id: null,
31-
isAdmin: null,
32-
tenant: null
31+
isAdmin: null
3332
},
3433
loading: false,
3534
error: null,
@@ -80,8 +79,7 @@ describe('Auth reducer', () => {
8079
it('should set the state with the corresponding payload, loading to false and error to null when AUTH_FETCH_USER_DATA_SUCCESS actions is fired', () => {
8180
const payload = {
8281
id: 'some user id',
83-
isAdmin: false,
84-
tenant: 'some sompanyId'
82+
isAdmin: false
8583
};
8684

8785
reducerTest(initialState, AUTH_FETCH_USER_DATA_SUCCESS(payload), {
@@ -206,7 +204,6 @@ describe('Auth reducer', () => {
206204
isAdmin: false,
207205
name: 'some name',
208206
location: 'some location',
209-
tenant: 'some tenantId',
210207
createdAt: '11/20/2020'
211208
};
212209
reducerTest(initialState, AUTH_UPDATE_USER_DATA({ ...userData }), {

src/state/reducers/auth/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import {
2727
const initialState = {
2828
userData: {
2929
id: null,
30-
isAdmin: null,
31-
tenant: null
30+
isAdmin: null
3231
},
3332
loading: false,
3433
error: null,
@@ -62,7 +61,6 @@ export const authReducer = createReducer(
6261
name: payload.name,
6362
location: payload.location,
6463
logoUrl: payload.logoUrl,
65-
tenant: payload.tenant,
6664
createdAt: payload.createdAt
6765
},
6866
loading: false,
@@ -140,7 +138,6 @@ export const authReducer = createReducer(
140138
name: payload.name,
141139
location: payload.location,
142140
logoUrl: payload.logoUrl || state.userData.logoUrl,
143-
tenant: payload.tenant,
144141
createdAt: payload.createdAt
145142
}
146143
})

src/state/reducers/users/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export const usersReducer = createReducer(
8989
name: payload.user.name,
9090
location: payload.user.location,
9191
id: payload.id,
92-
tenant: payload.user.tenant,
9392
logoUrl: payload.user.logoUrl,
9493
createdAt: payload.user.createdAt,
9594
email: elem.email

src/state/reducers/users/users.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ describe('Establishments reducer', () => {
138138
location: 'test location',
139139
email: 'test email',
140140
id: 'test id',
141-
tenant: 'test tenant',
142141
logoUrl: 'some logo'
143142
}
144143
];
@@ -149,7 +148,6 @@ describe('Establishments reducer', () => {
149148
location: 'test location',
150149
email: 'test email',
151150
id: 'test id',
152-
tenant: 'test tenant',
153151
logoUrl: 'some logo'
154152
}
155153
];
@@ -161,7 +159,6 @@ describe('Establishments reducer', () => {
161159
name: 'test name 2',
162160
location: 'test location',
163161
email: 'test email',
164-
tenant: 'test tenant',
165162
logoUrl: 'some logo'
166163
},
167164
id: 'test id'

0 commit comments

Comments
 (0)