Skip to content
Permalink
Browse files

Added abitlity to make VFS group checking non-strict (#85)

The `strictGroups: false` mountpoint attribute can now make it so group
matching is less strict. I.e. user can belong to *some* of the groups,
not *all* of them.
  • Loading branch information
andersevenrud committed Nov 21, 2019
1 parent b260f15 commit e91f6b23444e7b29c2227bfb674c7cb357aa3dc7
Showing with 14 additions and 4 deletions.
  1. +5 −0 __tests__/utils/vfs.js
  2. +5 −1 src/filesystem.js
  3. +4 −3 src/utils/vfs.js
@@ -266,10 +266,15 @@ describe('utils.vfs#filterMountByGroups', () => {
expect(vfs.filterMountByGroups([])(null)).toBe(true);
expect(vfs.filterMountByGroups(['a'])(['a'])).toBe(true);
expect(vfs.filterMountByGroups(['a', 'b'])(['a'])).toBe(true);

expect(vfs.filterMountByGroups(['a'])(['a'], false)).toBe(true);
expect(vfs.filterMountByGroups(['a', 'b'])(['a'], false)).toBe(true);
expect(vfs.filterMountByGroups(['a'])(['a', 'b'], false)).toBe(true);
});

test('Should be false', () => {
expect(vfs.filterMountByGroups([])(['a'])).toBe(false);
expect(vfs.filterMountByGroups(['a'])(['a', 'b'])).toBe(false);
expect(vfs.filterMountByGroups(['b'])(['a'], false)).toBe(false);
});
});
@@ -317,7 +317,11 @@ export default class Filesystem extends EventEmitter {
return this.mounts
.filter(m => all || m.mounted)
.filter(m => m.enabled !== false)
.filter(m => filterMountByGroups(user.groups)(m.attributes ? m.attributes.groups : []))
.filter(m => {
const mg = m.attributes ? m.attributes.groups : [];
const ms = m.attributes ? m.attributes.strictGroups !== false : true;
return filterMountByGroups(user.groups)(mg, ms);
})
.map(m => ({
attributes: Object.assign({}, m.attributes),
icon: icon(m.icon),
@@ -333,7 +333,8 @@ export const parseMontpointPrefix = str => {
* Filters a mountpoint by user groups
* @return {boolean}
*/
export const filterMountByGroups = userGroups => mountGroups => mountGroups instanceof Array
? mountGroups.every(g => userGroups.indexOf(g) !== -1)
: true;
export const filterMountByGroups = userGroups => (mountGroups, strict = true) =>
mountGroups instanceof Array
? mountGroups[strict ? 'every' : 'some'](g => userGroups.indexOf(g) !== -1)
: true;

0 comments on commit e91f6b2

Please sign in to comment.
You can’t perform that action at this time.