aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2021-02-11 20:40:00 +0100
committerhellekin <hellekin@cepheide.org>2021-02-11 20:40:00 +0100
commite5619547d5544a043dfec173f17020b09f882a98 (patch)
treed6b127a0ea3b71d139531cfc25e2e68f558325f0 /app
parent7f65f49b5036e4318b91dfc1ecd3ca21bc8ba74a (diff)
downloadincommon-map-e5619547d5544a043dfec173f17020b09f882a98.tar.gz
[FIX] Availability of agents
Diffstat (limited to 'app')
-rw-r--r--app/controllers/agents_controller.rb10
-rw-r--r--app/controllers/resources_controller.rb12
-rw-r--r--app/controllers/welcome_controller.rb21
-rw-r--r--app/helpers/application_helper.rb8
-rw-r--r--app/helpers/users_helper.rb2
-rw-r--r--app/javascript/scss/_agents.scss7
-rw-r--r--app/models/resource.rb4
-rw-r--r--app/models/user.rb3
-rw-r--r--app/views/agents/_agent.html.erb17
-rw-r--r--app/views/application/_user_info.html.erb4
-rw-r--r--app/views/layouts/application.html.erb2
-rw-r--r--app/views/taxonomies/_taxonomy.html.erb2
-rw-r--r--app/views/taxonomies/index.html.erb2
-rw-r--r--app/views/taxonomies/show.html.erb13
14 files changed, 82 insertions, 25 deletions
diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb
index 105e443..fcbaebe 100644
--- a/app/controllers/agents_controller.rb
+++ b/app/controllers/agents_controller.rb
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
class AgentsController < ApplicationController
- before_action :set_agent, only: [:new, :show, :edit, :update, :delete, :destroy]
+ before_action :set_agent, only: [:new, :show, :edit, :update, :delete, :destroy]
# GET /agents
def index
@@ -26,7 +26,7 @@ class AgentsController < ApplicationController
# GET /agents/:id/edit
def edit
- flash.now[:notice] = 'Please ask a maintainer to edit this resource!' unless current_user_maintainer?
+ flash.now[:notice] = 'Please ask a maintainer to edit this resource!' unless current_agent == @agent
end
# PATCH /agents/:id
@@ -36,7 +36,7 @@ class AgentsController < ApplicationController
# 2. Validate each change
# 3. Moderate queue or save
- return 403 unless current_user_maintainer?
+ return 403 unless current_agent == @agent
respond_to do |format|
if @agent.update(agent_params)
@@ -51,7 +51,7 @@ class AgentsController < ApplicationController
# GET /agents/:id/delete
def delete
- flash.now[:notice] = 'Please ask a maintainer to delete your Agent!' unless current_user_maintainer?
+ flash.now[:notice] = 'Please ask a maintainer to delete your Agent!' unless current_agent == @agent
end
# DELETE /agents/:id
@@ -59,7 +59,7 @@ class AgentsController < ApplicationController
return 403 # Yeah, right?
# Check list
# 1. User belongs to Agent and is :maintainer?
- if !(current_user_maintainer? && current_user_leader?)
+ unless current_agent == @agent
msg = 'You must be a maintainer and a leader to delete your Agent!'
respond_to do |format|
format.html { redirect_to :show, notice: msg }
diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb
index 52d89ea..2fa392f 100644
--- a/app/controllers/resources_controller.rb
+++ b/app/controllers/resources_controller.rb
@@ -18,13 +18,15 @@ class ResourcesController < ApplicationController
def create
# TODO Background job to list similar items
# TODO If there's a match, return to user with new record or list of mergeable ones
- return 403 unless (current_user_editor? || current_user_observer?)
classification = resource_params.delete(:classification) || { section_ids: [] }
+ Rails.logger.info resource_params
+
@resource = current_agent.resources.build(resource_params)
respond_to do |format|
+ Rails.logger.info "format: #{format} - Res: #{@resource.inspect}"
if @resource.save
classification[:section_ids].each { |id| @resource.classifications.find_or_create_by(section_id: id) }
format.html { redirect_to @resource, notice: 'Merci de votre contribution !' }
@@ -43,8 +45,7 @@ class ResourcesController < ApplicationController
# GET /resources/:id/edit
def edit
# TODO Add a moderation queue for unauthorized but valid changes
- flash.now[:notice] = 'Please ask an editor or a maintainer to edit this resource!' unless (current_user_editor? || current_user_maintainer?)
-
+ flash.now[:notice] = 'Please ask an editor or a maintainer to edit this resource!' unless @resource.agent == current_agent
Rails.logger.info "EDIT: #{@resource.uuid} #{@resource.name} // #{current_agent.id}"
end
@@ -56,7 +57,8 @@ class ResourcesController < ApplicationController
# 2. Validate each change
# 3. Moderate queue or save
- return 403 unless (current_user_editor? || current_user_maintainer?)
+ # TODO: pass this to current_agent and version resource
+ return 403 unless current_agent == @resource.agent
respond_to do |format|
if @resource.update(resource_params)
@@ -78,7 +80,7 @@ class ResourcesController < ApplicationController
def destroy
# Check list
# 1. User belongs to Agent and is :maintainer?
- if !current_user_maintainer?
+ if @resource.agent != current_agent
msg = 'You must be a maintainer to delete resources!'
respond_to do |format|
format.html { redirect_to :show, notice: msg }
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
index 5fce0cf..ad9cd95 100644
--- a/app/controllers/welcome_controller.rb
+++ b/app/controllers/welcome_controller.rb
@@ -102,20 +102,27 @@ class WelcomeController < ApplicationController
# Set @current_user to existing or new User record from SSO user info
def find_or_create_current_user
- @current_user = User.find_by(external_id: @sso.user_info[:external_id]) ||
+ user_data = {
+ external_id: @sso.user_info[:external_id],
+ avatar_url: @sso.user_info[:avatar_url],
+ email: @sso.user_info[:email],
+ name: @sso.user_info[:name],
+ username: @sso.user_info[:username]
+ }
+
+ @current_user = User.find_by(external_id: user_data[:external_id]) ||
begin
Rails.logger.info('new user...')
- u = User.create(
- external_id: @sso.user_info[:external_id],
- avatar_url: @sso.user_info[:avatar_url],
- email: @sso.user_info[:email],
- name: @sso.user_info[:name],
- username: @sso.user_info[:username])
+ u = User.create(user_data)
Rails.logger.info('created user %s' % u.inspect)
u
rescue Exception => e
Rails.logger.warning("#{e.type}: #{e.message}")
end
+
+ user_data.reverse_merge!(@current_user.attributes.symbolize_keys)
+ @current_user.update(user_data) if user_data != @current_user.attributes
+ @current_user
end
# Update user agents
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d80e4fe..c3c9b12 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -3,6 +3,14 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
module ApplicationHelper
+ # Set CSS classes on body tag
+ def body_classes(*args)
+ classes = args || []
+ classes << controller_name
+ classes << action_name
+ ' class="'.html_safe << classes.join(' ') << '"'.html_safe
+ end
+
# Markdown helper
# Always use all extensions. Additional parser and render options may be
# passed as a second argument.
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 1520238..4af2882 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -4,6 +4,6 @@
module UsersHelper
def default_user_avatar_url
- "https://talk.incommon.cc/uploads/talk_incommon_cc/optimized/1X/ae4533e882f427b1ae870080a42978c67c6437cc_2_32x32.png"
+ "https://talk.incommon.cc/uploads/default/original/1X/fb0b62dd9ad8917986ea0a901f864f04440de5f5.png"
end
end
diff --git a/app/javascript/scss/_agents.scss b/app/javascript/scss/_agents.scss
index ec9285d..951505a 100644
--- a/app/javascript/scss/_agents.scss
+++ b/app/javascript/scss/_agents.scss
@@ -7,3 +7,10 @@
// Place all the styles related to the Agents controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
+
+body.index article.agent {
+ border: 1px solid;
+ border-radius: 1rem;
+ margin: 2rem;
+ padding: 2rem;
+}
diff --git a/app/models/resource.rb b/app/models/resource.rb
index c76a9c6..c603978 100644
--- a/app/models/resource.rb
+++ b/app/models/resource.rb
@@ -12,7 +12,7 @@ class Resource < ApplicationRecord
has_many :classifications
has_many :sections, through: :classifications
- store_accessor :feature, :geometry, :properties
+ store_accessor :feature, :geometry, :properties, :meta, :version
# validates_associated :agent
@@ -77,7 +77,7 @@ class Resource < ApplicationRecord
# Add IN COMMON Resource UUID property
out['properties']['uuid'] = uuid
# Add IN COMMON Agent UUID property
- out['properties']['agent_uuid'] = agent.uuid
+ out['version'] = { agent: agent.uuid, resource: uuid, revision: 1 }
out
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 7288412..9e5c184 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -9,6 +9,7 @@ class User < ApplicationRecord
include UsersHelper
def avatar_url
- attributes[:avatar_url] || default_user_avatar_url
+ attributes[:avatar_url].present? ?
+ attributes[:avatar_url] : '' # default_user_avatar_url
end
end
diff --git a/app/views/agents/_agent.html.erb b/app/views/agents/_agent.html.erb
index 5a74df1..fda8bd0 100644
--- a/app/views/agents/_agent.html.erb
+++ b/app/views/agents/_agent.html.erb
@@ -3,13 +3,28 @@
<h1><%= link_to agent.name, agent_url(agent) %></h1>
<h2><%= link_to agent_url(agent) %></h1>
</head>
+ <% if current_agent == agent %>
+ <section class="agent-info">
+ <h3>Vous faƮtes partie de cet agent</h3>
+ <p>Ainsi que <%= pluralize(agent.members.count, 'membre') %>.</p>
+ <nav>
+ <ul>
+ <li><%= link_to 'Edit', edit_agent_url(agent) %></li>
+ </ul>
+ </nav>
+ </section>
+ <% end %>
<section id="stats">
<h3>Statistiques</h3>
<ul>
<li><%= link_to pluralize(agent.resources.count, 'Resource'), agent_resources_url(agent) %></li>
- <li><%= pluralize(agent.taxonomies.count, 'Taxonomy') %> with
+ <li><%= link_to pluralize(agent.taxonomies.count, 'Taxonomy'), agent_taxonomies_url(agent) %> with
<%= pluralize(agent.categories.count, 'Category') %> and
<%= pluralize(agent.sections.count, 'Section') %>.</li>
</ul>
</section>
</article>
+
+<% content_for :debug do %>
+<%=tag.pre agent.inspect %>
+<% end %>
diff --git a/app/views/application/_user_info.html.erb b/app/views/application/_user_info.html.erb
index 048e6fb..a1a42d2 100644
--- a/app/views/application/_user_info.html.erb
+++ b/app/views/application/_user_info.html.erb
@@ -11,3 +11,7 @@
<% end %>
</nav>
</section>
+
+<% content_for :debug do %>
+<%= @current_user.avatar_url %>
+<% end %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 60b285a..ce42bb6 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -13,7 +13,7 @@
<%= yield :head %>
</head>
- <body>
+ <body<%= body_classes %>>
<header>
<h1><%= link_to image_tag("https://talk.incommon.cc/uploads/default/original/1X/92f926e8210ea7a5412d6e2bdabfa825233e808b.png", alt: "IN COMMON", size: "x4em"), '/' %></h1>
<%= render 'application/user_info' %>
diff --git a/app/views/taxonomies/_taxonomy.html.erb b/app/views/taxonomies/_taxonomy.html.erb
index eb2dd79..79df167 100644
--- a/app/views/taxonomies/_taxonomy.html.erb
+++ b/app/views/taxonomies/_taxonomy.html.erb
@@ -1,4 +1,4 @@
-<section id="taxonomy-<%= taxonomy.to_param %>" data-controller="taxonomy" data-taxonomy-uuid="<%= taxonomy.uuid %>">
+<section class="on" id="taxonomy-<%= taxonomy.to_param %>" data-controller="taxonomy" data-taxonomy-uuid="<%= taxonomy.uuid %>">
<h3><%= taxonomy.name %></h3>
<p class="summary"><%= h taxonomy.summary %></p>
<div class="description"><%= m taxonomy.description %></div>
diff --git a/app/views/taxonomies/index.html.erb b/app/views/taxonomies/index.html.erb
index 705b0d4..fcbcb8b 100644
--- a/app/views/taxonomies/index.html.erb
+++ b/app/views/taxonomies/index.html.erb
@@ -1,5 +1,5 @@
<section id="taxonomies">
<h2>Available Taxonomies</h2>
- <%= render collection: @taxonomies %>
+ <%= render partial: :taxonomy, collection: @taxonomies %>
</section>
diff --git a/app/views/taxonomies/show.html.erb b/app/views/taxonomies/show.html.erb
index 99e9c89..3971acf 100644
--- a/app/views/taxonomies/show.html.erb
+++ b/app/views/taxonomies/show.html.erb
@@ -1 +1,14 @@
+<%#= map_container %>
+
<%= taxonomy_filter %>
+
+<% content_for :aside do %>
+ <div class="on" data-controller="taxonomy" data-taxonomy-uuid="<%= @taxonomy.to_param %>">
+ <div class="leaflet-bar leaftlet-control" id="taxonomy-toggle">
+ <button data-action="taxonomy#toggle" data-target="taxonomy.toggle"></button>
+ </div>
+ <div data-target="taxonomy.filter"></div>
+ </div>
+<% end %>
+
+