aboutsummaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2021-02-02 23:13:58 +0100
committerhellekin <hellekin@cepheide.org>2021-02-02 23:13:58 +0100
commitb5739232a535f89b48b54ee52ea7d9bb59f8a46f (patch)
tree189ce7ebf48371b29def0fddc7c2e41e7cfa38bd /app/helpers
parent8e404c4f3cf7880681b6f4cdf3c378e084ad54d2 (diff)
downloadincommon-map-b5739232a535f89b48b54ee52ea7d9bb59f8a46f.tar.gz
Introduce an Anonymous Agent
Since we moved away from Roles it's important to maintain a default Agent that is distinct from the previous default IN COMMON Agent. Previously, a user without a proper group would be granted the `observer` role in the default Agent, enough to create new resources. Now, we consider anonymous users to be part of the Anonymous Agent, which also brings the possibility for them to edit yet to be accepted Resources.
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/agents_helper.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/helpers/agents_helper.rb b/app/helpers/agents_helper.rb
index bbaeeca..3ecfd73 100644
--- a/app/helpers/agents_helper.rb
+++ b/app/helpers/agents_helper.rb
@@ -3,4 +3,24 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
module AgentsHelper
+ DEFAULT_AGENT_UUID = "154cd5a4-3341-4c5f-8dd3-805c976c2a26".freeze
+ DEFAULT_AGENT_NAME = 'Anonymous'.freeze
+
+ protected
+
+ # Return the name of the current agent from context
+ def current_agent_name
+ session[:current_agent] || current_user.presence&.agents&.first&.name || default_agent_name
+ end
+
+ # Default Agent for users coming from unknown sources
+ # This agent uses a different database for writing resources
+ def default_agent
+ @default_agent ||= Agent.find_by(uuid: DEFAULT_AGENT_UUID) # Anonymous
+ end
+
+ # Return the name of the default
+ def default_agent_name
+ DEFAULT_AGENT_NAME
+ end
end