diff --git a/Gemfile b/Gemfile index 3a36ae4cb..e386d1131 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,6 @@ gem 'rufus-scheduler', '~> 3.4.2' # Assets gem 'jquery-rails', '>= 4.2.0' -gem 'jquery-ui-rails' gem 'bootstrap-sass' gem 'sass-rails', '~> 5.0.7' gem 'coffee-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 6822349c2..e2e1f9011 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -180,8 +180,6 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jquery-ui-rails (5.0.3) - railties (>= 3.2.16) json (2.1.0) kaminari (1.1.1) activesupport (>= 4.1.0) @@ -423,7 +421,6 @@ DEPENDENCIES hstore_translate http_accept_language (~> 2.1.1) jquery-rails (>= 4.2.0) - jquery-ui-rails kaminari (~> 1.1.1) letter_opener (= 1.4.1) localeapp (= 2.1.1) diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 7bdc261c1..90a0a1a37 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -1,5 +1,3 @@ -#= require_self -#= require datepicker #= require give_time #= require tags #= require mobile_app_libs diff --git a/app/assets/javascripts/datepicker.js.coffee b/app/assets/javascripts/datepicker.js.coffee deleted file mode 100644 index f74b29052..000000000 --- a/app/assets/javascripts/datepicker.js.coffee +++ /dev/null @@ -1,20 +0,0 @@ -$ -> - $("input.datepicker").each (i) -> - $(this).datepicker - altFormat: "dd-mm-yy" - dateFormat: "dd/mm/yy" - altField: $(this).next() - $("#datepicker_from, #datepicker_to").datepicker - changeMonth: true - changeYear: true - showButtonPanel: true - dateFormat: "MM yy" - onClose: -> - month = $("#ui-datepicker-div .ui-datepicker-month :selected").val() - year = $("#ui-datepicker-div .ui-datepicker-year :selected").val() - $(this).datepicker "setDate", new Date(year, month, 1) - return - $("#datepicker_from, #datepicker_to").focus -> - $(".ui-datepicker-calendar").hide() - return - diff --git a/app/assets/javascripts/libs.js b/app/assets/javascripts/libs.js index 63a46c808..bc8647cb7 100644 --- a/app/assets/javascripts/libs.js +++ b/app/assets/javascripts/libs.js @@ -1,6 +1,5 @@ //= require jquery //= require jquery_ujs -//= require jquery-ui //= require jquery.validate //= require bootstrap //= require highcharts diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index b1455c6bd..828e5c541 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -1,7 +1,3 @@ -/* - *= require_self - */ - @import "variables"; @import "bootstrap-sprockets"; @import "bootstrap-custom"; @@ -312,11 +308,6 @@ ul.statistics li{ padding-left: 1.5rem; } -// if not navbar hidden datepicker in small windows -.ui-datepicker{ - z-index: 1000 !important; -} - // fields that contain an error .field_with_errors{ color: red; diff --git a/app/assets/stylesheets/libs.scss b/app/assets/stylesheets/libs.scss index 485de4a76..46c001a3f 100644 --- a/app/assets/stylesheets/libs.scss +++ b/app/assets/stylesheets/libs.scss @@ -1,4 +1,3 @@ /* -*= require jquery-ui *= require select2 */ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5ea40d98e..d9ba1e933 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,6 +17,7 @@ class ApplicationController < ActionController::Base end rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized + rescue_from ActiveRecord::RecordNotFound, with: :resource_not_found helper_method :current_organization, :admin?, :superadmin? @@ -118,4 +119,8 @@ def user_not_authorized flash[:error] = "You are not authorized to perform this action." redirect_to(request.referrer || root_path) end + + def resource_not_found + render 'errors/not_found', status: 404 + end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 220d68715..71c35f9b1 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -57,13 +57,13 @@ def edit instance_variable_set("@#{resource}", post) end + # GET /offers/:id + # GET /inquiries/:id + # def show - scope = if current_user.present? - current_organization.posts.active.of_active_members - else - model.all.active.of_active_members - end - post = scope.find params[:id] + post = Post.active.of_active_members.find(params[:id]) + update_current_organization!(post.organization) + instance_variable_set("@#{resource}", post) end @@ -115,4 +115,20 @@ def post_params set_user_id(p) end end + + # TODO: remove this horrible hack ASAP + # + # This hack set the current organization to the post's + # organization, both in session and controller instance variable. + # + # Before changing the current organization it's important to check that + # the current_user is an active member of the organization. + # + # @param organization [Organization] + def update_current_organization!(organization) + return unless current_user && current_user.active?(organization) + + session[:current_organization_id] = organization.id + @current_organization = organization + end end diff --git a/app/models/member.rb b/app/models/member.rb index d84d55e5d..ed20524a1 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,7 +1,7 @@ class Member < ActiveRecord::Base # Cast the member_uid integer to a string to allow pg ILIKE search (from Ransack *_contains) - ransacker :member_uid do - Arel.sql("to_char(member_uid, '9999999')") + ransacker :member_uid_search do + Arel.sql("member_uid::text") end belongs_to :user diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 795d32efc..44698d113 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -1,6 +1,10 @@ class ApplicationPolicy attr_reader :member, :user, :organization, :record + # TODO: Investigate how to just pass current_user here. + # Probably this will be solved by scoping the resources + # under `/organization`. + # def initialize(member, record) @member = member @user = member.user if member diff --git a/app/views/inquiries/show.html.erb b/app/views/inquiries/show.html.erb index 7c1bb7a0e..388c15283 100644 --- a/app/views/inquiries/show.html.erb +++ b/app/views/inquiries/show.html.erb @@ -1,15 +1,8 @@ -
- <% if admin? || @inquiry.user == current_user %> - <%= link_to edit_inquiry_path(@inquiry), class: "btn btn-warning" do %> - <%= glyph :pencil %> - <%= t "global.edit" %> +<% if @inquiry.organization == current_organization %> +
+ <% if admin? or @inquiry.user == current_user %> + <%= render 'shared/post_actions', post: @inquiry %> <% end %> - <%= link_to @inquiry, - data: { method: :delete, confirm: "sure?" }, - class: "btn btn-danger" do %> - <%= glyph :trash %> - <%= t "global.delete" %> - <% end %> - <% end %> -
+ +<% end %> <%= render "shared/post", post: @inquiry %> diff --git a/app/views/offers/show.html.erb b/app/views/offers/show.html.erb index a6135384a..a3afc8fa3 100644 --- a/app/views/offers/show.html.erb +++ b/app/views/offers/show.html.erb @@ -1,22 +1,15 @@ -- <% if admin? or @offer.user == current_user %> - <%= link_to edit_offer_path(@offer), class: "btn btn-warning" do %> - <%= glyph :pencil %> - <%= t "global.edit" %> +<% if @offer.organization == current_organization %> +
+ <% if admin? or @offer.user == current_user %> + <%= render 'shared/post_actions', post: @offer %> <% end %> - <%= link_to @offer, - data: { method: :DELETE, confirm: "sure?" }, - class: "btn btn-danger" do %> - <%= glyph :trash %> - <%= t "global.delete" %> + <% if current_user and @offer.user != current_user %> + <%= link_to new_transfer_path(id: @offer.user.id, offer: @offer.id, destination_account_id: @destination_account.id), + class: "btn btn-success" do %> + <%= glyph :time %> + <%= t ".give_time_for" %> + <% end %> <% end %> - <% end %> - <% if current_user and @offer.user != current_user %> - <%= link_to new_transfer_path(id: @offer.user.id, offer: @offer.id, destination_account_id: @destination_account.id), - class: "btn btn-success" do %> - <%= glyph :time %> - <%= t ".give_time_for" %> - <% end %> - <% end %> -
+ +<% end %> <%= render "shared/post", post: @offer %> diff --git a/app/views/shared/_post.html.erb b/app/views/shared/_post.html.erb index d9681bab7..370e03362 100644 --- a/app/views/shared/_post.html.erb +++ b/app/views/shared/_post.html.erb @@ -27,7 +27,7 @@ <% end %> - <% if current_user && current_organization %> + <% if current_user && current_organization == post.organization %>