Skip to content

v3.17.0 #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ GEM
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0225)
mimemagic (0.3.5)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_mime (1.0.2)
mini_portile2 (2.5.0)
minitest (5.14.4)
Expand Down Expand Up @@ -291,7 +293,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.4)
rexml (3.2.5)
rollbar (2.22.1)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
Expand Down
2 changes: 2 additions & 0 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
filter :email
filter :username
filter :phone
filter :postcode

form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs do
f.input :username
f.input :email
f.input :phone
f.input :postcode
f.input :gender, as: :select, collection: User::GENDERS
f.input :identity_document
end
Expand Down
6 changes: 5 additions & 1 deletion app/assets/javascripts/application/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ $(function() {
loadTags('inquiry');
});

$(".switch_member-js").on("click", function() {
loadTags('user');
});

function loadTags(type){
$.get({
url: `/tags/alpha_grouped_index.js?post_type=${type}`,
Expand All @@ -28,7 +32,7 @@ $(function() {
ajax: {
url: '/tags.json',
data: function(params) {
return { term: params.term };
return { term: params.term, model: $(this).data("model") };
},
processResults: function(data, params) {
// parse the data into the format expected by Select2
Expand Down
7 changes: 7 additions & 0 deletions app/assets/stylesheets/application/member-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
}
}

&__tags {
a {
margin-left: 4px;
color: white;
}
}

&__activity {
font-size: 14px;
color: #78adb9;
Expand Down
23 changes: 13 additions & 10 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@ class TagsController < ApplicationController
before_action :authenticate_user!, :member_should_be_active

def index
posts = Post.by_organization(current_organization)
@all_tags = posts.find_like_tag(params[:term])
model = params[:model].classify.constantize
posts = model.by_organization(current_organization)
@tags = posts.find_like_tag(params[:term])

render json: @all_tags
render json: @tags
end

def alpha_grouped_index
redirect_to users_path && return unless current_organization

post_type = params[:post_type] || "offer"
@alpha_tags = case post_type
when "offer" then Offer
when "inquiry" then Inquiry
end.by_organization(current_organization).
active.of_active_members.
alphabetical_grouped_tags
@tags = case post_type
when "offer"
Offer.by_organization(current_organization).active.of_active_members
when "inquiry"
Inquiry.by_organization(current_organization).active.of_active_members
when "user"
Member.by_organization(current_organization).active
end.alphabetical_grouped_tags

respond_to do |format|
format.html
format.js do
render partial: "grouped_index", locals: { alpha_tags: @alpha_tags, post_type: post_type }
render partial: "grouped_index", locals: { alpha_tags: @tags, post_type: post_type }
end
end
end
Expand Down
14 changes: 12 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
class UsersController < ApplicationController
before_action :authenticate_user!, :member_should_be_active

has_scope :tagged_with, as: :tag

def index
search_and_load_members current_organization.members.active, { s: 'user_last_sign_in_at DESC' }
members = current_organization.members.active
members = apply_scopes(members)

search_and_load_members members, { s: 'user_last_sign_in_at DESC' }
end

def manage
Expand Down Expand Up @@ -37,9 +42,12 @@ def create

if @user.persisted?
@user.tune_after_persisted(current_organization)
@user.add_tags(current_organization, params[:tag_list] || [])

redirect_to_after_create
else
@user.email = "" if empty_email

render action: "new"
end
end
Expand All @@ -49,6 +57,8 @@ def update
authorize @user

if @user.update(user_params)
@user.add_tags(current_organization, params[:tag_list] || [])

redirect_to @user
else
render action: :edit, status: :unprocessable_entity
Expand Down Expand Up @@ -76,7 +86,7 @@ def scoped_users

def user_params
fields_to_permit = %w"gender username email date_of_birth phone
alt_phone active description notifications push_notifications"
alt_phone active description notifications push_notifications postcode"
fields_to_permit += %w"admin registration_number
registration_date" if admin?
fields_to_permit += %w"organization_id superadmin" if superadmin?
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/member_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MemberDecorator < ViewModel
delegate :user, :member_uid, :active?, to: :object
delegate :user, :member_uid, :tags, :active?, to: :object
delegate :phone, :alt_phone, :username, :description, :last_sign_in_at, to: :user

def manager?
Expand Down
10 changes: 0 additions & 10 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ def update_balance
save
end

# Return the maximum allowed amount of time that the acccount is able to
# spend without overflowing
def allowance
if min_allowed_balance
[0, balance - min_allowed_balance].min
else
Float::INFINITY
end
end

# Print the account as its accountable reference
def to_s
accountable.to_s
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Taggable
extend ActiveSupport::Concern

included do
scope :tagged_with, ->(tag) { where("? = ANY (tags)", tag) }
scope :tagged_with, ->(tag) { where("? = ANY (#{table_name}.tags)", tag) }
end

def tag_list
Expand Down
15 changes: 15 additions & 0 deletions app/models/member.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
class Member < ApplicationRecord
include Taggable

# Cast the member_uid integer to a string to allow pg ILIKE search (from Ransack *_contains)
ransacker :member_uid_search do
Arel.sql("member_uid::text")
end
# Convert array of tags to string
ransacker :member_tags do
Arel.sql("array_to_string(tags, ',')")
end
ransack_alias :member_search, %w(
user_username
user_email
user_phone
user_alt_phone
member_uid_search
member_tags
).join("_or_")

belongs_to :user
belongs_to :organization
Expand All @@ -15,6 +29,7 @@ class Member < ApplicationRecord

scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) }
scope :active, -> { where active: true }
scope :by_organization, ->(org) { where(organization_id: org) if org }

validates :organization_id, presence: true
validates :member_uid,
Expand Down
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def tune_after_persisted(organization)
save
end

def add_tags(organization, tag_list)
member = as_member_of(organization)
member.update(tag_list: tag_list)
end

def has_valid_email?
!email.include? "example.com"
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_post_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
f.object.tags || [],
{ selected: f.object.tags },
multiple: true,
data: { placeholder: t('application.tips.entertag') },
data: { placeholder: t("application.tips.entertag"), model: "post" },
id: "tags-js",
class: "form-control" %>
</div>
Expand Down
38 changes: 20 additions & 18 deletions app/views/tags/alpha_grouped_index.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<h1>
<%= t '.maintitle' %>
<%= form_tag alpha_grouped_index_tags_path, method: :get do %>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active switch_offer-js">
<%= radio_button_tag 'switch_offer', 'offer', true %>
<%= Offer.model_name.human count: :many %>
</label>
<label class="btn btn-primary switch_inquiry-js">
<%= radio_button_tag 'switch_inquiry', 'inquiry' %>
<%= Inquiry.model_name.human count: :many %>
</label>
</div>
<% end %>
</h1>
<h1><%= t '.maintitle' %></h1>

<%= form_tag alpha_grouped_index_tags_path, method: :get do %>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active switch_offer-js">
<%= radio_button_tag 'switch_offer', 'offer', true %>
<%= Offer.model_name.human count: :many %>
</label>
<label class="btn btn-primary switch_inquiry-js">
<%= radio_button_tag 'switch_inquiry', 'inquiry' %>
<%= Inquiry.model_name.human count: :many %>
</label>
<label class="btn btn-primary switch_member-js">
<%= radio_button_tag 'switch_member', 'user' %>
<%= t "users.index.members" %>
</label>
</div>
<% end %>

<div class="alpha_tag_list col-xs-12 col-md-12">
<%= render 'grouped_index',
alpha_tags: @alpha_tags,
post_type: params[:post_type] || 'offer' %>
<%= render 'grouped_index', alpha_tags: @tags, post_type: params[:post_type] || 'offer' %>
</div>
10 changes: 10 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
end_year: Date.today.year - 12,
include_blank: :true %>
<%= f.input :description, as: "text" %>
<%= f.input :postcode %>
<%= label_tag :tag_list, t('activerecord.attributes.post.tag_list') %>
<div class='form-group'>
<%= select_tag :tag_list,
options_for_select(member.tags, member.tags),
multiple: true,
data: { placeholder: t("application.tips.entertag"), model: "member" },
id: "tags-js",
class: "form-control" %>
</div>

<div class='form-group'>
<label><%= t('.notifications') %></label>
Expand Down
11 changes: 11 additions & 0 deletions app/views/users/_member_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
<% else %>
<%= t('.no_activity') %>
<% end %>
<% member.tags[0..2].each do |tag| %>
<span class="to-member-card__header__text__tags">
<%= link_to users_path tag: tag do %>
<%= glyph :tag %>
<%= tag&.truncate(29) %>
<% end %>
</span>
<% end %>
<% if member.tags.size > 3 %>
...
<% end %>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<small><%= t ".edit_user" %></small>
</h1>

<%= render "form" %>
<%= render "form", member: @user.as_member_of(current_organization) %>
2 changes: 1 addition & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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 :user_username_or_user_email_or_member_uid_search_contains, class: "form-control" %>
<%= f.search_field :member_search_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 @@ -14,7 +14,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 :user_username_or_user_email_or_user_phone_or_user_alt_phone_or_member_uid_search_contains, class: "form-control" %>
<%= f.search_field :member_search_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/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>
<%= t ".new_user" %>
</h1>
<%= render "form" %>
<%= render "form", member: Member.new %>
23 changes: 23 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@
<% end %>
</dd>
<% end %>
<% if @user.postcode.present? %>
<dt>
<%= t "activerecord.attributes.user.postcode" %>
</dt>
<dd>
<%= @user.postcode %>
</dd>
<% end %>
<% if @member.tags.present? %>
<dt>
<%= t "application.navbar.tags" %>
</dt>
<dd>
<% @member.tags.each do |tag| %>
<span class="badge alert-success">
<%= link_to users_path tag: tag do %>
<%= glyph(:tag) %>
<%= tag %>
<% end %>
</span>
<% end %>
</dd>
<% end %>
</dl>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ ca:
notifications: Rebre notificacions
organization: Organització
phone: Telèfon
postcode: Codi postal
push_notifications: Rebre notificacions al mòbil
registration_date: Data d'alta
registration_number: Codi d'usuari
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ en:
notifications: Receive email notifications
organization: Organization
phone: Phone
postcode: Postal code
push_notifications: Receive mobile notifications
registration_date: Registration date
registration_number: User code
Expand Down
Loading