Skip to content

Commit

Permalink
Polish documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Jan 25, 2019
1 parent df5c604 commit 0372756
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ Appmode consist of a server-side and a notebook extension for Jupyter. Together

- To allow for passing information between notebooks via url parameters, the current url is injected into the variable ``jupyter_notebook_url``.

## Customization
## Server Side Configuration

Appmode has the following configuration options:
- `Appmode.trusted_path` Run only notebooks below this path in Appmode. Default: No restrictions.
- `Appmode.show_edit_button` Show _Edit App_ button during Appmode. Default: True.
- `Appmode.show_other_button` Show other buttons, e.g. Logout, during Appmode. Default: True.

## Client Side Customization

The UI elements of Appmode can be customized via the [custom.js](http://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/JavaScript%20Notebook%20Extensions.html#custom.js) file. Some examples are:
```
Expand Down
39 changes: 19 additions & 20 deletions appmode/server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,26 @@


class Appmode(LoggingConfigurable):
"""Object containing server-side configuration settings for appmode.
Defined separately from the AppmodeHandler to avoid multiple inheritance
and constructor conflicts.
"""Object containing server-side configuration settings for Appmode.
Defined separately from the AppmodeHandler to avoid multiple inheritance.
"""
trusted_path = Unicode('', help="Only allow notebooks under this web path to launch in app mode", config=True)
show_edit_button = Bool(True, help="Show Edit App button in the appmode header", config=True)
show_other_buttons = Bool(True, help="Show other notebook buttons in the appmode header (e.g., Logout)", config=True)
trusted_path = Unicode('', help="Run only notebooks below this path in Appmode.", config=True)
show_edit_button = Bool(True, help="Show Edit App button during Appmode.", config=True)
show_other_buttons = Bool(True, help="Show other buttons, e.g. Logout, during Appmode.", config=True)

#===============================================================================
class AppmodeHandler(IPythonHandler):
@property
def trusted_path(self):
"""Trusted appmode path"""
return self.settings['appmode_manager'].trusted_path
return self.settings['appmode'].trusted_path

@property
def show_edit_button(self):
"""Edit App button in appmode header"""
return self.settings['appmode_manager'].show_edit_button
return self.settings['appmode'].show_edit_button

@property
def show_other_buttons(self):
"""Other buttons in appmode header"""
return self.settings['appmode_manager'].show_other_buttons
return self.settings['appmode'].show_other_buttons

#===========================================================================
@web.authenticated
Expand All @@ -45,11 +41,10 @@ def get(self, path):
path = path.strip('/')
self.log.info('Appmode get: %s', path)

# Abort if the app we're trying to open does not live in the configured
# application path
# Abort if the app path is not below configured trusted_path.
if not path.startswith(self.trusted_path):
self.log.warn('Appmode refused to launch %s outside trusted path %s', path, self.trusted_path)
raise web.HTTPError(401, 'Notebook is not in a trusted appmode path')
self.log.warn('Appmode refused to launch %s outside trusted path %s.', path, self.trusted_path)
raise web.HTTPError(401, 'Notebook is not within trusted Appmode path.')

cm = self.contents_manager

Expand Down Expand Up @@ -132,8 +127,8 @@ def load_jupyter_server_extension(nbapp):
#nbapp.extra_template_paths.append(tmpl_dir) # dows

# For configuration values that can be set server side
mgr = Appmode(parent=nbapp)
nbapp.web_app.settings['appmode_manager'] = mgr
appmode = Appmode(parent=nbapp)
nbapp.web_app.settings['appmode'] = appmode

# slight violation of Demeter's Law
rootloader = nbapp.web_app.settings['jinja2_env'].loader
Expand All @@ -145,6 +140,10 @@ def load_jupyter_server_extension(nbapp):
host_pattern = '.*$'
route_pattern = url_path_join(web_app.settings['base_url'], r'/apps%s' % path_regex)
web_app.add_handlers(host_pattern, [(route_pattern, AppmodeHandler)])
nbapp.log.info("Appmode server extension loaded with trusted path: %s", mgr.trusted_path)

if appmode.trusted_path:
nbapp.log.info("Appmode server extension loaded with trusted path: %s", appmode.trusted_path)
else:
nbapp.log.info("Appmode server extension loaded.")

#EOF

0 comments on commit 0372756

Please sign in to comment.