Giter Site home page Giter Site logo

moodle-local_envbar's Introduction

GitHub Workflow Status (branch)

Environment bar - Moodle local plugin

image

This displays a prominment header across across the top of your NON PROD Moodle environments which can be configured to have different colors and messages for each environent, and also automatically detects and show you when the DB was last refreshed.

It's very useful when working with lots of different environments to avoid confusion around where you are, especially when env's can contain hard coded links and you accidentally jump between environments.

Principals

Showing what environment you are in needs to be reliable and fail safe.

If it doesn't work for any reason then you may as well not have it. The way this plugin works is that in your production system you specify what your different environments are. Then after a refresh of production data back to a staging environment it can auto detect that it is no longer in production and warn the end user. Further more if there isn't any config at all, then it will assume you are in a fresh development environment that hasn't been refreshed and show a default fail safe warning.

It will also automatically detect and show you when the environment was last refreshed from production, which is a common question testers ask.

Branches

Moodle version Totara version Branch PHP
Moodle 2.7 to 3.2 Totara 2.7 to 11 VERSION1 5.5+
Moodle 3.3 to 3.9 Totara 12 VERSION2 7.0+
Moodle 3.10+ Totara 13 VERSION3 7.3+

Installation

Add the plugin to /local/envbar/

Run the Moodle upgrade.

Configuration

Upon first installation you will see a notification across the screen that prodwwwroot has not been set. There is a convenient link in the bar to:

Site administration > Plugins > Local Plugins > Environment bar

Please set this value to be exactly what your production $CFG->wwwroot is. If you are on the production box then you can click on the 'autofill' button.

Or you can define the environments and prodwwwroot in config.php:

$CFG->local_envbar_prodwwwroot = 'http://moodle.prod';
$CFG->local_envbar_items = array(
    array(
        'matchpattern' => 'https://staging.moodle.edu',
        'showtext'     => 'Staging environment',
        'colourbg'     => 'orange',
        'colourtext'   => 'white',
    ),
    array(
        'matchpattern' => 'https://qa.moodle.edu',
        'showtext'     => 'QA environment',
        'colourbg'     => 'purple',
        'colourtext'   => 'white',
    ),
    array(
        'matchpattern' => 'http://moodle.local',
        'showtext'     => 'Localhost environment',
        'colourbg'     => 'black',
        'colourtext'   => 'white',
    ),
);

The colours available are,

black
white
red
green
seagreen
yellow
brown
blue
slateblue
chocolate
crimson
orange
darkorange

Please configure a secret key which is needed to let the environments talk to each other. If no secret key is set, the non production environments won't be able to detect their last reset time. Please set it to some random alphanumeric string of your choice or press the 'Generate' button. Or you can define the secret key in config.php:

$CFG->local_envbar_secretkey = 'SomeRandomAlphanumericalString';

In your non production environments it is also useful to inform your users when the next refresh will be. This time can be injected into the DB or set via config.php and can be flexibly set in a variety of ways:

// A unix timestamp:
$CFG->forced_plugin_settings['local_envbar']['nextrefresh'] = 1490946920;

// Any date string:
$CFG->forced_plugin_settings['local_envbar']['nextrefresh'] = '2017-04-03 4:00pm';

// Any valid strtotime string eg 2am every night:
$CFG->forced_plugin_settings['local_envbar']['nextrefresh'] = '2:00am';

moodle-local_envbar's People

Contributors

abias avatar andrewmadden avatar anupamatd avatar brendanheywood avatar bwalkerl avatar dkleto avatar dmitriim avatar golenkovm avatar ilyatregubov avatar jwalits avatar kattekrab avatar keevan avatar matthewhilton avatar nhoobin avatar peterburnett avatar peterspicer-catalyst avatar rhell4 avatar roperto avatar sarahjcotton avatar scottverbeek avatar suankan avatar tessa-fabry avatar tsmilan avatar tuanngocnguyen avatar xuangui2018 avatar yao9394 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moodle-local_envbar's Issues

Debugging message: This page did not call $PAGE->set_url(...)

My steps:

  1. Create a new course
  2. Set format: single activity
  3. Set activity: page
  4. Save and display.

PS: I also have cleanurls on, it could be related.

This page did not call $PAGE->set_url(...). Using http://moodle.test/mod/page/view.php?id=20
line 600 of /lib/pagelib.php: call to debugging()
line 820 of /lib/pagelib.php: call to moodle_page->magic_get_url()
line 313 of /local/envbar/renderer.php: call to moodle_page->__get()
line 162 of /local/envbar/renderer.php: call to local_envbar_user_menu()
line 292 of /local/envbar/classes/local/envbarlib.php: call to local_envbar_renderer->render_envbar()
line 44 of /local/envbar/lib.php: call to local_envbar\local\envbarlib::inject()
line 1405 of /lib/navigationlib.php: call to local_envbar_extend_navigation()
line 2873 of /lib/navigationlib.php: call to global_navigation->initialise()
line 451 of /course/format/singleactivity/lib.php: call to global_navigation->find()
line 1108 of /lib/pagelib.php: call to format_singleactivity->page_set_cm()
line 2702 of /lib/moodlelib.php: call to moodle_page->set_cm()
line 3046 of /lib/moodlelib.php: call to require_login()
line 50 of /mod/page/view.php: call to require_course_login()

