Skip to content

Commit

Permalink
Merge pull request #721 from coopdevs/develop
Browse files Browse the repository at this point in the history
Release v4.4.0
  • Loading branch information
markets authored Dec 9, 2023
2 parents 4b88177 + 5d56ea6 commit c1eabb2
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 87 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/petitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/views/organizations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
19 changes: 1 addition & 18 deletions app/views/organizations/_organizations_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@
<td><%= link_to(org.web, org.web) if org.web.present? %></td>
<td><%= org.members.count %></td>
<td>
<% 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) %>
<span class="badge"><%= petition.status %></span>
<% 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 %>
</td>
</tr>
18 changes: 18 additions & 0 deletions app/views/organizations/_petition_button.html.erb
Original file line number Diff line number Diff line change
@@ -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) %>
<span class="badge"><%= petition.status %></span>
<% 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 %>
3 changes: 2 additions & 1 deletion app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</div>
<div class="col-sm-5">
<ul class="nav nav-pills pull-right">
<% if admin? %>
<% if current_user&.manages?(@organization) %>
<li>
<%= link_to edit_organization_path(@organization) do %>
<%= glyph :pencil %>
Expand All @@ -101,6 +101,7 @@
</li>
<% end %>
</ul>
<%= render "organizations/petition_button", organization: @organization %>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="col-md-12">
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
<div class="form-group">
<%= 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" %>
</div>
<button class="btn btn-default" type="submit">
<%= t 'global.search' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/manage.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="col-md-12">
<%= search_form_for(@search, class: "navbar-form navbar-left", url: manage_users_path) do |f| %>
<div class="form-group">
<%= 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" %>
</div>
<button class="btn btn-default" type="submit">
<%= t 'global.search' %>
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/ransack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Ransack.configure do |config|
config.add_predicate 'unaccent_cont',
arel_predicate: 'matches',
formatter: proc { |s| ActiveSupport::Inflector.transliterate("%#{s}%") },
validator: proc { |s| s.present? },
compounds: true,
type: :string
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNotNullConstraintToMemberUidInMembers < ActiveRecord::Migration[6.1]
def change
change_column_null :members, :member_uid, false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUniqueIndexOnMemberUidInMembers < ActiveRecord::Migration[6.1]
def change
add_index :members, [:organization_id, :member_uid], unique: true
end
end
Loading

0 comments on commit c1eabb2

Please sign in to comment.