Add links plugin

This can be used to link to external services related to the foodcoop.
With the indirect mode it is possible to implement a secure login to other
services. In that case Foodsoft will send a HTTP GET request and redirect
the user to the returned Location header. This allows the generation of
a one-time login URL.
A typical use-case would be that a workgroup, which is responsible for
the email account, does not need to share the login credentials and can
use a link within the Foodsoft instead.
This commit is contained in:
Patrick Gansterer 2020-07-29 11:19:20 +02:00
parent e16f03eebf
commit 7657b05787
16 changed files with 211 additions and 0 deletions

View file

@ -0,0 +1 @@
require 'foodsoft_links/engine'

View file

@ -0,0 +1,27 @@
module FoodsoftLinks
class Engine < ::Rails::Engine
def navigation(primary, context)
primary.item :links, I18n.t('navigation.links'), '#', if: Proc.new { visble_links(context).any? } do |subnav|
visble_links(context).each do |link|
subnav.item link.id, link.name, context.link_path(link)
end
end
# move to left before admin item
if i = primary.items.index(primary[:admin])
primary.items.insert(i, primary.items.delete_at(-1))
end
end
def visble_links(context)
ret = Link.ordered
current_user = context.current_user
unless current_user.role_admin?
workgroups = current_user.workgroups.map(&:id)
ret = ret.where(workgroup: [nil] + workgroups)
end
ret
end
end
end

View file

@ -0,0 +1,3 @@
module FoodsoftLinks
VERSION = "0.0.1"
end