Skip to content

Commit 631720d

Browse files
committed
enh: properly showing All Projects option on Resource edit, given user permissions
1 parent e34f563 commit 631720d

File tree

1 file changed

+64
-13
lines changed

1 file changed

+64
-13
lines changed

ui/src/resourceedit.vue

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,27 @@
6767
</b-col>
6868
<b-col cols="9">
6969
<v-select v-if="projects" :options="projects" v-model="resource.gids"
70-
:reduce="r=>r.group_id" label="name" multiple/>
70+
:reduce="r=>r.group_id" label="name" multiple>
71+
<template v-slot:option="project">
72+
<span :class="{
73+
'resource-projects-all__vs__dropdown-option': project.group_id == 1,
74+
'resource-projects-private__vs__dropdown-option': project.private,
75+
}">
76+
{{ project.name }}
77+
<span class="resource-projects-all_admin-message" v-if="config.hasRole('admin') && project.group_id == 1">
78+
(Brainlife Administrators Only)
79+
</span>
80+
</span>
81+
</template>
82+
<template v-slot:selected-option="project">
83+
<span :class="{
84+
'resource-projects-all__vs__selected': project.group_id == 1,
85+
'resource-projects-private__vs__selected': project.private,
86+
}">
87+
{{ project.name }}
88+
</span>
89+
</template>
90+
</v-select>
7191
<p>
7292
<small>Please select projects that you'd like enable this resource. Any jobs submitted by any member of specified project will be executed on this resource. You have to be listed as administrator of the project to be able to select it.</small>
7393
</p>
@@ -314,23 +334,37 @@ export default {
314334
}}).then(res=>{
315335
this.projects = res.data.projects;
316336
317-
//brainlife admin can add global user (but only site admin can *add* it)
318-
//if(this.config.hasRole('admin')) {
319-
this.projects.push({
320-
group_id: 1,
321-
name: "(Public Resource)",
322-
desc: "Share this resource with all brainlife users - only brainlife administrator can add this"
337+
this.projects.forEach(p => {
338+
p.private = false;
323339
});
324340
341+
if (
342+
// brainlife admin can add global user (but only site admin can *add* it)
343+
this.config.hasRole('admin') ||
344+
345+
// if you are editing a resource and it has already public permission
346+
(this.resource._id && this.resource.gids.includes(1))
347+
) {
348+
this.projects.push({
349+
group_id: 1,
350+
name: "All Projects",
351+
desc: "Share this resource with all Brainlife users - only Brainlife administrators can add this",
352+
private: false,
353+
});
354+
}
355+
325356
//add private groups that user doesn't have access to.. so the value won't disappear
326-
this.resource.gids.forEach(gid=>{
327-
const project = this.projects.find(p=>p.group_id == gid);
328-
if(!project) this.projects.push({
357+
this.resource.gids.forEach(gid => {
358+
const project = this.projects.find(p => p.group_id == gid);
359+
if (!project) {
360+
this.projects.push({
329361
group_id: gid,
330-
name: "(Private Project "+gid+")",
362+
name: "Private Project",
331363
desc: "You don't have access to this project by it was added by other administrator",
332-
});
333-
});
364+
private: true,
365+
});
366+
}
367+
});
334368
});
335369
},
336370
@@ -443,5 +477,22 @@ export default {
443477
small {
444478
opacity: 0.5;
445479
}
480+
.resource-projects-all_admin-message {
481+
color: #C00;
482+
}
483+
.resource-projects-all__vs__selected {
484+
color: #393;
485+
font-weight: bold;
486+
}
487+
.resource-projects-private__vs__selected {
488+
color: #999;
489+
}
490+
.resource-projects-all__vs__dropdown-option {
491+
color: #393;
492+
font-weight: bold;
493+
}
494+
.resource-projects-private__vs__dropdown-option {
495+
color: #999;
496+
}
446497
</style>
447498

0 commit comments

Comments
 (0)