diff --git a/Gemfile b/Gemfile index d58616d34..386447c98 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,7 @@ gem 'sidekiq', '~> 6.5' gem 'sidekiq-cron', '~> 1.9.1' gem 'aws-sdk-s3', '~> 1.94', require: false gem 'image_processing', '~> 1.12' +gem 'active_storage_validations', '~> 1.1.3' # Assets gem 'jquery-rails', '~> 4.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index 7792343b2..2fb288110 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,6 +39,11 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) + active_storage_validations (1.1.3) + activejob (>= 5.2.0) + activemodel (>= 5.2.0) + activestorage (>= 5.2.0) + activesupport (>= 5.2.0) activeadmin (2.9.0) arbre (~> 1.2, >= 1.2.1) formtastic (>= 3.1, < 5.0) @@ -447,6 +452,7 @@ PLATFORMS ruby DEPENDENCIES + active_storage_validations (~> 1.1.3) activeadmin (~> 2.9.0) aws-sdk-s3 (~> 1.94) bootsnap (~> 1.12.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1a7f0d1ab..a8823c0c8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,10 +6,10 @@ class ApplicationController < ActionController::Base MissingTOSAcceptance = Class.new(Exception) OutadedTOSAcceptance = Class.new(Exception) - append_before_action :check_for_terms_acceptance!, unless: :devise_controller? + before_action :set_locale + before_action :check_for_terms_acceptance!, unless: :devise_controller? before_action :configure_permitted_parameters, if: :devise_controller? - before_action :set_locale, - :set_current_organization, + before_action :set_current_organization, :store_user_location rescue_from MissingTOSAcceptance, OutadedTOSAcceptance do diff --git a/app/controllers/petitions_controller.rb b/app/controllers/petitions_controller.rb index 005c29b0c..8dc4d432b 100644 --- a/app/controllers/petitions_controller.rb +++ b/app/controllers/petitions_controller.rb @@ -3,6 +3,7 @@ class PetitionsController < ApplicationController def create petition = Petition.new petition_params + petition.status = "pending" if petition.save OrganizationNotifier.new_petition(petition).deliver_now @@ -13,7 +14,7 @@ def create flash[:error] = t('errors.internal_server_error.description') end - redirect_to organizations_path + redirect_back fallback_location: organization_path(petition.organization) end def update @@ -38,6 +39,6 @@ def manage private def petition_params - params.permit(%i[organization_id user_id status]) + params.permit(%i[organization_id user_id]) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 30d02375d..5fe37cdd8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -27,7 +27,7 @@ def gravatar_url(user, size = 32) def organization_logo org = @organization || @current_organization - return unless org && org.logo.attached? + return unless org && org.logo.attached? && org.errors.details[:logo].blank? return if "#{controller_name}##{action_name}".in? %w(organizations#index pages#show) content_tag(:div, class: "row organization-logo") do diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb index 70f1c0aba..4dba82ec7 100644 --- a/app/models/concerns/taggable.rb +++ b/app/models/concerns/taggable.rb @@ -42,7 +42,8 @@ def tag_cloud end def find_like_tag(pattern) - all_tags.uniq.select { |t| t =~ /#{pattern}/i } + transliterated_pattern = pattern.present? ? ActiveSupport::Inflector.transliterate(pattern) : "" + all_tags.uniq.select { |t| ActiveSupport::Inflector.transliterate(t) =~ /#{transliterated_pattern}/i } end # Builds a hash where the keys are the capital letters of the tags and the diff --git a/app/models/organization.rb b/app/models/organization.rb index 559f34a8a..cec867101 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -27,6 +27,9 @@ class Organization < ApplicationRecord validates :name, presence: true, uniqueness: true + LOGO_CONTENT_TYPES = %w(image/jpeg image/png image/gif) + validates :logo, content_type: LOGO_CONTENT_TYPES + before_validation :ensure_url after_create :create_account diff --git a/app/views/organizations/_form.html.erb b/app/views/organizations/_form.html.erb index d87e41885..4405fa831 100644 --- a/app/views/organizations/_form.html.erb +++ b/app/views/organizations/_form.html.erb @@ -9,6 +9,6 @@ <%= f.input :address %> <%= f.input :neighborhood %> <%= f.input :city %> - <%= f.input :logo %> + <%= f.input :logo, input_html: { accept: Organization::LOGO_CONTENT_TYPES.join(',') } %> <%= f.button :submit %> <% end %> diff --git a/app/views/organizations/_organizations_row.html.erb b/app/views/organizations/_organizations_row.html.erb index 3b589b013..f68caa55f 100644 --- a/app/views/organizations/_organizations_row.html.erb +++ b/app/views/organizations/_organizations_row.html.erb @@ -5,23 +5,6 @@ <%= link_to(org.web, org.web) if org.web.present? %> <%= org.members.count %> - <% if current_user %> - <% petition = current_user.petitions.where(organization_id: org.id).last %> - - <% if member = Member.where(user: current_user, organization: org).first %> - <%= link_to t('users.user_rows.delete_membership'), - member, - method: :delete, - data: { confirm: t('users.user_rows.sure_delete', organization_name: org.name) }, - class: 'btn btn-danger' %> - <% elsif petition && !current_user.was_member?(petition) %> - <%= petition.status %> - <% else %> - <%= link_to t('petitions.apply'), - petitions_path(user_id: current_user.id, organization_id: org.id, status: 'pending'), - method: :post, - class: 'btn btn-default' %> - <% end %> - <% end %> + <%= render "organizations/petition_button", organization: org %> diff --git a/app/views/organizations/_petition_button.html.erb b/app/views/organizations/_petition_button.html.erb new file mode 100644 index 000000000..12e42d459 --- /dev/null +++ b/app/views/organizations/_petition_button.html.erb @@ -0,0 +1,18 @@ +<% if current_user %> + <% petition = current_user.petitions.where(organization_id: organization.id).last %> + + <% if member = Member.where(user: current_user, organization: organization).first %> + <%= link_to t('users.user_rows.delete_membership'), + member, + method: :delete, + data: { confirm: t('users.user_rows.sure_delete', organization_name: organization.name) }, + class: 'btn btn-danger' %> + <% elsif petition && !current_user.was_member?(petition) %> + <%= petition.status %> + <% else %> + <%= link_to t('petitions.apply'), + petitions_path(user_id: current_user.id, organization_id: organization.id), + method: :post, + class: 'btn btn-default' %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/organizations/show.html.erb b/app/views/organizations/show.html.erb index 7247ea8c7..8153bea7d 100644 --- a/app/views/organizations/show.html.erb +++ b/app/views/organizations/show.html.erb @@ -84,7 +84,7 @@
+ <%= render "organizations/petition_button", organization: @organization %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 47b7322e7..bf73c674f 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -11,7 +11,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
- <%= f.search_field :member_search_cont, value: params.dig(:q, :member_search_cont), class: "form-control" %> + <%= f.search_field :member_search_unaccent_cont, value: params.dig(:q, :member_search_unaccent_cont), class: "form-control" %>