Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
BobLamarley committed Dec 25, 2024
1 parent b35c686 commit a2f9c41
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 125 deletions.
8 changes: 3 additions & 5 deletions manager2/src/app/admin/projects/projects.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ <h3>Pending projects</h3>
<td>
<div class="btn-group">
<button type="button" style="margin-right: 0px !important; " class="p-button p-button-sm p-button-info " (click)="modify_project(pending)">View</button>
<button type="button" style="margin-right: 0px !important; " class="p-button p-button-sm p-button-danger " (click)="openRejectModal(pending)">Reject</button>
<button type="button" style="margin-right: 0px !important; " class="p-button p-button-sm p-button-danger " data-toggle="modal" data-target="#rejectModal" (click)="openRejectModal(pending)">Reject</button>
</div>
</td>
</tr>
Expand Down Expand Up @@ -318,10 +318,8 @@ <h3 class="panel-title">Group creation</h3>
</div>
</div>

<!-- Reject Modal -->
<div
class="modal"
style="z-index: 1500;"
class="modal fade"
id="rejectModal"
tabindex="-1"
role="dialog"
Expand Down Expand Up @@ -372,4 +370,4 @@ <h5 class="modal-title">Reject Project</h5>
</div>
</div>
</div>
</div>
</div>
78 changes: 36 additions & 42 deletions manager2/src/app/admin/projects/projects.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ProjectsComponent implements OnInit {

rejectionReason: string = ''
currentProject: any = null
user_uid: string = null

constructor(
private route: ActivatedRoute,
Expand Down Expand Up @@ -290,68 +291,61 @@ export class ProjectsComponent implements OnInit {

reject_project(input_project: any) {
const project: Project = this.projectService.mapToProject(input_project);
this.reset_msgs()
this.reset_msgs();
this.projectService.delete_pending(project.uuid).subscribe(
resp => {
(resp) => {
this.pending_msg = resp.message;
this.pending_list(true);
},
err => this.pending_err_msg = err.error
(err) => {
this.pending_err_msg = err.error;
}
);

}

openRejectModal(project: any) {
openRejectModal(project: any, user_uid: any) {
this.currentProject = project
const rejectModal = document.getElementById('rejectModal')
if (rejectModal) {
(rejectModal as any).style.display = 'block'
rejectModal.classList.add('show')
}
this.user_uid = user_uid
}

closeRejectModal() {
const rejectModal = document.getElementById('rejectModal')
const rejectModal = document.getElementById('rejectModal');
if (rejectModal) {
(rejectModal as any).style.display = 'none'
rejectModal.classList.remove('show')
// Simulate the close functionality
rejectModal.classList.remove('show');
rejectModal.setAttribute('aria-hidden', 'true');
rejectModal.style.display = 'none';

// Remove the backdrop if present
const modalBackdrop = document.querySelector('.modal-backdrop');
if (modalBackdrop) {
modalBackdrop.remove();
}

// Restore scrolling
document.body.classList.remove('modal-open');
document.body.style.overflow = '';
document.body.style.paddingRight = '';
}
this.rejectionReason = ''
this.currentProject = null
this.user_uid = null
}

confirmRejectProject() {
//this.reject_project(this.currentProject)

if (this.rejectionReason) {
console.log(this.currentProject)
console.log(`Reason provided: ${this.currentProject}`);
console.log(`Reason provided: ${this.currentProject.uuid}`);
console.log(`Reason provided: ${this.currentProject.owner}`);



// Fetch the user details
this.userService.getUser(this.currentProject.owner).subscribe(
async (resp) => {
this.projectService.reject_project(this.currentProject.uuid, this.rejectionReason, resp.email).subscribe(
() => {
console.log('Rejection email sent successfully.');
},
err => {
console.error('Failed to send rejection email:', err);
}
);
},
(err) => {
console.error('Failed to get user email:', err);
this.reject_project(this.currentProject);
if(this.rejectionReason)
this.userService.notify(this.currentProject.owner, {
subject: `: Project ${this.currentProject.id} creation rejected`,
message: `The reason why your project was not accepted by one of our admins is the following: ${this.rejectionReason}`,
send_copy_to_support: true
}).subscribe(
err => {
console.log(('failed to send mail'));
}
);
} else {
console.warn('Rejection reason or current project is missing.');
}
this.closeRejectModal()


this.closeRejectModal();
}

reset_msgs() {
Expand Down
17 changes: 5 additions & 12 deletions manager2/src/app/admin/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,23 +291,16 @@ export class ProjectsService {
}

delete_pending(projectUuid: string): Observable<any> {
//let user = this.authService.profile;
let params = new HttpParams();
let params = new HttpParams().set('uuid', projectUuid);

let httpOptions = {
//headers: new HttpHeaders({
// 'x-api-key': user.apikey
//}),
params: params
const httpOptions = {
params: params,
};

return this.http.delete(
environment.apiUrl + '/pending/project/' + projectUuid,
environment.apiUrl + '/pending/project',
httpOptions
);
}

reject_project(projectUuid: string, rejectionReason: string, ownerEmail: string): Observable<any> {
return this.http.post(`${environment.apiUrl}/pending/project/${projectUuid}/reject`, { rejectionReason, ownerEmail });
}

}
76 changes: 11 additions & 65 deletions routes/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,16 @@ router.delete('/pending/project/:uuid', async function (req, res) {
res.status(401).send('Not authorized');
return;
}

let user = null;
let isadmin = false;

try {
user = await dbsrv.mongo_users().findOne({ _id: req.locals.logInfo.id });
isadmin = await rolsrv.is_admin(user);
} catch(e) {
} catch (e) {
logger.error(e);
res.status(404).send({message: 'User session not found'});
res.status(404).send({ message: 'User session not found' });
res.end();
return;
}
Expand All @@ -558,85 +560,29 @@ router.delete('/pending/project/:uuid', async function (req, res) {
res.status(404).send('User not found');
return;
}

if (!isadmin) {
res.status(401).send('Not authorized');
return;
}

try {
await prjsrv.remove_project_request(req.params.uuid, user.uid);
} catch(e) {
} catch (e) {
logger.error(e);
if (e.code && e.message) {
res.status(e.code).send({message: e.message});
res.end();
return;
res.status(e.code).send({ message: e.message });
} else {
res.status(500).send({message: 'Server Error, contact admin'});
res.end();
return;
res.status(500).send({ message: 'Server Error, contact admin' });
}
}
res.send({ message: 'Pending Project deleted'});

});

router.post('/pending/project/:uuid/reject', async function (req, res) {
if (!req.locals.logInfo.is_logged) {
res.status(401).send('Not authorized');
return;
}

const rejectionReason = req.body.rejectionReason?.trim();
if (!rejectionReason) {
res.status(400).send({ message: 'Rejection reason is required.' });
return;
}

const ownerEmail = req.body.rejectionReason?.trim();
if (!ownerEmail) {
res.status(400).send({ message: 'owner Email is required.' });
return;
}

let user = null;
let isadmin = false;

try {
user = await dbsrv.mongo_users().findOne({ _id: req.locals.logInfo.id });
isadmin = await rolsrv.is_admin(user);
} catch (e) {
logger.error(e);
res.status(404).send({ message: 'User session not found' });
return;
}

if (!user) {
res.status(404).send('User not found');
return;
}
if (!isadmin) {
res.status(401).send('Not authorized');
return;
}

try {
await maisrv.send_notif_mail({
name: 'rejection_project_creation',
destinations: [ownerEmail, CONFIG.general.accounts],
subject: `[Creation project rejected] `,
message: `Your project "${ownerEmail}" has been rejected for the following reason: ${rejectionReason}`,
});
logger.info(`Rejection email sent to: ${ownerEmail}`);
} catch (emailError) {
logger.error('Failed to send rejection email:', emailError);
res.status(500).send({ message: 'Failed to send rejection email.' });
res.end();
return;
}

res.send({ message: 'Rejection email sent successfully.' });
res.send({ message: 'Pending Project deleted' });
});


router.get('/project/:id/users', async function(req, res){
if(! req.locals.logInfo.is_logged) {
res.status(401).send({message: 'Not authorized'});
Expand Down
3 changes: 2 additions & 1 deletion routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ router.post('/user/:id/notify', async function(req, res) {
}
let message = req.body.message;
let subject = req.body.subject;
let send_copy_to_support = req.body.send_copy_to_support;
let msg_destinations = [user.email];
if (user.send_copy_to_support) {
if (user.send_copy_to_support || send_copy_to_support) {
msg_destinations.push(CONFIG.general.support);
}

Expand Down

0 comments on commit a2f9c41

Please sign in to comment.