Skip to content

Commit d9a72a2

Browse files
committed
Merge pull request #109 from fsek/profile-merge
Merge profiles into users WIP
2 parents 16a0b5d + 037ce20 commit d9a72a2

File tree

148 files changed

+2177
-2385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+2177
-2385
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ gem 'coffee-rails'
1515
gem 'coffee-script-source', '1.8.0'
1616
gem 'devise'
1717
gem 'bootstrap3-datetimepicker-rails', '~> 4.7.14'
18+
gem 'datetimepicker-rails', github: 'zpaulovics/datetimepicker-rails', branch: 'master', submodules: true
1819
gem 'factory_girl_rails'
1920
gem 'fancybox2-rails'
2021
gem 'font-awesome-rails'
@@ -32,6 +33,7 @@ gem 'paperclip'
3233
gem 'prawn-rails'
3334
gem 'responders', '~> 2.0'
3435
gem 'sass-rails'
36+
gem 'simple_form'
3537
gem 'sqlite3'
3638
gem 'turbolinks'
3739
gem 'uglifier'

Gemfile.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
GIT
2+
remote: git://github.com/zpaulovics/datetimepicker-rails.git
3+
revision: c5405f3486b57a52416caf93b79fc09d56930a82
4+
branch: master
5+
submodules: true
6+
specs:
7+
datetimepicker-rails (4.7.15)
8+
momentjs-rails (>= 2.9.0)
9+
110
GEM
211
remote: https://rubygems.org/
312
specs:
@@ -281,6 +290,9 @@ GEM
281290
sexp_processor (4.5.0)
282291
shoulda-matchers (2.8.0)
283292
activesupport (>= 3.0.0)
293+
simple_form (3.1.0)
294+
actionpack (~> 4.0)
295+
activemodel (~> 4.0)
284296
simplecov (0.9.2)
285297
docile (~> 1.1.0)
286298
multi_json (~> 1.0)
@@ -363,6 +375,7 @@ DEPENDENCIES
363375
coffee-rails
364376
coffee-script-source (= 1.8.0)
365377
database_cleaner
378+
datetimepicker-rails!
366379
devise
367380
factory_girl_rails
368381
fancybox2-rails
@@ -391,6 +404,7 @@ DEPENDENCIES
391404
rspec-rails
392405
sass-rails
393406
shoulda-matchers
407+
simple_form
394408
sqlite3
395409
therubyracer
396410
turbolinks

app/controllers/admin/cafe_works_controller.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ def edit
1616
end
1717

1818
def create
19-
flash[:notice] = 'Cafejobbet skapades, success.' if @cafe_work.save
19+
flash[:notice] = alert_create(CafeWork) if @cafe_work.save
2020
redirect_to [:admin, @cafe_work]
2121
end
2222

2323
def update
2424
if @cafe_work.update(cafe_work_params)
25-
flash[:notice] = 'Cafejobbet uppdaterades'
26-
redirect_to [:admin, @cafe_work]
25+
redirect_to [:admin, @cafe_work], notice: alert_update(CafeWork)
2726
else
2827
render action: :edit
2928
end
@@ -34,7 +33,7 @@ def destroy
3433
@id = @cafe_work.id
3534
@cafe_work.destroy
3635
respond_to do |format|
37-
format.html { redirect_to :admin_hilbert, notice: 'Cafepasset raderades.' }
36+
format.html { redirect_to :admin_hilbert, alert: alert_destroy(CafeWork) }
3837
format.js
3938
end
4039
end
@@ -51,7 +50,8 @@ def setup
5150
def setup_create
5251
if preview?
5352
@cafe_works = @r.preview(@lv_first, @lv_last)
54-
elsif save?
53+
@cafe_work.valid?
54+
else
5555
@r.setup(@lv_first, @lv_last)
5656
flash[:notice] = 'Cafejobben skapades'
5757
end
@@ -71,7 +71,7 @@ def authorize
7171
end
7272

