Skip to content

Commit

Permalink
Allow upgrading to specific branch via front-end
Browse files Browse the repository at this point in the history
  • Loading branch information
stijn-uva committed Oct 10, 2023
1 parent d431471 commit 697cd2b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
9 changes: 8 additions & 1 deletion backend/workers/restart_4cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ def work(self):
log_file_backend.unlink()

if self.job.data["remote_id"] == "upgrade":
command = sys.executable + " helper-scripts/migrate.py --release --repository %s --yes --restart --output %s" % \
command = sys.executable + " helper-scripts/migrate.py --repository %s --yes --restart --output %s" % \
(shlex.quote(config.get("4cat.github_url")), shlex.quote(str(log_file_backend)))
if self.job.details and self.job.details.get("branch"):
# migrate to code in specific branch
command += f" --branch {self.job.details['branch']}"
else:
# migrate to latest release
command += " --release"

else:
command = sys.executable + " 4cat-daemon.py --no-version-check force-restart"

Expand Down
11 changes: 11 additions & 0 deletions common/lib/config_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@
"help": "Can restart/upgrade",
"tooltip": "Controls whether users can restart and upgrade 4CAT via the Control Panel"
},
"privileges.can_upgrade_to_dev": {
# this is NOT an admin privilege, because all admins automatically
# get all admin privileges! users still need the above privilege
# to actually use this, anyway
"type": UserInput.OPTION_TOGGLE,
"default": False,
"help": "Can upgrade to development branch",
"tooltip": "Controls whether users can upgrade 4CAT to a development branch of the code via the Control Panel. "
"This is an easy way to break 4CAT so it is recommended to not enable this unless you're really "
"sure of what you're doing."
},
"privileges.admin.can_manage_tags": {
"type": UserInput.OPTION_TOGGLE,
"default": False,
Expand Down
20 changes: 19 additions & 1 deletion webtool/templates/controlpanel/restart.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,30 @@ <h2><span>Restart/Upgrade 4CAT</span></h2>
</button></li>

{% if can_upgrade %}
<li><button name="action" value="upgrade"{% if in_progress %} disabled="disabled"{% endif %}>
<li><button name="action" class="confirm-first" value="upgrade"{% if in_progress %} disabled="disabled"{% endif %}>
<i class="fa fa-wrench" aria-hidden="true"></i> Upgrade (danger!)
</button></li>
{% endif %}
</ul>
</form>
{% if __user_config("privileges.can_upgrade_to_dev") %}
<hr>
<form action="{{ url_for("trigger_restart") }}" method="POST">
<p>You can also upgrade to a development branch of the <a href="{{ __user_config("4cat.github_url") }}">
configured GitHub repository</a>. This way you can for example use new or experimental features
before they are officially released.</p>
<p><strong>WARNING:</strong> it is <em>very</em> easy to break your 4CAT by upgrading to a development
branch. Only use this if you know what you're doing. Don't say we didn't warn you! </p>
<div class="form-element">
<label for="update-branch">Branch</label>
<input type="text" name="branch" id="update-branch" value="master">
</div>

<div class="submit-container">
<button class="confirm-first" name="action" value="upgrade-branch"><i class="fa fa-explosion"></i> Update to branch</button>
</div>
</form>
{% endif %}
</section>

<section>
Expand Down
3 changes: 2 additions & 1 deletion webtool/views/views_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def trigger_restart():
shutil.copy(current_version_file, frontend_version_file)

# from here on, the back-end takes over
queue.add_job("restart-4cat", {}, mode)
details = {} if not request.form.get("branch") else {"branch": request.form["branch"]}
queue.add_job("restart-4cat", details, mode)
flash("%s initiated. Check process log for progress." % mode.title())

return render_template("controlpanel/restart.html", flashes=get_flashed_messages(), in_progress=lock_file.exists(),
Expand Down

0 comments on commit 697cd2b

Please sign in to comment.