Skip to content

Commit

Permalink
This Fixes att#900
Browse files Browse the repository at this point in the history
  • Loading branch information
sujitbehera27 committed Dec 3, 2014
1 parent c7ffbc3 commit 20095e3
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 4 deletions.
2 changes: 2 additions & 0 deletions conf/rcloud.conf.samp
Expand Up @@ -14,3 +14,5 @@ solr.url: http://127.0.0.1:8983/solr/rcloudnotebooks
solr.page.size: 5
rcs.system.config.addons: rcloud.viewer, rcloud.enviewer
rcloud.languages: rcloud.r, rcloud.python
smtp.server:xxxxxxxxxxxxx
email.from:DoNotREPLY
18 changes: 16 additions & 2 deletions htdocs/js/ui/settings_frame.js
Expand Up @@ -35,17 +35,19 @@ RCloud.UI.settings_frame = (function() {
sort: 10000,
default_value: false,
label: "",
id:"",
set: function(val) {}
}, opts);
return {
sort: opts.sort,
default_value: opts.default_value,
create_control: function(on_change) {
var check = $.el.input({type: 'checkbox'});
$(check).prop('id',opts.id);
var label = $($.el.label(check, opts.label));
$(check).change(function() {
var val = $(this).prop('checked');
on_change(val);
on_change(val,this.id);
opts.set(val);
});
return label;
Expand All @@ -61,6 +63,7 @@ RCloud.UI.settings_frame = (function() {
var that = this;
this.add({
'show-command-prompt': that.checkbox({
id:"show-command-prompt",
sort: 100,
default_value: true,
label: "Show Command Prompt",
Expand All @@ -69,13 +72,24 @@ RCloud.UI.settings_frame = (function() {
}
})
});
this.add({
'subscribe-to-comments': that.checkbox({
id:"subscribe-to-comments",
sort: 100,
default_value: true,
label: "Subscribe To Comments",
set: function(val) {
RCloud.UI.command_prompt.show_prompt(val);
}
})
});
},
load: function() {
var that = this;
var sort_controls = [];
for(var name in options_) {
var option = options_[name];
controls_[name] = option.create_control(function(value) {
controls_[name] = option.create_control(function(value,name) {
if(!now_setting_[name])
rcloud.config.set_user_option(name, value);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/gist/NAMESPACE
@@ -1,2 +1,2 @@
export(auth.url, create.gist, create.gist.comment, current.gist.context, delete.gist.comment, fork.gist, get.gist,
get.gist.comments, modify.gist, modify.gist.comment, set.gist.context, access.token, context.info)
get.gist.comments, modify.gist, modify.gist.comment, set.gist.context, access.token, context.info, get.user)
3 changes: 3 additions & 0 deletions packages/gist/R/comments.R
Expand Up @@ -9,3 +9,6 @@ create.gist.comment <- function (gist.id, content, ctx = current.gist.context()

get.gist.comments <- function (id, ctx = current.gist.context())
UseMethod("get.gist.comments", ctx)

get.user <- function (id, ctx = current.gist.context())
UseMethod("get.user", ctx)
3 changes: 3 additions & 0 deletions packages/gitgist/R/do.R
Expand Up @@ -308,3 +308,6 @@ get.gist.comments.gitgistcontext <- function (id, ctx)
list(ok=TRUE, content=.get.global.json(id, ".comments.json", ctx))

auth.url.gitgistcontext <- function(redirect, ctx) NULL ## no auth provided

get.user.githubcontext <- function (id, ctx)
list(ok=TRUE, content=.get.global.json(id, ".user.json", ctx))
1 change: 1 addition & 0 deletions packages/githubgist/R/do.R
Expand Up @@ -51,4 +51,5 @@ delete.gist.comment.githubcontext <- github::delete.gist.comment

modify.gist.comment.githubcontext <- github::modify.gist.comment

get.user.githubcontext <- github::get.user

33 changes: 33 additions & 0 deletions rcloud.support/R/notebook.comments.R
Expand Up @@ -28,6 +28,7 @@ rcloud.get.comments <- function(id)
rcloud.post.comment <- function(id, content)
{
res <- create.gist.comment(id, content, ctx = .session$gist.context)
rcloud.comments.email(id,content,' posted a new')
if (nzConf("solr.url")) mcparallel(.solr.post.comment(id, content, res$content$id), detached=TRUE)
res
}
Expand All @@ -48,6 +49,7 @@ rcloud.post.comment <- function(id, content)
rcloud.modify.comment <- function(id, cid, content)
{
res <- modify.gist.comment(id,cid,content, ctx = .session$gist.context)
rcloud.comments.email(id,content,' modified an old')
mcparallel(.solr.modify.comment(id, content, cid), detached=TRUE)
res$ok
}
Expand All @@ -71,3 +73,34 @@ rcloud.delete.comment <- function(id,cid)
res <- delete.gist.comment(id,cid, ctx = .session$gist.context)
res$ok
}

rcloud.comments.email <- function(id,content,type) {
to <- .session$username
to.email <- rcloud.get.git.user(to)$email
from.email <- getConf("email.from")
title <- rcloud.get.notebook.info(id)$description
smtp <- getConf("smtp.server")
is.subscribed <- rcloud.config.get.single.user.option(to,'subscribe-to-comments')

if (from.email == "" || length(from.email) == 0)
from.email <- 'DoNotREPLY'

if(is.null(is.subscribed) | length(is.subscribed) == 0 | smtp == "" || length(smtp) == 0)
is.subscribed <- FALSE

if(is.subscribed) {
subject <- paste(.session$username,type," comment on your notebook [",title,"]",sep="");
cont <- rcloud.create.email(fromJSON(content[1]))
msg <- mime_part(cont)
msg[["headers"]][["Content-Type"]] <- "text/html"
body <- list(msg)
sendmail(from.email, to.email, subject,body , control=list(smtpServer=smtp))
}
}

rcloud.create.email <- function(content) {
url <- .session$url
email.content <- paste0('<html><head><title>Comment Notification</title></head><body><div><h3>Comment :</h3><p>"',
content,'"</p><p><a href=\'',url,'\' target=\'',url,'\'>Go To Notebook</a></p></div></body></html>')
email.content
}
5 changes: 4 additions & 1 deletion rcloud.support/R/rcloud.support.R
Expand Up @@ -3,7 +3,7 @@

# FIXME what's the relationship between this and rcloud.config in conf.R?
rcloud.get.conf.value <- function(key) {
Allowed <- c('host', 'github.base.url', 'github.api.url', 'github.gist.url','solr.page.size')
Allowed <- c('host', 'github.base.url', 'github.api.url', 'github.gist.url','solr.page.size','smtp.server','email.from')
if(key %in% Allowed)
getConf(key)
else
Expand Down Expand Up @@ -638,6 +638,9 @@ rcloud.config.set.user.option <- function(key, value)
rcloud.config.get.alluser.option <- function(key)
rcs.get(rcs.key(user=".allusers", notebook="system", "config", key))

rcloud.config.get.single.user.option <- function(userid,key)
rcs.get(rcs.key(user=userid, notebook="system", "config", key))

################################################################################
# notebook cache

Expand Down

0 comments on commit 20095e3

Please sign in to comment.