Skip to content
Open
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
63 changes: 63 additions & 0 deletions app/api/employees.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,67 @@ export default (api) => {

return res.json(out);
});

/**
* @description get the metadata for the employee
* - id: search by employee id
*/
api.get(`/employees/:id/metadata`, async (req, res) => {

// query for employee
if ( !req.params.id ) {
return res.status(400).json({
error: 'Missing employee identifier'
});
}

const id_type = req.query.idType;

let person = await UcdlibEmployees.getById(req.params.id, id_type);
let employeeId = person.res.rows[0].id;

const out = {
total: 0,
results: [],
}

const r = await UcdlibEmployees.getById(employeeId, "id", {includeMetadata:true})

out.total = r.res.rowCount;
out.results = r.res.rows;

return res.json(out);

});

/**
* @description post the updated metadata for the employee
* - id: search by employee id
*/
api.post(`/employees/:id/metadata/`, async (req, res) => {

// query for employee
if ( !req.params.id ) {
return res.status(400).json({
error: 'Missing employee identifier'
});
}

const out = {
total: 0,
results: [],
}

const id = req.body.id;
const metadataValue = req.body.metadataValue;


const results = await UcdlibEmployees.updateMetadata(id, metadataValue)

out.total = results.res.rowCount;
out.results = results.res.rows;

return res.json(out);

});
}
2 changes: 1 addition & 1 deletion app/client/src/elements/pages/bundles/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const defs = {
main : [
'home', 'onboarding', 'separation', 'separation-new', 'separation-single', 'onboarding-new',
'onboarding-single', 'permissions-single', 'permissions'
'onboarding-single', 'permissions-single', 'settings', 'permissions'
],
tools: ['patron', 'orgchart', 'tools']
};
Expand Down
1 change: 1 addition & 0 deletions app/client/src/elements/pages/bundles/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ import "../ucdlib-iam-page-permissions-single";
import "../ucdlib-iam-page-separation";
import "../ucdlib-iam-page-separation-new";
import "../ucdlib-iam-page-separation-single";
import "../ucdlib-iam-page-user-settings";
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function render() {

<p style="margin-bottom:30px;">Upload the most recent csv for the organizational chart here.
Make sure to use the format which includes headers and the required
columns: <br />(Lived Name, EE ID, Email, Notes, Department Name, Working Title, Appointment Type Code, Supervisor ID).
columns: <br >(Lived Name, External ID, Email, Notes, Department Name, Working Title, Appointment Type Code, External ID Reports To).<br />
</p>

<form style="margin:85px 0px 85px 0;" id="csvForm" @submit=${this._onSubmitCSV}>
Expand Down
160 changes: 160 additions & 0 deletions app/client/src/elements/pages/ucdlib-iam-page-user-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { LitElement } from 'lit';
import {render} from "./ucdlib-iam-page-user-settings.tpl.js";
import { LitCorkUtils, Mixin } from '@ucd-lib/cork-app-utils';


/**
* @description Landing page for user settings
*/
export default class UcdlibIamPageUserSettings extends Mixin(LitElement)
.with(LitCorkUtils) {

static get properties() {
return {
updateInProgress: {state: true},
results: {type: Array}
};
}

constructor() {
super();
this.render = render.bind(this);
this._injectModel('AppStateModel','AuthModel', 'EmployeeModel');
this.token = null;
this.firstName = null;
this.lastName = null;
this.metadata = [];
this.updateList = [];
this.noChange = true;
this.enableDirectReportNotification = null;
this.initialDirectReportNotification = null;
}

/**
* @description Disables the shadowdom
* @returns
*/
createRenderRoot() {
return this;
}


/* Add the check for the new user_setting enable flag */

/**
* @method handleDirectReportChange
* @description handle the checkbox changing direct report
*
* @param {Object} e
*/
handleDirectReportChange(e) {

this.enableDirectReportNotification = e.target.checked;
this.noChange = this.initialDirectReportNotification === this.enableDirectReportNotification;

this.requestUpdate();
}


/**
* @method _onAppStateUpdate
* @description bound to AppStateModel app-state-update event
*
* @param {Object} e
*/
async _onAppStateUpdate(e) {
if ( e.page != this.id ) return;
this.AppStateModel.showLoaded(this.id);

this.token = this.AuthModel.getToken().token || null;
this.firstName = this.token.given_name || null;
this.lastName = this.token.family_name || null;
this.iamId = this.token.iamId || null;
this.ccReportsToolTip = "By default, only DIRECT supervisors are CCed on their employee's RT tickets. Checking this box will ensure you are CCed on RT tickets submitted by anyone below you in your reporting line.";

const r = await this.EmployeeModel.getMetadata(this.iamId, "iamId");

this.metadata = r.payload.results[0].metadata;

this.currentDirectReportStatus();

/* More Metadata should be made into a new function */

}

/**
* @method currentDirectReportStatus
* @description get the current Direct Report Status
*/
async currentDirectReportStatus(){
let meta = this.metadata.find(m => m.metadataKey === "cc_notification");
this.directReportsId = meta.metadataId;
if(typeof meta.metadataValue === 'string') {
meta = meta ? meta.metadataValue.toLowerCase() : false;
this.initialDirectReportNotification = meta === "true" ? true: false;

} else {
meta = meta.metadataValue;
this.initialDirectReportNotification = meta;
}
this.enableDirectReportNotification = this.initialDirectReportNotification;

this.requestUpdate();
}

/**
* @description Event handler for when the edit form is submitted
* @param {*} e - form submit event
* @returns
*/
async _onEditSubmit(e){
e.preventDefault();

if ( this.updateInProgress ) return;
this.updateInProgress = true;


this.updateList.push({
id: this.directReportsId,
metadataValue: this.enableDirectReportNotification
});

/* Add future object statements for metadata here */

let r = [];

for(let element of this.updateList){
let res = await this.EmployeeModel.updateMetadata(element, this.iamId);
r.push(res);
}

const allLoaded = r.every(item => item.state === 'loaded');
const hasIs400 = r.some(item => item.error?.payload?.is400 === true);


let successText = `${this.firstName} ${this.lastName}'s User Settings has been updated.`;

if (allLoaded) {
this.AppStateModel.refresh();
setTimeout(() => {
this.AppStateModel.showAlertBanner({message: successText, brandColor: 'quad'});
}, 1000);
this.updateInProgress = false;

} else {
if ( hasIs400) {
this.requestUpdate();
this.AppStateModel.showAlertBanner({message: 'Error when updating the user settings. Form data needs fixing.', brandColor: 'double-decker'});
this.logger.error('Error in form updating user settings', r);
} else {
this.AppStateModel.showAlertBanner({message: 'An unknown error occurred when updating your User Settings', brandColor: 'double-decker'});
this.logger.error('Error updating user settings', r);
}
}
}



}

customElements.define('ucdlib-iam-page-user-settings', UcdlibIamPageUserSettings);
41 changes: 41 additions & 0 deletions app/client/src/elements/pages/ucdlib-iam-page-user-settings.tpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { html } from 'lit';

/**
* @description Main render function for this element
* @returns {TemplateResult}
*/
export function render() {
return html`
<form @submit=${this._onEditSubmit}>
<div class="l-container">
<div class="l-shrink panel o-box">
<h2 class='heading--underline'>RT Functionality</h2>
<fieldset class="checkbox">
<ul class="list--reset">
<li>
<input id="direct-reports"
name="direct-reports"
type="checkbox"
?disabled=${this.updateInProgress}
?checked=${this.enableDirectReportNotification}
@change=${this.handleDirectReportChange}>
<label for="direct-reports">All Direct Reports Notification
<abbr title=${this.ccReportsToolTip}>*</abbr>
</label>
</li>
</ul>
</fieldset>


<button
class='btn btn--primary'
?disabled=${this.updateInProgress || this.noChange}
type='submit'>
<span ?hidden=${!this.updateInProgress} class='u-space-mr--small'><i class='fas fa-circle-notch fa-spin'></i></span>
<span>Update</span>
</button>
</div>
</div>
</form>

`;}
2 changes: 2 additions & 0 deletions app/client/src/elements/ucdlib-iam-app.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function render() {
<ucd-theme-header>
<ucdlib-branding-bar slogan='Identity and Access Management'>
<a href='/logout'>Logout</a>
<a href='/settings'>User Settings</a>
</ucdlib-branding-bar>
<ucd-theme-primary-nav>
<ul link-text='Onboarding' href='/onboarding'>
Expand Down Expand Up @@ -54,5 +55,6 @@ export function render() {
<ucdlib-iam-page-permissions-single id='permissions-single'></ucdlib-iam-page-permissions-single>
<ucdlib-iam-page-permissions id='permissions'></ucdlib-iam-page-permissions>
<ucdlib-iam-page-tools id='tools'></ucdlib-iam-page-tools>
<ucdlib-iam-page-user-settings id='settings'></ucdlib-iam-page-user-settings>
</ucdlib-pages>
`;}
12 changes: 12 additions & 0 deletions app/client/src/models/AppStateModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class AppStateModelImpl extends AppStateModel {
update.location.path.length > 1
) {
p = 'orgchart';
} else if(
update.location.path[0] == 'settings' &&
update.location.path.length > 1
) {
p = 'settings';
} else if(
update.location.path[0] == 'patron' &&
update.location.path.length > 1
Expand Down Expand Up @@ -142,6 +147,9 @@ class AppStateModelImpl extends AppStateModel {
} else if ( update.page === 'patron' ){
title.show = this.store.pageTitles.patronLookup ? true : false;
title.text = this.store.pageTitles.patronLookup;
} else if ( update.page === 'settings' ){
title.show = this.store.pageTitles.userSettings ? true : false;
title.text = this.store.pageTitles.userSettings;
} else if ( update.page === 'tools' ){
title.show = this.store.pageTitles.tools ? true : false;
title.text = this.store.pageTitles.tools;
Expand Down Expand Up @@ -229,6 +237,10 @@ class AppStateModelImpl extends AppStateModel {
breadcrumbs.show = true;
breadcrumbs.breadcrumbs.push(this.store.breadcrumbs.patronLookup);
}
else if ( update.page === 'settings' ){
breadcrumbs.show = true;
breadcrumbs.breadcrumbs.push(this.store.breadcrumbs.userSettings);
}
else if ( update.page === 'tools' ){
breadcrumbs.show = true;
breadcrumbs.breadcrumbs.push(this.store.breadcrumbs.tools);
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/stores/AppStateStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AppStateStoreImpl extends AppStateStore {
permissionsEmployee: {text: 'Select a UC Davis Employee', link: '/permissions#employee'},
orgchart: {text: 'Create Organizational Chart Tool', link: '/orgchart'},
patronLookup: {text: 'Search by Patron Lookup Tool', link: '/patron'},
userSettings: {text: 'User Settings', link: '/settings'},
tools: {text: 'Support Tools', link: '/tools'}
};

Expand All @@ -41,6 +42,7 @@ class AppStateStoreImpl extends AppStateStore {
permissions: 'Employee Permissions',
orgchart: 'Organization Chart Tool',
patronLookup: 'Patron Lookup',
userSettings: 'User Settings',
tools: 'Support Tools'
};

Expand Down
2 changes: 1 addition & 1 deletion app/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AppConfig extends BaseConfig {

this.version = corkBuild.version;

this.routes = ['onboarding', 'separation', 'logout', 'permissions', 'orgchart', 'patron', 'tools'];
this.routes = ['onboarding', 'separation', 'logout', 'permissions', 'orgchart', 'patron', 'settings', 'tools'];
this.title = 'UC Davis Library Identity and Access Management';
this.baseUrl = env.UCDLIB_BASE_URL || 'https://iam.staff.library.ucdavis.edu';
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/compose/ucdlib-iam-support-local-dev/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ services:
- 5432:5432
volumes:
- db-data:/var/lib/postgresql/data
#- ../../deploy/utils/db-entrypoint:/docker-entrypoint-initdb.d
- ../../deploy/utils/db-entrypoint:/docker-entrypoint-initdb.d

adminer:
image: adminer
Expand Down
6 changes: 6 additions & 0 deletions deploy/utils/db-entrypoint/005-metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE metadata (
metadata_id SERIAL PRIMARY KEY,
metadata_key varchar(50) NOT NULL,
metadata_value jsonb,
employee_id integer REFERENCES employees (id)
);
Loading