Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GCRC/nunaliit
Browse files Browse the repository at this point in the history
  • Loading branch information
kunwarj committed Jan 16, 2025
2 parents b7c7201 + 4661eb1 commit b5c6333
Show file tree
Hide file tree
Showing 31 changed files with 897 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ textarea.submission_deny_dialog_reason {
margin-bottom: 5px;
}

textarea.submission_approve_dialog_message {
width: 460px;
height: 125px;
}

.submission_approve_dialog_options {
margin-top: 5px;
margin-bottom: 5px;
}

span.patchSelected, div.patchSelected {
font-weight: bold;
color: #00ff00;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,45 +278,128 @@
});
}

,_approve: function(subDocId, approvedDoc){
,_approve: function(subDocId, approvedDoc, approveFn){
var _this = this;

this._getSubmissionDocument({
subDocId: subDocId
,onSuccess: function(subDoc){
subDoc.nunaliit_submission.state = 'approved';
$n2.couchDocument.adjustDocument(subDoc);

if( approvedDoc ){
subDoc.nunaliit_submission.approved_doc = {};
subDoc.nunaliit_submission.approved_reserved = {};
for(var key in approvedDoc){
if( key.length > 0 && key[0] === '_' ) {
var effectiveKey = key.substr(1);
subDoc.nunaliit_submission.approved_reserved[effectiveKey] =
approvedDoc[key];
} else {
subDoc.nunaliit_submission.approved_doc[key] =
approvedDoc[key];
collectApprovalMessage(function(message, sendEmail) {
_this._getSubmissionDocument({
subDocId: subDocId
,onSuccess: function(subDoc){
subDoc.nunaliit_submission.state = 'approved';
$n2.couchDocument.adjustDocument(subDoc);

if( approvedDoc ){

if (message && message !== '') {
subDoc.nunaliit_submission.approval_message = message;
}

if (sendEmail) {
subDoc.nunaliit_submission.approval_email = {
requested: true
}
}

subDoc.nunaliit_submission.approved_doc = {};
subDoc.nunaliit_submission.approved_reserved = {};
for(var key in approvedDoc){
if( key.length > 0 && key[0] === '_' ) {
var effectiveKey = key.substr(1);
subDoc.nunaliit_submission.approved_reserved[effectiveKey] =
approvedDoc[key];
} else {
subDoc.nunaliit_submission.approved_doc[key] =
approvedDoc[key];
};
};
};
};

_this.submissionDb.updateDocument({
data: subDoc
,onSuccess: function(docInfo){
_this.logger.log( _loc('Submission approved') );
_this._refreshSubmissions();
}
,onError: function(err){
_this.logger.error( _loc('Unable to update submission document: {err}',{err:err}) );
}

_this.submissionDb.updateDocument({
data: subDoc
,onSuccess: function(docInfo){
_this.logger.log( _loc('Submission approved') );
if( typeof approveFn === 'function' ){
approveFn();
};
_this._refreshSubmissions();
}
,onError: function(err){
_this.logger.error( _loc('Unable to update submission document: {err}',{err:err}) );
}
});
}
,onError: function(err){
_this.logger.error( _loc('Unable to obtain submission document: {err}',{err:err}) );
}
});
})

function collectApprovalMessage(callback, sendEmail){
var diagId = $n2.getUniqueId();
var $diag = $('<div>')
.attr('id',diagId)
.addClass('submission_approve_dialog')
.appendTo( $('body') );

$('<textarea>')
.addClass('submission_approve_dialog_message')
.appendTo($diag);

var $options = $('<div>')
.addClass('submission_approve_dialog_options')
.appendTo($diag);

var cbId = $n2.getUniqueId();
$('<input type="checkbox">')
.attr('id',cbId)
.attr('name','send_email')
.appendTo($options);
$('<label>')
.attr('for',cbId)
.text( _loc('Send e-mail to submitter with message') )
.appendTo($options);

var $buttons = $('<div>')
.addClass('submission_approve_dialog_buttons')
.appendTo($diag);

$('<button>')
.addClass('n2_button_ok')
.text( _loc('OK') )
.appendTo($buttons)
.click(function(){
var $diag = $('#'+diagId);

var comment = $diag.find('textarea.submission_approve_dialog_message').val();
var email = $diag.find('input[name="send_email"]').is(':checked');

$diag.dialog('close');
if( typeof callback === 'function' ){
callback(comment,email);
};
});
}
,onError: function(err){
_this.logger.error( _loc('Unable to obtain submission document: {err}',{err:err}) );
}
});

$('<button>')
.addClass('n2_button_cancel')
.text( _loc('Cancel') )
.appendTo($buttons)
.click(function(){
var $diag = $('#'+diagId);
$diag.dialog('close');
});

$diag.dialog({
autoOpen: true
,title: _loc('Enter approval message')
,modal: true
,width: 'auto'
,close: function(event, ui){
var diag = $(event.target);
diag.dialog('destroy');
diag.remove();
}
});
}
}

,_deny: function(subDocId, onDeniedFn){
Expand Down Expand Up @@ -1013,9 +1096,10 @@
.text( _loc('Approve') )
.appendTo($buttons)
.click(function(){
_this._approve(subDocId, proposedDoc);
var $diag = $('#'+diagId);
$diag.dialog('close');
_this._approve(subDocId, proposedDoc, function() {
var $diag = $('#'+diagId);
$diag.dialog('close');
});
return false;
});
$('<button>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static public AtlasProperties fromProperties(Properties props) throws Exception
atlasProps.setCouchDbSubmissionDbName( props.getProperty("couchdb.submission.dbName") );
atlasProps.setCouchDbAdminUser( props.getProperty("couchdb.admin.user") );
atlasProps.setInReachDbName(props.getProperty("couchdb.inreach.dbName", ""));
atlasProps.setExportUser(props.getProperty("export.complete.user"));
atlasProps.setExportPassword(props.getProperty("export.complete.password"));

// CouchDb password
try {
Expand Down Expand Up @@ -201,6 +203,7 @@ static public void writeProperties(File atlasDir, Properties props) throws Excep
Set<String> sensitivePropertyNames = new HashSet<String>();
{
sensitivePropertyNames.add("couchdb.admin.password");
sensitivePropertyNames.add("export.complete.password");
sensitivePropertyNames.add("server.key");
sensitivePropertyNames.add("google.mapapi.key");

Expand Down Expand Up @@ -320,6 +323,8 @@ static public void writeProperties(File atlasDir, Properties props) throws Excep
private String inReachDbName;
private String couchDbAdminUser;
private String couchDbAdminPassword;
private String exportUser;
private String exportPassword;
private int serverPort = 8080;
private boolean restricted = false;
private byte[] serverKey = null;
Expand Down Expand Up @@ -403,6 +408,20 @@ public void setCouchDbAdminPassword(String couchDbAdminPassword) {
this.couchDbAdminPassword = couchDbAdminPassword;
}

public String getExportUser() {
return exportUser;
}
public void setExportUser(String exportUser) {
this.exportUser = exportUser;
}

public String getExportPassword() {
return exportPassword;
}
public void setExportPassword(String exportPassword) {
this.exportPassword = exportPassword;
}

public int getServerPort() {
return serverPort;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ public void runCommand(
// Servlet for export
{
ServletHolder servletHolder = new ServletHolder(new ExportServlet());
servletHolder.setInitParameter("exportUser", atlasProperties.getExportUser());
servletHolder.setInitParameter("exportPassword", atlasProperties.getExportPassword());
servletHolder.setInitOrder(2);
context.addServlet(servletHolder,"/servlet/export/*");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import ca.carleton.gcrc.couch.submission.mail.SubmissionMailNotifierImpl;
import ca.carleton.gcrc.couch.submission.mail.SubmissionMailNotifierNull;
import ca.carleton.gcrc.couch.submission.mail.SubmissionRejectionGenerator;
import ca.carleton.gcrc.couch.submission.mail.SubmissionAcceptedGenerator;
import ca.carleton.gcrc.couch.submission.SubmissionConstants;
import ca.carleton.gcrc.couch.user.UserDesignDocumentImpl;
import ca.carleton.gcrc.couch.user.UserServlet;
Expand Down Expand Up @@ -618,6 +619,15 @@ private void initMail(ServletContext servletContext) throws ServletException {
);
submissionNotifier.setDocumentCreatedGenerator(couchdbTemplate);
}
{
MailMessageGenerator template = new SubmissionAcceptedGenerator();
CouchDbTemplateMailMessageGenerator couchdbTemplate = new CouchDbTemplateMailMessageGenerator(
documentDatabase,
"org.nunaliit.email_template.submission_accepted",
template
);
submissionNotifier.setSubmissionAcceptedGenerator(couchdbTemplate);
}

mailNotification = mail;
this.submissionNotifier = submissionNotifier;
Expand Down
5 changes: 5 additions & 0 deletions nunaliit2-couch-export/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons-compress.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Loading

0 comments on commit b5c6333

Please sign in to comment.