Skip to content

Commit

Permalink
Merge pull request #499 from coopdevs/develop
Browse files Browse the repository at this point in the history
Release v1.14.0
  • Loading branch information
sseerrggii authored May 16, 2019
2 parents f3e99f4 + ad9a8f0 commit 4d58da4
Show file tree
Hide file tree
Showing 70 changed files with 1,140 additions and 195 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
language: ruby
cache: bundler
bundler_args: '--without production development'
env: DATABASE_URL=postgres://postgres@localhost/timeoverflow_test
bundler_args: '--without development'
env:
global:
- DATABASE_URL=postgres://postgres@localhost/timeoverflow_test
- CC_TEST_REPORTER_ID=025bc15a0fa9afa52d86ee24fea845cf1d363f48a466bcf2cef8ab80c29acb28
before_script:
- bundle exec rake db:setup
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
# allow elasticsearch to be ready - https://docs.travis-ci.com/user/database-setup/#ElasticSearch
- sleep 10
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
services:
- elasticsearch
addons:
Expand Down
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ group :test do
gem 'faker', '~> 1.9'
gem 'capybara', '~> 3.13'
gem 'selenium-webdriver', '~> 3.141'
gem 'chromedriver-helper', '~> 2.1'
gem 'webdrivers', '~> 3.0'
gem 'simplecov', '~> 0.16.1', require: false
end

group :production do
gem 'rails_12factor', '0.0.3'
end
20 changes: 7 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ GEM
sshkit (>= 1.6.1, != 1.7.0)
arbre (1.1.1)
activesupport (>= 3.0.0)
archive-zip (0.11.0)
io-like (~> 0.3.0)
arel (6.0.4)
ast (2.4.0)
autoprefixer-rails (6.3.1)
Expand Down Expand Up @@ -96,9 +94,6 @@ GEM
xpath (~> 3.2)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
chromedriver-helper (2.1.0)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
chronic (0.10.2)
coderay (1.1.2)
coffee-rails (4.1.0)
Expand Down Expand Up @@ -175,7 +170,6 @@ GEM
has_scope (~> 0.6)
railties (>= 4.2, <= 5.2)
responders
io-like (0.3.0)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand Down Expand Up @@ -219,6 +213,7 @@ GEM
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.2)
net_http_ssl_fix (0.0.10)
netrc (0.11.0)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
Expand Down Expand Up @@ -266,11 +261,6 @@ GEM
rails-i18n (4.0.3)
i18n (~> 0.6)
railties (~> 4.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.3)
rails_stdout_logging (0.0.3)
railties (4.2.11)
actionpack (= 4.2.11)
activesupport (= 4.2.11)
Expand Down Expand Up @@ -393,6 +383,11 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
webdrivers (3.7.2)
net_http_ssl_fix
nokogiri (~> 1.6)
rubyzip (~> 1.0)
selenium-webdriver (~> 3.0)
whenever (0.9.4)
chronic (>= 0.6.3)
xpath (3.2.0)
Expand All @@ -412,7 +407,6 @@ DEPENDENCIES
capistrano-rails (~> 1.1)
capistrano-rbenv (~> 2.1)
capybara (~> 3.13)
chromedriver-helper (~> 2.1)
coffee-rails
dalli
database_cleaner (= 1.6.2)
Expand All @@ -435,7 +429,6 @@ DEPENDENCIES
pundit (~> 2.0.0)
rails (~> 4.2)
rails-i18n
rails_12factor (= 0.0.3)
rdiscount
rollbar (= 2.8.3)
rspec-rails (~> 3.8.2)
Expand All @@ -453,6 +446,7 @@ DEPENDENCIES
uglifier (= 2.7.2)
unicorn
web-console (= 2.1.3)
webdrivers (~> 3.0)
whenever

