From 3d4f9f2c280f9d85722951fa5850ca00a7e80aac Mon Sep 17 00:00:00 2001 From: hellekin Date: Thu, 29 Oct 2020 22:40:35 +0100 Subject: REUSE: Add AGPL-3.0-or-later to app/* --- app/controllers/agents_controller.rb | 91 +++++++++++++++++++++++++++++++ app/controllers/application_controller.rb | 6 +- app/controllers/categories_controller.rb | 23 ++++++++ app/controllers/my/agent_controller.rb | 4 ++ app/controllers/resources_controller.rb | 4 ++ app/controllers/users_controller.rb | 4 ++ app/controllers/welcome_controller.rb | 4 ++ 7 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 app/controllers/agents_controller.rb create mode 100644 app/controllers/categories_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb new file mode 100644 index 0000000..105e443 --- /dev/null +++ b/app/controllers/agents_controller.rb @@ -0,0 +1,91 @@ +# SPDX-FileCopyrightText: 2020 IN COMMON Collective +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +class AgentsController < ApplicationController + before_action :set_agent, only: [:new, :show, :edit, :update, :delete, :destroy] + + # GET /agents + def index + @agents = Agent.order(:name).page params[:page] + end + + # GET /agents/new + def new + end + + # POST /agents + def create + flash.now[:alert] = 'Agents are created from actual groups for now...' + render :new + end + + # GET /agents/:id + def show + end + + # GET /agents/:id/edit + def edit + flash.now[:notice] = 'Please ask a maintainer to edit this resource!' unless current_user_maintainer? + end + + # PATCH /agents/:id + def update + # Check list: + # 1. Compare records for changes + # 2. Validate each change + # 3. Moderate queue or save + + return 403 unless current_user_maintainer? + + respond_to do |format| + if @agent.update(agent_params) + format.html { redirect_to @agent, notice: 'Merci de votre contribution !' } + format.json { render :show, status: :ok, location: @agent } + else + format.html { render :edit } + format.json { render json: @agent.errors, status: :unprocessable_entity } + end + end + end + + # GET /agents/:id/delete + def delete + flash.now[:notice] = 'Please ask a maintainer to delete your Agent!' unless current_user_maintainer? + end + + # DELETE /agents/:id + def destroy + return 403 # Yeah, right? + # Check list + # 1. User belongs to Agent and is :maintainer? + if !(current_user_maintainer? && current_user_leader?) + msg = 'You must be a maintainer and a leader to delete your Agent!' + respond_to do |format| + format.html { redirect_to :show, notice: msg } + format.json { render json: '{}', status: :forbidden, message: msg } + end + else + @agent.destroy + respond_to do |format| + format.html { redirect_to :index, notice: 'OK, resource Agent successfully removed.' } + format.json { head :no_content } + end + end + end + + private + + def agent_params + params + .require(:agent) + .permit(:uuid, + :name, + :summary, + :description) + end + + def set_agent + @agent = Agent.find_by(uuid: params[:id]) || Agent.new + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 14f50bf..5299f54 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,8 @@ -class ApplicationController < ActionController::Base - protect_from_forgery with: :null_session +# SPDX-FileCopyrightText: 2020 IN COMMON Collective +# +# SPDX-License-Identifier: AGPL-3.0-or-later +class ApplicationController < ActionController::Base require 'sso' before_action :current_user diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000..40f1ff5 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2020 IN COMMON Collective +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +class CategoriesController < ApplicationController + before_action :set_category, only: [:new, :show, :edit, :update, :delete, :destroy] + + def index + end + + def show + @category = Category.find(params[:id]) + end + + def edit + end + + private + + def set_category + @category = Category.find_by(id: params[:id]) || Category.new + end +end diff --git a/app/controllers/my/agent_controller.rb b/app/controllers/my/agent_controller.rb index ac761b7..6da2642 100644 --- a/app/controllers/my/agent_controller.rb +++ b/app/controllers/my/agent_controller.rb @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2020 IN COMMON Collective +# +# SPDX-License-Identifier: AGPL-3.0-or-later + class My::AgentController < ApplicationController # PATCH /my/current_agent def switch diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index 04d4e70..52d89ea 100644 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2020 IN COMMON Collective +# +# SPDX-License-Identifier: AGPL-3.0-or-later + class ResourcesController < ApplicationController before_action :set_resource, only: [:new, :show, :edit, :update, :delete, :destroy] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2cfa2ab..9a3cf74 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2020 IN COMMON Collective +# +# SPDX-License-Identifier: AGPL-3.0-or-later + class UsersController < ApplicationController # GET /my/users # If you're a leader, you will see a list of Agent members diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 0c41e5a..cafddd1 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2020 IN COMMON Collective +# +# SPDX-License-Identifier: AGPL-3.0-or-later + class WelcomeController < ApplicationController # GET / def index -- cgit v1.2.3