Add colour picker (hex) option

Instead of having a set list of default colours, a colour picker than stores a hex value would be better suited, allowing clients to add their style guide colours.

This has already been requested by one client.

Undefined property: stdClass::$prodlastcheck

Moodle 3.3

Being on 53e686b of local/envbar
Envbar is not configured at all. When on /local/envbar/index.php I'm getting Notice: Undefined property: stdClass::$prodlastcheck in /local/envbar/index.php on line 94

Add support for multilang tags in "text to show"

Hi,

I'm looking forward to bring your very helpful plugin into production.
However, there are some things would would be even more helpful if they would exist:

Could you please think about adding support for multilang tags in the "text to show" setting, i.e. process it with format_string() ?

Background information: I want not only to show the name of the Moodle instance, but also a quick & helping description in the user's language about the instance.

Thanks,
Alex

Some 'design' or 'stage' urls won't save properly and get overwritten in the admin gui

eg enter two url's like d-blah.com and s-blah.com, and save. They will both get saved as d-blah.com

The exact circumstances aren't clear, but it looks like they need to have the same suffix and tld, and it only seems to apply to s- and d- and not other things like t- or j-.

Maybe a leaking regular expression?

eg a single record with:

https://s-learn.nbcs.nsw.edu.au/

gets changed to

https://d-learn.nbcs.nsw.edu.au/

Ability to quickly remove the bar temporarily

There is a requirement for some people to take screenshots, either for testing or for documentation purposes and they don't want to see the envbar. Rather than disable the whole envbar which defeats the purpose of it, a simpler feature would just be a X top right which kills the bar on this page, but it's stil comes back on reload.

Be able to manually specify the last refresh date

  • For worst case if something is busted with the refresh process or whatever, just a very simple form which lets you set the full date / time of the refresh. You would only do this in the non prod environment, if you are in prod this doesn't make sense

Show envbar only to admin users on a new install when prodwwwroot is not set.

If the local_envbar/prodwwwroot has not been set then a large red default environment bar will be shown to all users of the site indicating that it is required to be configured.

I propose to only show it to users that have administration capabilities initially until it has been setup correctly. They are the users that would be installing and configuring the plugin.

Auto detect the different refresh ages of each environment

This means each env will talk to each other. We could make each non-prod env call back to prod, as the prod env is usually more visible than the non prod envs, or the other way around.

It would be better for prod to only pin on demand each non prod env, as it is away of them all, but likely not routable.

We don't ever want this to be some sort of ddos attack on prod, the update notification should be very minimal, eg once every 24 hours, but it is also pushing across a timestamp of when it was last refreshed which won't change much.

So:

  • a new task, run every 24 hours
  • store our last ping time to prod, if our last refresh isn't newer then don't ping
  • ping a very simple rest call on the prod with a timestamp and a hash of both the url + the title. This is a very basic form of authenticating as only prod and the refreshed env's will know both the title and the url. If the title changes then this will have to be in place before the refresh gets a new date.

There is a possible edge case / opportunity - if we are refreshing from one box to a bunch of other boxes and we add another one, it might be useful if prod got notified of them all anyway. This might be a list of 'other env's' and you could one-click add it to the proper list. A poor-mans quick & simple way of getting your head around how many env's have been floating around if you are sans pipelines etc.

  • So if hash doesn't match then just ignore it, but if it doesn't match AND the url is one not in our list, then go store this somewhere. Do this in a new table somewhere, or in the same table but with a flag and split the list.

Last refreshed date detection

  • make a cron task, run it every 10 minutes.
    • IF the current box matches the production url then store a cfg value for the current time
    • IF it doesn't match then don't touch it
  • when displaying the envbar (ie we are non prod) then read this value and prominently display how old the data is

Multiple versions of the static html saved into the additionalhtmlhead setting

If you edit via:

/admin/settings.php?section=additionalhtml

then the envbar doesn't bootstrap, and so the config element will not be resaved with a static copy of the envbar output.

However if you edit via this page:

https://moodle-upgrade.cqu.edu.au/admin/search.php?query=additionalhtml

This is will. So if you save it 3 times you will get 3 copies of the static html baked into that config item.

The root cause is the timing of the execution which we cannot do anything about. So what I think the most viable solution is a post save cleanup.

  • in the renderer we need some unchanging tokens which we can use to detect the present and extend of the static html. I would suggest adding something like:
<!-- STARTENVBAR -->
<div class="envbar">...
<!--ENDENVBAR -->
  • when the envbar bootstraps, it should quickly test $CFG->additionalhtml to see if it contains STARTENVBAR, and if so then it will regex out that chunk and resave the config item.

