Skip to content

Commit

Permalink
Merge pull request #429 from coopdevs/develop
Browse files Browse the repository at this point in the history
Release v1.9.0
  • Loading branch information
sauloperez authored Sep 20, 2018
2 parents 7e28ed9 + aacb6c9 commit a118ba1
Show file tree
Hide file tree
Showing 53 changed files with 563 additions and 461 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@


# database setup:
DATABASE_ADAPTER=postgres
DATABASE_USER=postgres
DATABASE_HOST=localhost
DATABASE_NAME=timeoverflow_development

# host part of the url for mail links:
MAIL_LINK_HOST=localhost:3000
MAIL_LINK_PROTO=http

# a list of emails for superadmin users
ADMINS="[email protected]"
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'rails-i18n'
gem "rdiscount"
gem 'activeadmin', '~> 1.2.1'
gem 'has_scope'
gem 'pundit'
gem 'pundit', '~> 2.0.0'
gem 'pg', '0.17.1'
gem 'hstore_translate'
gem 'dalli'
Expand Down Expand Up @@ -48,7 +48,7 @@ group :development do
gem 'airbrussh', require: false
gem 'localeapp', '2.1.1', require: false
gem 'letter_opener', '1.4.1'
gem 'dotenv-rails', '1.0.2'
gem 'dotenv-rails', '2.5.0'
end

group :development, :test do
Expand Down
17 changes: 9 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ GEM
diff-lcs (1.3)
domain_name (0.5.20170223)
unf (>= 0.0.5, < 1.0.0)
dotenv (1.0.2)
dotenv-rails (1.0.2)
dotenv (= 1.0.2)
dotenv (2.5.0)
dotenv-rails (2.5.0)
dotenv (= 2.5.0)
railties (>= 3.2, < 6.0)
elasticsearch (1.0.8)
elasticsearch-api (= 1.0.7)
elasticsearch-transport (= 1.0.7)
Expand All @@ -152,7 +153,7 @@ GEM
i18n (~> 0.5)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.23)
ffi (1.9.25)
formtastic (3.1.5)
actionpack (>= 3.2.13)
formtastic_i18n (0.6.0)
Expand Down Expand Up @@ -237,7 +238,7 @@ GEM
prawn-table (0.2.2)
prawn (>= 1.3.0, < 3.0.0)
public_suffix (2.0.5)
pundit (0.3.0)
pundit (2.0.0)
activesupport (>= 3.0.0)
rack (1.6.10)
rack-protection (2.0.1)
Expand Down Expand Up @@ -321,7 +322,7 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
rubyzip (1.2.1)
rubyzip (1.2.2)
rufus-scheduler (3.4.2)
et-orbi (~> 1.0)
sass (3.4.21)
Expand Down Expand Up @@ -412,7 +413,7 @@ DEPENDENCIES
dalli
database_cleaner (= 1.6.2)
devise (~> 4.4.1)
dotenv-rails (= 1.0.2)
dotenv-rails (= 2.5.0)
elasticsearch-model
elasticsearch-rails
fabrication
Expand All @@ -427,7 +428,7 @@ DEPENDENCIES
pg (= 0.17.1)
prawn (~> 2.2.0)
prawn-table (~> 0.2.2)
pundit
pundit (~> 2.0.0)
rails (~> 4.2)
rails-i18n
rails_12factor (= 0.0.3)
Expand Down
13 changes: 13 additions & 0 deletions app/admin/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
f.actions
end

controller do
def destroy
resource.destroy

if resource == current_organization
sign_out(current_user)
redirect_to root_path
else
redirect_to admin_organizations_path
end
end
end

filter :name
filter :city, as: :select, collection: -> { Organization.pluck(:city).uniq }
filter :neighborhood
Expand Down
17 changes: 9 additions & 8 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
class OrganizationsController < ApplicationController
before_filter :load_resource, only: [:show, :edit, :update, :destroy, :set_current]
before_filter :load_resource, only: [:show, :edit, :update, :set_current]

def new
@organization = Organization.new

authorize @organization
end

def index
@organizations = Organization.all
@organizations = Organization.all.page(params[:page]).per(25)
end

def show
Expand All @@ -21,8 +23,10 @@ def show
def create
@organization = Organization.new(organization_params)

authorize @organization

if @organization.save
redirect_to @organization, status: :created
redirect_to @organization
else
render action: :new, status: :unprocessable_entity
end
Expand All @@ -36,11 +40,6 @@ def update
end
end

def destroy
@organization.destroy
redirect_to organizations_path, notice: "deleted"
end

# POST /organizations/:organization_id/set_current
#
def set_current
Expand All @@ -54,6 +53,8 @@ def set_current

def load_resource
@organization = Organization.find(params[:id])

authorize @organization
end

def organization_params
Expand Down
5 changes: 0 additions & 5 deletions app/inputs/collection_select2_input.rb

This file was deleted.

