Skip to content

Release v1.9.0 #429

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 46 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1be5c19
- add some missing "dependent: :destroy" in Organization model: fixes…
markets May 26, 2018
6c89900
gems: update Pundit to latest release (1.1.0)
markets May 26, 2018
d34e083
add more OrganizationsController specs
markets May 26, 2018
26d77a4
UserPolicy minor DRY refactor:
markets May 28, 2018
035117b
add some organizations#show view specs
markets May 28, 2018
4bfc636
OrganizatioPolicy: make show action a public page
markets May 29, 2018
9418484
delete events when deleting target object
markets Jun 7, 2018
7f6a087
- let's remove PushNotification when we delete an Event
markets Jun 10, 2018
0c6c1e7
Merge branch 'develop' into delete_org and fix conflicts
markets Aug 8, 2018
2231b63
gems: Pundit 2
markets Aug 8, 2018
43b3738
policies: :scissors: Scopes as we are not really using it (policy_sco…
markets Aug 15, 2018
ea38581
Add PushNotification#to
enricostano Jun 4, 2018
8069d51
Add title to PushNotification
enricostano Jun 4, 2018
2e8b31d
Add PushNotification fabricator
enricostano Jun 4, 2018
ae9ef90
Add token to DeviceToken fabricator
enricostano Jun 4, 2018
cb16c03
Create new PushNotifications with title
enricostano Jun 4, 2018
2352b79
Remove unused services
enricostano Jun 4, 2018
67c4fe8
Add scheduled job to send push notifications
enricostano Jun 4, 2018
13ff3d1
Upgrade elasticsearch gems
enricostano Jun 4, 2018
5c114f4
Flag push_notifications as processed
enricostano Jun 19, 2018
9313474
Set notifications as processed after publish
enricostano Aug 21, 2018
005e683
Revert "Upgrade elasticsearch gems"
enricostano Aug 23, 2018
20eb8cb
Remove Expo client gem
enricostano Aug 23, 2018
7751766
Use standard ruby net http instead of Expo client
enricostano Aug 23, 2018
e247110
#send is a word reserved to Ruby... :boom
enricostano Aug 23, 2018
2698747
Fix notifications broadcast
enricostano Aug 23, 2018
d94684e
Use Post title as notification title
enricostano Aug 23, 2018
1e816a3
[Security] Bump rubyzip from 1.2.1 to 1.2.2
dependabot-support Aug 31, 2018
285617f
`.env.example` cleanup (remove unused vars) and dotenv-rails upgrade
markets Aug 31, 2018
94acd09
:scissors: config/newrelic.yml, we are using Skylight now
markets Aug 15, 2018
d2eae50
:scissors: unused app/inputs/* (old simple_form overrides)
markets Aug 31, 2018
452e5c4
[Security] Bump ffi from 1.9.23 to 1.9.25
dependabot-support Sep 1, 2018
fee1aac
Fixed migrations with defaults
mllocs Sep 3, 2018
bcb8684
Refactor PushNotificatiosn::Creator with a Base class
mllocs Sep 3, 2018
ff7cc52
Merge pull request #417 from coopdevs/upgrade_dotenv
sauloperez Sep 4, 2018
6d0923a
Merge pull request #415 from greysteil/dependabot/bundler/rubyzip-1.2.2
sauloperez Sep 4, 2018
dbf1a65
Merge pull request #418 from greysteil/dependabot/bundler/ffi-1.9.25
sauloperez Sep 4, 2018
22a26c9
Merge pull request #377 from coopdevs/feature/scheduled-jobs
enricostano Sep 11, 2018
7cc1d11
Merge branch 'develop' into delete_org
markets Sep 12, 2018
4960664
en.yml
sseerrggii Sep 18, 2018
c6e9934
ca es eu pt-BR
sseerrggii Sep 18, 2018
3204d41
Merge pull request #428 from coopdevs/translate/quit-app-platform-brands
sauloperez Sep 19, 2018
14fe6bc
Admin section: Logout user if deleted organization is current_organiz…
markets Sep 19, 2018
a47597e
Merge pull request #368 from coopdevs/delete_org
sauloperez Sep 20, 2018
cbe7e14
fix cancel_membership wrong key name
sseerrggii Sep 20, 2018
aacb6c9
Merge pull request #430 from coopdevs/fix/cancel_membership_key
sauloperez Sep 20, 2018
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
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="admin@timeoverflow.org"
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