JS error if there is no User Menu

If there is no user menu (menu selector is empty), JS will error:

view.php?id=81:111 Uncaught DOMException: Failed to execute 'querySelector' on 'Document': The provided selector is empty.

Detect and warn when jumping between environments

The main risk here is testing on a test box, clicking on a link which is hard coded to prod, not noticing the difference, and then continuing on potentially busting prod data.

  • look at the referrer, if is set
  • and it isn't then same as the wwwroot we are in
  • and it is one of the alternate env's? if so then make a custom warning message. Make is super spammy with something pretty garish

This has some caveats, such as the referrer not being passed when jumping from http to https and vice versa. To do this properly the environments, at least the testing ones, need to send the referrer header. If there is a mismatch between http / https etc they won't be sent, so we want to define a referer policy to always send in these cases. We want the full dirty 'unsafe-url' policy BUT only for dev.

  • tack the policy onto the header

https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-unsafe-url

Support is some evergreens:

http://caniuse.com/#feat=referrer-policy

Make bar smaller (or adjustable)

I really like this plugin, but we would like to the bar to be a bit shorter (less white space above and below the words). Because of how the styles are applied, it's harder to override in our custom styles.

It would be nice if it was: a) smaller, b) a setting, c) overridable.

The last one could be done by getting rid of !important. I assume you added it because the default one would override, but you just need a higher scoring selector, like header.nabvar-fixed-top, .navbar.nabvar-fixed-top, or body .nabvar-fixed-top.

Document example of background image css offset in readme

If there is a background image, the spacer will not push it down.

We can offset it in the CSS field as a fix, but if the bar is closed it is not restored.

Quick idea: an 'extra JS on hide' which runs when the close button is pressed.

Make color selection and ux better

  • convert to a text area which can accept any valid css color OR a css keyword instead of a dropdown, needs some regex validation either #000 - #fff OR #000000 - #ffffff OR a string of chars. regex /#([a-f0-9]{3}){1,2}\b/i Don't attempt to validate the list of valid css keywords.
  • set the type of the input to color, it will default to text if it isn't available
  • move the set of old options into a data list for the text field, make the list smaller, test how this works in various browsers and see
  • enable new records by default
  • Change: Add 1 field(s) to form => 'Add another environment'

See also:

http://caniuse.com/#feat=datalist

https://developer.mozilla.org/en/docs/Web/HTML/Element/datalist

Convert the env bar to a renderer

  • make a renderer for the envbar, pass in everything it needs
  • pass in an extra flag to say wether it is staticly fixed, or just a normal div
  • call this render in the inject function with the static position
  • also call it for each env in the config page as a preview, but not fixes, inline
  • also call it for the 'default' unmatched env

More color ux improvement

  • when adding a new environment, have the default black / white bar preview show
  • onkeyup / onchange update the color bar preview

Support of Moodle 3.2

Moodle 3.2 came out. Would be good to support a new Boost theme
At the moment the bar hides top menu.

  • add to travis
  • test against boost theme
  • test against bootstrap theme

Add next refresh date advisory notice to bar

When the washing / refresh process has run, it would be very useful for the process to inject some config into the database to advise when the next expected cleaning process will run, ie when data will go missing.

Thinking something very simple like a hidden set_config() which the cleaning process set, or we could write a simple cli which takes a timestamp and sets this in the db so the interface between the refresh and the instance is loosely coupled.

Bugs in account menu env jump links

Appears to be 2 bugs:

image

  • it looks like the logic might be running twice and so creating double the number of identical env bar items
  • there are also empty env items

Add a class to the body when enabled

Would be good to have a class put into the body classes so if any theme modifications are needed, then can easily target the element with css.

e.g. a site already has a fixed navigation when the page scrolls (bootstrap affix). Since the Envbar is fixed also, then this sits over or under any other fixed menu bar, depending on what the z-index is. If there was a body class to indicate that the envbar was enabled, then a theme could cater for this.

SCRIPT_FILENAME does not match symlinked $CFG->dirroot

To prevent duplication of the envbar we have a check

if ($_SERVER['SCRIPT_FILENAME'] === $CFG->dirroot.'/admin/settings.php')

The script filename will not match the string we are comparing against.

link: /var/www/sites/moodle/current
target: /var/www/sites/moodle/releases/release_52

The duplication can also happen when viewing /admin/search.php so we will add another check for that file.

Environment quick swap menu

  • after detecting what environment we are in, render in the header a dropdown to quickly link to the same url in the other environments. NOTE: this means we must know the wwwroot of the other env's and not simple a regex, probably deprecate the regex completely??
  • this is potentially useful for admin type people who constantly swap between env's. So lets have a way to selectively turn it on in production too for just these people. Obvious choice would be a new capability? But even then maybe make it opt in somehow, perhaps if you go to the envbar config page you can an extra option to opt in. If the envbar is ever shown to you in prod, have an opt out button in the envbar. Maybe in the usermenu top right??
  • #21 will warn, should we just let it? it's nice confirmation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.