Skip to content

Commit

Permalink
Merge branch 'rethinkdb' into nich/react
Browse files Browse the repository at this point in the history
Conflicts:
	salvus/page/projects.cjsx
  • Loading branch information
nicholasruhland committed Aug 7, 2015
2 parents 64a8413 + df054c7 commit 0b0ef62
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 15 deletions.
7 changes: 3 additions & 4 deletions salvus/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1936,8 +1936,8 @@ class SyncTable extends EventEmitter
@_last_err = err
if @_closed
throw "object is closed"
#console.log("query #{@_table}: -- got result of doing query", resp)
if first
# result of doing query
first = false
if err
#console.log("query #{@_table}: _run: first error ", err)
Expand Down Expand Up @@ -2009,7 +2009,7 @@ class SyncTable extends EventEmitter

# Figure out what to change in our local view of the database query result.
if not @_value_local? or not @_value_server?
# Easy case -- nothing has been initialized yet, so just set everything.
#console.log("_update_all: easy case -- nothing has been initialized yet, so just set everything.")
@_value_local = @_value_server = immutable.fromJS(x)
first_connect = true
changed_keys = misc.keys(x) # of course all keys have been changed.
Expand Down Expand Up @@ -2054,7 +2054,6 @@ class SyncTable extends EventEmitter
# First connection and table is empty.
@emit('change', changed_keys)


_update_change: (change) =>
#console.log("_update_change", change)
changed_keys = []
Expand Down Expand Up @@ -2165,7 +2164,7 @@ class SyncTable extends EventEmitter
@emit('change')
@save(cb)

close: =>
close : =>
@_closed = true
@removeAllListeners()
if @_id?
Expand Down
5 changes: 3 additions & 2 deletions salvus/page/editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ class exports.Editor

# This approach to public "editor"/viewer types is temporary.
if extra_opts.public_access
opts.read_only = true
if filename_extension_notilde(filename) == 'html'
if opts.content.indexOf("#ipython_notebook") != -1
editor = new JupyterNBViewer(@, filename, opts.content)
Expand All @@ -902,6 +903,7 @@ class exports.Editor
if extra_opts.public_access
# This is used only for public access to files
editor = new CodeMirrorEditor(@, filename, opts.content, extra_opts)
editor.element.find("a[href=#split-view]").hide() # disable split view for public worksheets
if filename_extension_notilde(filename) == 'sagews'
editor.syncdoc = new (syncdoc.SynchronizedWorksheet)(editor, {static_viewer:true})
editor.once 'show', () =>
Expand Down Expand Up @@ -1386,7 +1388,6 @@ exports.FileEditor = FileEditor
class CodeMirrorEditor extends FileEditor
constructor: (@editor, @filename, content, opts) ->
editor_settings = flux.getStore('account').get_editor_settings()

opts = @opts = defaults opts,
mode : required
geometry : undefined # (default=full screen);
Expand Down Expand Up @@ -2222,7 +2223,7 @@ class CodeMirrorEditor extends FileEditor

# add a textedit toolbar to the editor
init_sagews_edit_buttons: () =>
if @opts.readonly # no editing button bar needed for read-only files
if @opts.read_only # no editing button bar needed for read-only files
return

if IS_MOBILE # no edit button bar on mobile either -- too big (for now at least)
Expand Down
16 changes: 16 additions & 0 deletions salvus/page/projects.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,22 @@ class ProjectsTable extends Table

flux.createTable('projects', ProjectsTable)

# This doesn't belong as an action unless it works by setting something in the store. Put it here for now.
# Will move it later...
exports.get_public_project_title = (project_id, cb) ->
salvus_client.query
query :
public_projects : {project_id : project_id, title : null}
cb : (err, resp) ->
if err
cb(err)
else
title = resp?.query?.public_projects?.title
if not title?
cb("unable to get title")
else
cb(undefined, title)

exports.open_project = open_project = (opts) ->
opts = defaults opts,
project_id: required
Expand Down
51 changes: 44 additions & 7 deletions salvus/rethink.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,28 @@ class RethinkDB
cb(err)
], (err) => opts.cb(err, groups))