RUBY VERSION
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# TimeOverflow [![View performance data on Skylight](https://badges.skylight.io/problem/grDTNuzZRnyu.svg)](https://oss.skylight.io/app/applications/grDTNuzZRnyu) [![Build Status](https://travis-ci.org/coopdevs/timeoverflow.svg)](https://travis-ci.org/coopdevs/timeoverflow) [![Code Climate](https://codeclimate.com/github/timeoverflow/timeoverflow/badges/gpa.svg)](https://codeclimate.com/github/timeoverflow/timeoverflow)
# TimeOverflow
[![View performance data on Skylight](https://badges.skylight.io/problem/grDTNuzZRnyu.svg)](https://oss.skylight.io/app/applications/grDTNuzZRnyu)
[![Build Status](https://travis-ci.org/coopdevs/timeoverflow.svg)](https://travis-ci.org/coopdevs/timeoverflow)
[![Maintainability](https://api.codeclimate.com/v1/badges/f82c6d98a2441c84f2ef/maintainability)](https://codeclimate.com/github/coopdevs/timeoverflow/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/f82c6d98a2441c84f2ef/test_coverage)](https://codeclimate.com/github/coopdevs/timeoverflow/test_coverage)

#### www.timeoverflow.org

:globe_with_meridians: Read this [in English](docs/README.en.md)
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#= require give_time
#= require tags
#= require mobile_app_libs
#= require multi_select2

$(document).on 'click', 'a[data-popup]', (event) ->
window.open($(this).attr('href'), 'popup', 'width=600,height=600')
Expand Down
36 changes: 36 additions & 0 deletions app/assets/javascripts/give_time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$( document ).ready(function () {
jQuery.validator.addMethod(
"either-hours-minutes-informed",
function (value, element) {
return Boolean($("#transfer_hours").val() || $("#transfer_minutes").val());
},
"Hours or minutes should be informed"
);

function submitHandler(form) {
// just submit when fields are not visible, in order to not break the multi
// transfer wizard
if (!$("#transfer_hours").is(":visible")) {
form.submit();
return;
}

var amount = $("#transfer_hours").val() * 3600 + $("#transfer_minutes").val() * 60;
$("#transfer_amount").val(amount);

if (amount == 0) {
$(form).find('.js-error-amount').removeClass('invisible').show();
return;
}

if ($(form).valid()) {
form.submit();
}
}

var config = {
submitHandler: submitHandler
};

$("#multi_transfer, #new_transfer").validate(config);
})
18 changes: 0 additions & 18 deletions app/assets/javascripts/give_time.js.coffee

This file was deleted.

32 changes: 32 additions & 0 deletions app/assets/javascripts/multi_select2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* A setup function to make select2 jquery plugin play as an ordinary form when
* using the "multiple" flag.
*
* Also allows options to be disabled.
*
*
* @param {String} selector - CSS selector pointing to a <select /> element
* @param {Object} options
* @param {Array<String>} options.value - initial value
* @param {Array<String>} options.disabledOptions - disabled option values to disable
* @param {Array<String>} options.noMatchesFormat - i18n'd string to show when no matches found when filtering
*/
window.initializeSelect2 = function(selector, options) {
var $select = $(selector);

var optionsToDisableSelector = (options.disabledOptions || []).map(function (optionId) {
return "option[value=" + optionId + "]";
}).join(',');

var $options = $select.find(optionsToDisableSelector);
$options.attr('disabled', 'disabled');

$select.select2({
formatNoMatches: function () {
return options.noMatchesFormat
}
});

$select.val(options.value.length === 0 ? null : options.value);
$select.trigger('change');
}
16 changes: 16 additions & 0 deletions app/controllers/concerns/with_transfer_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module WithTransferParams
def transfer_params
permitted_transfer_params = [
:destination,
:amount,
:reason,
:post_id,
]

permitted_transfer_params.push(:source) if admin?

params.
require(:transfer).
permit(*permitted_transfer_params)
end
end
89 changes: 89 additions & 0 deletions app/controllers/multi_transfers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
class MultiTransfersController < ApplicationController
include WithTransferParams

STEPS = [
'select_type',
'select_source',
'select_target',
'set_params',
'confirm'
]

def step
authorize :multi_transfer

set_steps_info
propagate_params
prepare_template_vars
end

def create
authorize :multi_transfer

operation = Operations::Transfers.create(
from: params[:from],
to: params[:to],
transfer_params: params[:transfer].to_hash
)
operation.perform
end

private

def set_steps_info
@steps = STEPS
@step_name = step_name
@form_action = if @step_name == @steps.last
multi_transfers_create_path
else
multi_transfers_step_path(step: next_step)
end
@is_last_step = is_last_step
end

def propagate_params
@type_of_transfer = (params[:type_of_transfer] || :many_to_one).to_sym
@from = params[:from] || []
@to = params[:to] || []

@transfer_amount = params[:transfer] && params[:transfer][:amount]
@transfer_post_id = params[:transfer] && params[:transfer][:post_id]
@transfer_reason = params[:transfer] && params[:transfer][:reason]
@transfer_minutes = params[:transfer] && params[:transfer][:minutes]
@transfer_hours = params[:transfer] && params[:transfer][:hours]
end

def prepare_template_vars
@accounts = [current_organization.account] + current_organization.member_accounts.merge(Member.active)

if @type_of_transfer == :many_to_one && @to.length == 1
@target_accountable = Account.find(@to.first).accountable
end

@should_render_offer_selector = (
@type_of_transfer.to_sym == :many_to_one &&
@target_accountable &&
@target_accountable.offers.length > 0
)

@from_names = Account.find(@from).map(&:accountable).map(&:to_s)
@to_names = Account.find(@to).map(&:accountable).map(&:to_s)
@post_title = @transfer_post_id && Post.find(@transfer_post_id).title
end

def step_index
params[:step].to_i - 1
end

def next_step
params[:step].to_i + 1
end

def step_name
STEPS[step_index]
end

def is_last_step
step_index == STEPS.length - 1
end
end
6 changes: 2 additions & 4 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,15 @@ def resources

def set_user_id(p)
if current_user.manages?(current_organization)
p.update publisher_id: current_user.id
p.reverse_merge! user_id: current_user.id
else
p.update user_id: current_user.id
end
end

def post_params
permitted_fields = [:description, :end_on, :global, :joinable, :permanent,
:start_on, :title, :category_id, :user_id, :is_group,
:publisher_id, :active, tag_list: []]
permitted_fields = [:description, :end_on, :start_on, :title, :category_id,
:user_id, :is_group, :active, tag_list: []]

params.fetch(resource, {}).permit(*permitted_fields).tap do |p|
set_user_id(p)
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def statistics_inactive_users
def statistics_demographics
@members = current_organization.members
@age_counts = age_counts
@gender_counts = gender_counts
end

def statistics_last_login
Expand Down Expand Up @@ -168,4 +169,16 @@ def age_counts
counts[age_label] += 1
end
end

def gender_counts
@members.each_with_object(Hash.new(0)) do |member, counts|
gender = member.user_gender
gender_label = if gender.present?
t("simple_form.options.user.gender.#{gender}")
else
t("statistics.statistics_demographics.unknown")
end
counts[gender_label] += 1
end
end
end
12 changes: 2 additions & 10 deletions app/controllers/transfers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class TransfersController < ApplicationController
include WithTransferParams

def create
@source = find_source
@account = Account.find(transfer_params[:destination])
Expand Down Expand Up @@ -64,14 +66,4 @@ def redirect_target
raise ArgumentError
end
end

def transfer_params
params.
require(:transfer).
permit(:destination,
:amount,
:reason,
:post_id,
*[*(:source if admin?)])
end
end
Loading

0 comments on commit 4d58da4

Please sign in to comment.