Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion src/breeding-insight/model/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export class User {
roleId?: string;
roleName?: string;
programRoles?: ProgramUser[];
inactiveProgramRoles?: ProgramUser[];
programList?: string;

constructor(id?:string, name?: string, orcid?: string, email?: string, role?: Role, programRoles?: ProgramUser[]) {
constructor(id?:string, name?: string, orcid?: string, email?: string, role?: Role, programRoles?: ProgramUser[], inactiveProgramRoles?: ProgramUser[]) {
this.id = id;
this.name = name;
this.orcid = orcid;
Expand All @@ -38,6 +39,7 @@ export class User {
this.roleName = role.name;
}
this.programRoles = programRoles;
this.inactiveProgramRoles = inactiveProgramRoles;
this.programList = this.programRoles ? this.programRoles.map((x) => x.program ? x.program.name : '').join(", ") : "";
}

Expand Down
9 changes: 6 additions & 3 deletions src/breeding-insight/service/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ export class UserService {
let users = biResponse.result.data.map((user: any) => {
const role: Role | undefined = this.parseSystemRoles(user.systemRoles);
const programRoles: ProgramUser[] | undefined = this.parseProgramRoles(user.programRoles);
return new User(user.id, user.name, user.orcid, user.email, role, programRoles);
const inactiveProgramRoles: ProgramUser[] | undefined = this.parseProgramRoles(user.programRoles, false);
return new User(user.id, user.name, user.orcid, user.email, role, programRoles, inactiveProgramRoles);
});

resolve([users, biResponse.metadata]);
Expand Down Expand Up @@ -233,7 +234,7 @@ export class UserService {
return undefined;
}

private static parseProgramRoles(programRoleResponse: any[]): ProgramUser[] | undefined {
private static parseProgramRoles(programRoleResponse: any[], isActive=true): ProgramUser[] | undefined {

if (programRoleResponse && programRoleResponse.length > 0) {

Expand All @@ -244,7 +245,9 @@ export class UserService {
const programResponse: any = programRole.program;
let program: Program | undefined;
if (programResponse){
if (programResponse.id && programResponse.name){
//Determines if retrieving a list of active or inactive programs
let activeFilter = isActive ? programRole.active : !programRole.active;
if (programResponse.id && programResponse.name && activeFilter){
program = new Program(programResponse.id, programResponse.name);
}
}
Expand Down
23 changes: 22 additions & 1 deletion src/components/program/ProgramUsersTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export default class ProgramUsersTable extends Vue {

ProgramUserService.update(updatedUser).then((user: any) : any => {
this.getUsers();
this.$emit('show-success-notification', 'Success! ' + updatedUser.name + ' updated.');
this.$emit('show-success-notification', 'Success! ' + user.name + ' updated.');
if(user.email === this.activeUser!.email) return UserService.getUserInfo();
else return;
}).then((user: any) => {
Expand Down Expand Up @@ -351,6 +351,20 @@ export default class ProgramUsersTable extends Vue {
// if we found a system user by email in checkExistingUserByEmail then system user exists
const systemUserExisted = this.newUser.id !== undefined;

if (systemUserExisted) {
//If the user is an inactive user in the program, need to re-activate through PUT instead
if (this.newUser.active === false){
this.updateUser(this.newUser);

//Ensure new user form closes
this.newUser = new ProgramUser();
this.newUserActive = false;

this.newUserFormState.bus.$emit(DataFormEventBusHandler.SAVE_COMPLETE_EVENT);
return;
}
}

ProgramUserService.create(this.newUser).then((user: ProgramUser) => {
this.paginationController.updatePage(1);
this.paginationController.updateOnAdd();
Expand Down Expand Up @@ -394,6 +408,13 @@ export default class ProgramUsersTable extends Vue {
// email exists
if (users.length === 1) {
user.id = users[0].id;
//Assess if user already has an inactive role in the program
if (users[0].inactiveProgramRoles.length > 0 && this.activeProgram) {
let tester = users[0].inactiveProgramRoles.filter(x => x.program.id == this.activeProgram.id);
if (tester.length > 0) {
user.active = tester[0].active;
}
}
}
} catch (error) {
// Display error that users cannot be loaded
Expand Down
Loading