7373
def cafe_work_params
74-
params.require(:cafe_work).permit(:work_day, :pass, :lp, :lv)
74+
params.require(:cafe_work).permit(:work_day, :pass, :lp, :lv, :lv_first, :lv_last, :d_year)
7575
end
7676

7777
def set_new_cafe_work
@@ -89,15 +89,11 @@ def set_cafe_setup
8989
end
9090

9191
def set_lv
92-
@lv_first = (params[:lv_first].present?) ? params[:lv_first].to_i : 0
93-
@lv_last = (params[:lv_last].present?) ? params[:lv_last].to_i : 0
92+
@lv_first = cafe_work_params[:lv_first] || 0
93+
@lv_last = cafe_work_params[:lv_last] || 0
9494
end
9595

9696
def preview?
97-
params[:commit] == 'Förhandsgranska'
98-
end
99-
100-
def save?
101-
params[:commit] == 'Spara'
97+
params[:commit] == I18n.t(:preview)
10298
end
10399
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Admin::UsersController < ApplicationController
2+
load_permissions_and_authorize_resource
3+
before_action :authorize
4+
5+
def index
6+
end
7+
8+
private
9+
10+
def authorize
11+
authorize! :manage, User
12+
end
13+
end

app/controllers/albums_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def new
2727
end
2828

2929
def create
30-
@album.author = current_user.profile
30+
@album = Album.new(album_params)
31+
@album.author = current_user
3132
if @album.save
3233
redirect_to @album, notice: 'Albumet skapades!'
3334
else

app/controllers/application_controller.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ class ApplicationController < ActionController::Base
44
before_action :configure_permitted_devise_parameters, if: :devise_controller?
55
before_action :set_locale
66

7-
helper_method :success_update
8-
helper_method :success_create
7+
helper_method :alert_update, :alert_create, :alert_destroy
98

109
rescue_from CanCan::AccessDenied do |ex|
1110
if current_user.nil?
@@ -40,12 +39,16 @@ def model_name(model, multiple)
4039
end
4140
end
4241