# return list of paths that are public (and not disabled)
get_public_paths: (opts) =>
opts = defaults opts,
project_id : required
cb : required
if not @_validate_opts(opts) then return
# TODO: filter disabled on server not on client!
query = @table('public_paths').getAll(opts.project_id, index:'project_id')
query.filter(@r.row("disabled").eq(false).default(true)).pluck('path').run (err, v) =>
if err
opts.cb(err)
else
opts.cb(undefined, (x.path for x in v))

has_public_path: (opts) =>
opts = defaults opts,
project_id : required
cb : required # cb(err, has_public_path)
query = @table('public_paths').getAll(opts.project_id, index:'project_id')
query.filter(@r.row("disabled").eq(false).default(true)).count().run (err, n) =>
opts.cb(err, n>0)

path_is_public: (opts) =>
opts = defaults opts,
project_id : required
Expand All @@ -1158,13 +1180,13 @@ class RethinkDB
# Get all public paths for the given project_id, then check if path is "in" one according
# to the definition in misc.
# TODO: implement caching + changefeeds so that we only do the get once.
@table('public_paths').getAll(opts.project_id, index:'project_id').pluck('path', 'disabled').run (err, v) =>
if err
opts.cb(err)
return
public_paths = (x.path for x in v when not x.disabled)
is_public = misc.path_is_in_public_paths(opts.path, public_paths)
opts.cb(undefined, is_public)
@get_public_paths
project_id : opts.project_id
cb : (err, public_paths) =>
if err
opts.cb(err)
else
opts.cb(undefined, misc.path_is_in_public_paths(opts.path, public_paths))

# Set last_edited for this project to right now, and possibly update its size.
# It is safe and efficient to call this function very frequently since it will
Expand Down Expand Up @@ -2001,6 +2023,21 @@ class RethinkDB
if x == 'account_id'
v.push(opts.account_id)
cb()
else if x == 'project_id-public'
if not opts.query.project_id
cb("must specify project_id")
else
if SCHEMA[opts.table].anonymous
@has_public_path
project_id : opts.query.project_id
cb : (err, has_public_path) =>
if err
cb(err)
else if not has_public_path
cb("project does not have any public paths")
else
v.push(opts.query.project_id)
cb()
else if x == 'project_id'
if not opts.query.project_id
cb("must specify project_id")
Expand Down
21 changes: 19 additions & 2 deletions salvus/schema.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ schema.table_name =
cmd : 'getAll'
args : ['account_id'] # special args that get filled in:
'account_id' - replaced by user's account_id
'project_id' - filled in by project_id, which must be specified in the query itself
'project_id' - filled in by project_id, which must be specified in the query itself;
(if table not anonymous then project_id must be a project that user has read access to)
'project_id-public' - filled in by project_id, which must be specified in the query itself;
(if table not anonymous then project_id must be of a project with at east one public path)
'all_projects_read' - filled in with list of all the id's of projects this user has read access to
'collaborators' - filled in by account_id's of all collaborators of this user
an arbitrary function - gets called with an object with these keys:
Expand Down Expand Up @@ -150,7 +153,6 @@ schema.accounts =
type : 'timestamp'
desc : 'When this user was last active.'
indexes :
email_address : []
passports : ["that.r.row('passports').keys()", {multi:true}]
created_by : ["[that.r.row('created_by'), that.r.row('created')]"]
email_address : []
Expand Down Expand Up @@ -455,6 +457,21 @@ schema.projects =
for group in require('misc').PROJECT_GROUPS
schema.projects.indexes[group] = [{multi:true}]

# Get publicly available information about a project.
#
schema.public_projects =
anonymous : true
virtual : 'projects'
user_query :
get :
all :
cmd : 'getAll'
args : ['project_id-public']
fields :
project_id : true
title : true


schema.public_paths =
primary_key: 'id'
anonymous : true # allow user *read* access, even if not signed in
Expand Down

0 comments on commit 0b0ef62

Please sign in to comment.