Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BI-2152 - Experimental Collaborator Front-end Permissions #396

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/components/layouts/UserSideBarLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,50 @@
<!-- <li>
<a>Germplasm Inventory</a>
</li>-->
<li>
<li
v-if="$ability.can('access', 'Germplasm')"
>
<router-link
v-bind:to="{name: 'germplasm', params: {programId: activeProgram.id}}"
:id="germplasmMenuId"
v-if="$ability.can('access', 'Germplasm')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a v-if on this router-link but not the others? You might consider standardizing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

>
Germplasm
</router-link>
</li>
<li>
<li
v-if="$ability.can('access', 'Experiment')"
>
<router-link
v-bind:to="{name: 'experiments-observations', params: {programId: activeProgram.id}}"
>
Experiments & Observations
</router-link>
</li>
<li>
<li
v-if="$ability.can('access', 'Ontology')"
>
<router-link
v-bind:to="{name: 'ontology', params: {programId: activeProgram.id}}"
:id="ontologyMenuId"

>
Ontology
</router-link>
</li>
<li>
<li
v-if="$ability.can('create', 'Import')"
>
<router-link
v-bind:to="{name: 'import'}"
:id="importFileMenuId"
v-if="$ability.can('create', 'Import')"
>
Import Data
</router-link>
</li>
<li>
<li
v-if="$ability.can('access', 'SampleManagement')"
>
<router-link
v-bind:to="{name: 'sample-management', params: {programId: activeProgram.id}}"
:id="sampleMgmtMenuId"
Expand All @@ -138,20 +149,26 @@
<a>Reports</a>
</li>
-->
<li>
<li
v-if="$ability.can('access', 'ProgramAdministration')"
>
<router-link
v-bind:to="{name: 'program-administration', params: {programId: activeProgram.id}}"
:id="programManagementMenuId"
>
Program Administration
</router-link>
</li>
<li>
<li
v-if="$ability.can('access', 'BrAPI')"
>
<router-link v-bind:to="{name: 'brapi-info', params: {programId: activeProgram.id}}" :id="brAPIMenuId">
BrAPI
</router-link>
</li>
<li>
<li
v-if="$ability.can('access', 'JobManagement')"
>
<router-link
v-bind:to="{name: 'job-management', params: {programId: activeProgram.id}}"
:id="jobManagementMenuId"
Expand Down
3 changes: 2 additions & 1 deletion src/config/AppAbility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import {Ability, AbilityClass} from '@casl/ability';

type Actions = 'manage' | 'create' | 'read' | 'update' | 'delete' | 'archive' | 'access' | 'submit';
type Subjects = 'ProgramUser' | 'Location' | 'User' | 'AdminSection' | 'Trait' | 'Import' | 'ProgramConfiguration' | 'Submission';
type Subjects = 'ProgramUser' | 'Location' | 'User' | 'AdminSection' | 'Trait' | 'Import' | 'ProgramConfiguration' | 'Submission'
| 'Experiment' | 'Germplasm' | 'Ontology' | 'SampleManagement' | 'ProgramAdministration' | 'JobManagement' | 'Collaborator' | 'BrAPI' ;

export type AppAbility = Ability<[Actions, Subjects]>;
export const AppAbility = Ability as AbilityClass<AppAbility>;
33 changes: 32 additions & 1 deletion src/config/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ type DefinePermissions = (user: User, builder: AbilityBuilder<AppAbility>) => vo

const rolePermissions: Record<string, DefinePermissions> = {
readonly(user, { can }) {
can('access', 'Experiment');
can('access', 'Ontology');
can('access', 'Germplasm');
can('access', 'ProgramAdministration');
can('access', 'SampleManagement');
can('access', 'BrAPI');
can('access', 'JobManagement');
},
experimentalcollaborator(user, { can }) {
can('access', 'Experiment');
can('access', 'BrAPI');
},
programadministrator(user, { can }) {
can('create', 'ProgramUser');
Expand All @@ -40,14 +51,35 @@ const rolePermissions: Record<string, DefinePermissions> = {
can('access', 'ProgramConfiguration');
can('create', 'ProgramConfiguration');
can('update', 'ProgramConfiguration');
can('access', 'Experiment');
can('access', 'Ontology');
can('access', 'Germplasm');
can('access', 'SampleManagement');
can('access', 'ProgramAdministration');
can('access', 'BrAPI');
can('access', 'JobManagement');
can('create', 'Collaborator');

},
systemadministrator(user, { can }) {
can('create', 'ProgramUser');
can('update', 'ProgramUser');
can('archive', 'ProgramUser');
can('create', 'Location');
can('update', 'Location');
can('archive', 'Location');
can('manage', 'User');
can('access', 'AdminSection');
can('submit', 'Submission');
can('access', 'Experiment');
can('access', 'Ontology');
can('access', 'Germplasm');
can('access', 'SampleManagement');
can('access', 'ProgramAdministration');
can('access', 'BrAPI');
can('access', 'JobManagement');
can('create', 'Collaborator');

}
};

Expand Down Expand Up @@ -81,7 +113,6 @@ export function defineAbilityFor(user: User | undefined, program: Program | unde
programRole.program.id === program.id && programRole.domain &&
programRole.active &&
typeof rolePermissions[roleFunctionName] === 'function') {

rolePermissions[roleFunctionName](user, builder);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default class ExperimentDetails extends ProgramsBase {
private actions: ActionMenuItem[] = [
new ActionMenuItem('experiment-import-file', 'import-file', 'Import file', this.$ability.can('create', 'Import')),
new ActionMenuItem('experiment-download-file', 'download-file', 'Download file'),
new ActionMenuItem('experiment-add-collaborator', 'add-collaborator', 'Add Collaborator'),
new ActionMenuItem('experiment-add-collaborator', 'add-collaborator', 'Add Collaborator', this.$ability.can('create', 'Collaborator')),
// new ActionMenuItem('experiment-create-sub-entity-dataset', 'create-sub-entity-dataset', 'Create Sub-Entity Dataset')
];

Expand Down
Loading