From b5739232a535f89b48b54ee52ea7d9bb59f8a46f Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 2 Feb 2021 23:13:58 +0100 Subject: 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. --- app/helpers/agents_helper.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/helpers') 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 -- cgit v1.2.3