Skip to content

Commit

Permalink
Merge pull request #109 from fsek/profile-merge
Browse files Browse the repository at this point in the history
Merge profiles into users WIP
  • Loading branch information
henrikssn committed May 13, 2015
2 parents 16a0b5d + 037ce20 commit d9a72a2
Show file tree
Hide file tree
Showing 148 changed files with 2,177 additions and 2,385 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gem 'coffee-rails'
gem 'coffee-script-source', '1.8.0'
gem 'devise'
gem 'bootstrap3-datetimepicker-rails', '~> 4.7.14'
gem 'datetimepicker-rails', github: 'zpaulovics/datetimepicker-rails', branch: 'master', submodules: true
gem 'factory_girl_rails'
gem 'fancybox2-rails'
gem 'font-awesome-rails'
Expand All @@ -32,6 +33,7 @@ gem 'paperclip'
gem 'prawn-rails'
gem 'responders', '~> 2.0'
gem 'sass-rails'
gem 'simple_form'
gem 'sqlite3'
gem 'turbolinks'
gem 'uglifier'
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: git://github.com/zpaulovics/datetimepicker-rails.git
revision: c5405f3486b57a52416caf93b79fc09d56930a82
branch: master
submodules: true
specs:
datetimepicker-rails (4.7.15)
momentjs-rails (>= 2.9.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -281,6 +290,9 @@ GEM
sexp_processor (4.5.0)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
simple_form (3.1.0)
actionpack (~> 4.0)
activemodel (~> 4.0)
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
Expand Down Expand Up @@ -363,6 +375,7 @@ DEPENDENCIES
coffee-rails
coffee-script-source (= 1.8.0)
database_cleaner
datetimepicker-rails!
devise
factory_girl_rails
fancybox2-rails
Expand Down Expand Up @@ -391,6 +404,7 @@ DEPENDENCIES
rspec-rails
sass-rails
shoulda-matchers
simple_form
sqlite3
therubyracer
turbolinks
Expand Down
22 changes: 9 additions & 13 deletions app/controllers/admin/cafe_works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ def edit
end

def create
flash[:notice] = 'Cafejobbet skapades, success.' if @cafe_work.save
flash[:notice] = alert_create(CafeWork) if @cafe_work.save
redirect_to [:admin, @cafe_work]
end

def update
if @cafe_work.update(cafe_work_params)
flash[:notice] = 'Cafejobbet uppdaterades'
redirect_to [:admin, @cafe_work]
redirect_to [:admin, @cafe_work], notice: alert_update(CafeWork)
else
render action: :edit
end
Expand All @@ -34,7 +33,7 @@ def destroy
@id = @cafe_work.id
@cafe_work.destroy
respond_to do |format|
format.html { redirect_to :admin_hilbert, notice: 'Cafepasset raderades.' }
format.html { redirect_to :admin_hilbert, alert: alert_destroy(CafeWork) }
format.js
end
end
Expand All @@ -51,7 +50,8 @@ def setup
def setup_create
if preview?
@cafe_works = @r.preview(@lv_first, @lv_last)
elsif save?
@cafe_work.valid?
else
@r.setup(@lv_first, @lv_last)
flash[:notice] = 'Cafejobben skapades'
end
Expand All @@ -71,7 +71,7 @@ def authorize
end

def cafe_work_params
params.require(:cafe_work).permit(:work_day, :pass, :lp, :lv)
params.require(:cafe_work).permit(:work_day, :pass, :lp, :lv, :lv_first, :lv_last, :d_year)
end

def set_new_cafe_work
Expand All @@ -89,15 +89,11 @@ def set_cafe_setup
end

def set_lv
@lv_first = (params[:lv_first].present?) ? params[:lv_first].to_i : 0
@lv_last = (params[:lv_last].present?) ? params[:lv_last].to_i : 0
@lv_first = cafe_work_params[:lv_first] || 0
@lv_last = cafe_work_params[:lv_last] || 0
end

def preview?
params[:commit] == 'Förhandsgranska'
end

def save?
params[:commit] == 'Spara'
params[:commit] == I18n.t(:preview)
end
end
13 changes: 13 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Admin::UsersController < ApplicationController
load_permissions_and_authorize_resource
before_action :authorize

def index
end

private

def authorize
authorize! :manage, User
end
end
3 changes: 2 additions & 1 deletion app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def new
end

def create
@album.author = current_user.profile
@album = Album.new(album_params)
@album.author = current_user
if @album.save
redirect_to @album, notice: 'Albumet skapades!'
else
Expand Down
17 changes: 10 additions & 7 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ class ApplicationController < ActionController::Base
before_action :configure_permitted_devise_parameters, if: :devise_controller?
before_action :set_locale

helper_method :success_update
helper_method :success_create
helper_method :alert_update, :alert_create, :alert_destroy

rescue_from CanCan::AccessDenied do |ex|
if current_user.nil?
Expand Down Expand Up @@ -40,12 +39,16 @@ def model_name(model, multiple)
end
end

def alert_update_resource(resource)
%(#{model_name(resource, false)} #{I18n.t('success_update')}.)
def alert_update(resource)
%(#{model_name(resource, false)} #{I18n.t(:success_update)}.)
end

def alert_create_resource(resource)
%(#{model_name(resource, false)} #{I18n.t('success_create')}.)
def alert_create(resource)
%(#{model_name(resource, false)} #{I18n.t(:success_create)}.)
end

def alert_destroy(resource)
%(#{model_name(resource, false)} #{I18n.t(:success_destroy)}.)
end

protected
Expand Down Expand Up @@ -73,7 +76,7 @@ def current_ability
# load the permissions for the current user so that UI can be manipulated
def load_permissions
return unless current_user
@current_permissions = current_user.profile.posts.each do |post|
@current_permissions = current_user.posts.each do |post|
post.permissions.map { |i| [i.subject_class, i.action] }
end
end
Expand Down
11 changes: 3 additions & 8 deletions app/controllers/cafe_works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def show
@cafe_work.load(current_user)
end

def authorize
@authenticated = @cafe_work.authorize(worker_params[:access_code])
end

def update_worker
if @cafe_work.add_or_update(worker_params, current_user)
flash[:notice] = 'Bokningen uppdaterades - du arbetar!'
Expand All @@ -22,8 +18,7 @@ def update_worker
end

def remove_worker
access = (params[:cafe_work].present?) ? worker_params[:access_code] : nil
if @cafe_work.remove_worker(current_user, access)
if @cafe_work.remove_worker(current_user)
flash[:notice] = 'Du arbetar inte längre på passet'
redirect_to @cafe_work
else
Expand All @@ -48,8 +43,8 @@ def nyckelpiga
private

def worker_params
params.require(:cafe_work).permit(:profile_id, :name, :lastname, :phone, :email,
:utskottskamp, :access_code, council_ids: [])
params.require(:cafe_work).permit(:user_id, :firstname, :lastname, :phone, :email,
:utskottskamp, council_ids: [])
end

def councils
Expand Down
60 changes: 17 additions & 43 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,80 +1,54 @@
# encoding:UTF-8
class ContactsController < ApplicationController
before_filter :authenticate_edit, only: [:new, :edit, :update, :destroy]
before_action :set_contact, only: [:show, :edit, :update, :destroy, :mail]
load_permissions_and_authorize_resource

def index
@contacts = Contact.all
end

def show
@sent = false
end

def new
@contact = Contact.new
end

def edit
end

def mail
if (params[:name]) && (params[:email]) && (params[:msg])
@name = params[:name]
@email = params[:email]
@msg = params[:msg]
ContactMailer.contact_email(@name, @email, @msg, @contact).deliver_now
respond_to do |format|
format.html { redirect_to @contact, notice: 'Meddelandet skickades.' }
format.json { render action: 'show', status: :created, location: @contact }
@sent = true
end
if @contact.mail(mail_params)
redirect_to @contact, notice: 'Meddelandet skickades.'
else
redirect_to @contact, alert: 'Någonting blev fel, prova att skicka igen.'
end
end

def create
@contact = Contact.new(contact_params)
respond_to do |format|
if @contact.save
format.html { redirect_to @contact, notice: 'Kontakten skapades, success.' }
format.json { render action: 'show', status: :created, location: @contact }
else
format.html { render action: 'new' }
format.json { render json: @contact.errors, status: :unprocessable_entity }
end
if @contact.save
redirect_to @contact, notice: alert_create(Contact)
else
render action: :new
end
end

def update
respond_to do |format|
if @contact.update(contact_params)
format.html { render action: 'edit', notice: 'Kontakten uppdaterades!' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @contact.errors, status: :unprocessable_entity }
end
if @contact.update(contact_params)
render action: :edit, notice: alert_update(Contact)
else
render action: :edit
end
end

def destroy
@contact.destroy
respond_to do |format|
format.html { redirect_to contacts_url }
format.json { head :no_content }
end
redirect_to contacts_path, notice: alert_destroy(Contact)
end

private
# Use callbacks to share common setup or constraints between actions.
def set_contact
@contact = Contact.find_by_id(params[:id])
if (@contact == nil)
redirect_to(contacts_path, notice: 'Ingen kontakt hittades.')
end

def mail_params
params.require(:contact).permit(:send_name, :send_email, :message, :copy)
end

# Never trust parameters from the scary internet, only allow the white list through.
def contact_params
params.require(:contact).permit(:name, :email, :public, :text, :council_id)
end
Expand Down
Loading

0 comments on commit d9a72a2

Please sign in to comment.