6 changes: 0 additions & 6 deletions app/inputs/datepicker_input.rb

This file was deleted.

6 changes: 5 additions & 1 deletion app/jobs/create_push_notifications_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def perform(event_id:)

raise 'A valid Event must be provided' unless event

::PushNotifications::Creator.new(event: event).create!
if event.post_id
::PushNotifications::Creator::Post.new(event: event).create!
else
raise "You need to define a PushNotifications::Creator class for this event type ##{event.id}"
end
end
end
11 changes: 11 additions & 0 deletions app/jobs/send_push_notifications_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class SendPushNotificationsJob < ActiveJob::Base
queue_as :cron

def perform
push_notifications = PushNotification.where(processed_at: nil).limit(100)

::PushNotifications::Broadcast.new(
push_notifications: push_notifications
).send_notifications
end
end
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Event < ActiveRecord::Base
belongs_to :post
belongs_to :member
belongs_to :transfer
has_many :push_notifications, dependent: :destroy

validates :action, presence: true
validate :resource_presence
Expand Down
1 change: 1 addition & 0 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Member < ActiveRecord::Base
belongs_to :organization
has_one :account, as: :accountable
has_many :movements, through: :account
has_many :events, dependent: :destroy

delegate :balance, to: :account, prefix: true, allow_nil: true
delegate :gender, :date_of_birth, to: :user, prefix: true, allow_nil: true
Expand Down
8 changes: 4 additions & 4 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Organization < ActiveRecord::Base
has_many :members, dependent: :destroy
has_many :users, -> { order "members.created_at DESC" }, through: :members
has_many :all_accounts, class_name: "Account", inverse_of: :organization
has_many :all_accounts, class_name: "Account", inverse_of: :organization, dependent: :destroy
has_many :all_movements, class_name: "Movement", through: :all_accounts, source: :movements
has_many :all_transfers, class_name: "Transfer", through: :all_movements, source: :transfer
has_one :account, as: :accountable
has_one :account, as: :accountable, dependent: :destroy
has_many :member_accounts, through: :members, source: :account
has_many :posts
has_many :posts, dependent: :destroy
has_many :offers
has_many :inquiries
has_many :documents, as: :documentable
has_many :documents, as: :documentable, dependent: :destroy

validates :name, presence: true, uniqueness: true

Expand Down
3 changes: 1 addition & 2 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ def self.inherited(child)
attr_reader :member_id

belongs_to :category

belongs_to :user
belongs_to :organization
belongs_to :publisher, class_name: "User", foreign_key: "publisher_id"
has_many :user_members, class_name: "Member", through: :user, source: :members
has_many :transfers
has_many :movements, through: :transfers
has_many :events, dependent: :destroy

delegate :name, to: :category, prefix: true, allow_nil: true

Expand Down
4 changes: 3 additions & 1 deletion app/models/push_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ class PushNotification < ActiveRecord::Base
belongs_to :event, foreign_key: 'event_id'
belongs_to :device_token, foreign_key: 'device_token_id'

validates :event, :device_token, presence: true
validates :event, :device_token, :title, presence: true

delegate :token, to: :device_token
end
4 changes: 2 additions & 2 deletions app/models/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Transfer < ActiveRecord::Base
attr_accessor :source, :destination, :amount, :hours, :minutes

belongs_to :post
belongs_to :operator, class_name: "User"
has_many :movements
has_many :movements, dependent: :destroy
has_many :events, dependent: :destroy

validate :different_source_and_destination

Expand Down
21 changes: 1 addition & 20 deletions app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def index?
end

def show?
scope.where(id: record.id).exists?
record.class.where(id: record.id).exists?
end

def create?
Expand All @@ -39,23 +39,4 @@ def edit?
def destroy?
false
end

def scope
Pundit.policy_scope!(member, record.class)
end

class Scope
attr_reader :member, :user, :organization, :scope

def initialize(member, scope)
@member = member
@user = member.user if member
@organization = member.organization if member
@scope = scope
end

def resolve
scope
end
end
end
19 changes: 19 additions & 0 deletions app/policies/organization_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class OrganizationPolicy < ApplicationPolicy
alias_method :organization, :record

def index?
true
end

def create?
user&.superadmin?
end

def update?
user&.superadmin? || user&.admins?(organization)
end

def set_current?
user&.as_member_of(organization)
end
end
19 changes: 0 additions & 19 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
class UserPolicy < ApplicationPolicy
def new?
user.admins?(organization)
end

def create?
user.admins?(organization)
end
Expand All @@ -14,19 +10,4 @@ def update?
user.admins?(organization)
)
end

class Scope < ApplicationPolicy::Scope
attr_reader :member, :user, :organization, :scope

def initialize(user, scope)
@member = member
@user = member.user if member
@organization = member.organization if member
@scope = scope
end

def resolve
scope
end
end
end
Loading

0 comments on commit a118ba1

Please sign in to comment.