43-
def alert_update_resource(resource)
44-
%(#{model_name(resource, false)} #{I18n.t('success_update')}.)
42+
def alert_update(resource)
43+
%(#{model_name(resource, false)} #{I18n.t(:success_update)}.)
4544
end
4645

47-
def alert_create_resource(resource)
48-
%(#{model_name(resource, false)} #{I18n.t('success_create')}.)
46+
def alert_create(resource)
47+
%(#{model_name(resource, false)} #{I18n.t(:success_create)}.)
48+
end
49+
50+
def alert_destroy(resource)
51+
%(#{model_name(resource, false)} #{I18n.t(:success_destroy)}.)
4952
end
5053

5154
protected
@@ -73,7 +76,7 @@ def current_ability
7376
# load the permissions for the current user so that UI can be manipulated
7477
def load_permissions
7578
return unless current_user
76-
@current_permissions = current_user.profile.posts.each do |post|
79+
@current_permissions = current_user.posts.each do |post|
7780
post.permissions.map { |i| [i.subject_class, i.action] }
7881
end
7982
end

app/controllers/cafe_works_controller.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ def show
88
@cafe_work.load(current_user)
99
end
1010

11-
def authorize
12-
@authenticated = @cafe_work.authorize(worker_params[:access_code])
13-
end
14-
1511
def update_worker
1612
if @cafe_work.add_or_update(worker_params, current_user)
1713
flash[:notice] = 'Bokningen uppdaterades - du arbetar!'
@@ -22,8 +18,7 @@ def update_worker
2218
end
2319

2420
def remove_worker
25-
access = (params[:cafe_work].present?) ? worker_params[:access_code] : nil
26-
if @cafe_work.remove_worker(current_user, access)
21+
if @cafe_work.remove_worker(current_user)
2722
flash[:notice] = 'Du arbetar inte längre på passet'
2823
redirect_to @cafe_work
2924
else
@@ -48,8 +43,8 @@ def nyckelpiga
4843
private
4944

5045
def worker_params
51-
params.require(:cafe_work).permit(:profile_id, :name, :lastname, :phone, :email,
52-
:utskottskamp, :access_code, council_ids: [])
46+
params.require(:cafe_work).permit(:user_id, :firstname, :lastname, :phone, :email,
47+
:utskottskamp, council_ids: [])
5348
end
5449

5550
def councils

app/controllers/contacts_controller.rb

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,54 @@
11
# encoding:UTF-8
22
class ContactsController < ApplicationController
3-
before_filter :authenticate_edit, only: [:new, :edit, :update, :destroy]
4-
before_action :set_contact, only: [:show, :edit, :update, :destroy, :mail]
3+
load_permissions_and_authorize_resource
54

65
def index
7-
@contacts = Contact.all
86
end
97

108
def show
11-
@sent = false
129
end
1310

1411
def new
15-
@contact = Contact.new
1612
end
1713

1814
def edit
1915
end
2016

2117
def mail
22-
if (params[:name]) && (params[:email]) && (params[:msg])
23-
@name = params[:name]
24-
@email = params[:email]
25-
@msg = params[:msg]
26-
ContactMailer.contact_email(@name, @email, @msg, @contact).deliver_now
27-
respond_to do |format|
28-
format.html { redirect_to @contact, notice: 'Meddelandet skickades.' }
29-
format.json { render action: 'show', status: :created, location: @contact }
30-
@sent = true
31-
end
18+
if @contact.mail(mail_params)
19+
redirect_to @contact, notice: 'Meddelandet skickades.'
20+
else
21+
redirect_to @contact, alert: 'Någonting blev fel, prova att skicka igen.'
3222
end
3323
end
3424

3525
def create
36-
@contact = Contact.new(contact_params)
37-
respond_to do |format|
38-
if @contact.save
39-
format.html { redirect_to @contact, notice: 'Kontakten skapades, success.' }
40-
format.json { render action: 'show', status: :created, location: @contact }
41-
else
42-
format.html { render action: 'new' }
43-
format.json { render json: @contact.errors, status: :unprocessable_entity }
44-
end
26+
if @contact.save
27+
redirect_to @contact, notice: alert_create(Contact)
28+
else
29+
render action: :new
4530
end
4631
end
4732

4833
def update
49-
respond_to do |format|
50-
if @contact.update(contact_params)
51-
format.html { render action: 'edit', notice: 'Kontakten uppdaterades!' }
52-
format.json { head :no_content }
53-
else
54-
format.html { render action: 'edit' }
55-
format.json { render json: @contact.errors, status: :unprocessable_entity }
56-
end
34+
if @contact.update(contact_params)
35+
render action: :edit, notice: alert_update(Contact)
36+
else
37+
render action: :edit
5738
end
5839
end
5940

6041
def destroy
6142
@contact.destroy
62-
respond_to do |format|
63-
format.html { redirect_to contacts_url }
64-
format.json { head :no_content }
65-
end
43+
redirect_to contacts_path, notice: alert_destroy(Contact)
6644
end
6745

6846
private
69-
# Use callbacks to share common setup or constraints between actions.
70-
def set_contact
71-
@contact = Contact.find_by_id(params[:id])
72-
if (@contact == nil)
73-
redirect_to(contacts_path, notice: 'Ingen kontakt hittades.')
74-
end
47+
48+
def mail_params
49+
params.require(:contact).permit(:send_name, :send_email, :message, :copy)
7550
end
7651

77-
# Never trust parameters from the scary internet, only allow the white list through.
7852
def contact_params
7953
params.require(:contact).permit(:name, :email, :public, :text, :council_id)
8054
end

0 commit comments

Comments
 (0)