Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/hitobito/hitobito_pbs
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare committed Oct 12, 2014
2 parents 2eae09d + 6107af4 commit 795f36a
Show file tree
Hide file tree
Showing 24 changed files with 524 additions and 85 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# encoding: utf-8

# Copyright (c) 2014, Pfadibewegung Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.

require File.expand_path('../app_root', __FILE__)

source 'https://rubygems.org'
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# encoding: utf-8
#!/usr/bin/env rake

# Copyright (c) 2014, Pfadibewegung Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.


begin
require 'bundler/setup'
rescue LoadError
Expand Down
35 changes: 35 additions & 0 deletions app/jobs/group_membership_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# encoding: utf-8

# Copyright (c) 2012-2014, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_pbs.

class GroupMembershipJob < BaseJob

self.parameters = [:recipient_id, :actuator_id, :group_id, :locale]

def initialize(recipient, actuator, group)
super()
@recipient_id = recipient.id
@actuator_id = actuator.id
@group_id = group.id
end

def perform
set_locale
GroupMembershipMailer.added_to_group(recipient, actuator, group).deliver
end

def recipient
@recipient ||= Person.find(@recipient_id)
end

def actuator
@actuator ||= Person.find(@actuator_id)
end

def group
@group ||= Group.find(@group_id)
end
end
34 changes: 34 additions & 0 deletions app/mailers/group_membership_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# encoding: utf-8

# Copyright (c) 2012-2014, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_pbs.

class GroupMembershipMailer < ActionMailer::Base

CONTENT_GROUP_MEMBERSHIP = 'group_membership'

def added_to_group(recipient, actuator, group)
content = CustomContent.get(CONTENT_GROUP_MEMBERSHIP)
values = {
'recipient-name' => recipient.greeting_name,
'actuator-name' => actuator.to_s,
'group-link' => group_link_with_layer(group)
}

# This email is only sent to the main email address.
mail(to: recipient.email, subject: content.subject) do |format|
format.html { render text: content.body_with_values(values) }
end
end

private

def group_link_with_layer(group)
group_links = group.with_layer.map do |g|
"<a href=\"#{group_url(g)}\">#{g}</a>"
end
group_links.join(' / ')
end
end
31 changes: 31 additions & 0 deletions app/models/pbs/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ module Pbs::Role
included do
self.used_attributes += [:created_at, :deleted_at]

validates_presence_of :created_at, on: :update

validates :created_at,
timeliness: { type: :datetime,
on_or_before: :now,
allow_blank: true }

validates :deleted_at,
timeliness: { type: :datetime,
on_or_before: :now,
after: ->(role) { role.created_at },
allow_blank: true }

before_create :detect_group_membership_notification
after_create :send_group_membership_notification
end

def created_at=(value)
Expand All @@ -49,4 +55,29 @@ def deleted_at=(value)
# could not set value
super(nil)
end

def detect_group_membership_notification
@send_notification = false;

return unless Person.stamper
@current_user = Person.find(Person.stamper)

# don't notify newly created users without roles
p = Person.find(person.id)
return unless p.roles.exists?

# manually initialize ability (this is not very beautiful but
# must be done to detect change in access to person data)
@send_notification = Ability.new(@current_user).cannot?(:update, p)

true
end

def send_group_membership_notification
if @send_notification && @current_user
GroupMembershipJob.new(person, @current_user, group).enqueue!
end

true
end
end
18 changes: 18 additions & 0 deletions app/serializers/pbs/group_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: utf-8

# Copyright (c) 2014, Pfadibewegung Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.

module Pbs::GroupSerializer
extend ActiveSupport::Concern

included do
extension(:attrs) do |_|
map_properties(*item.used_attributes(:pbs_shortname, :website, :bank_account, :pta, :vkp,
:pbs_material_insurance, :description))
end
end

end
18 changes: 18 additions & 0 deletions app/serializers/pbs/person_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: utf-8

# Copyright (c) 2014, Pfadibewegung Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.

module Pbs::PersonSerializer
extend ActiveSupport::Concern

included do
extension(:details) do |_|
map_properties :pbs_number, :j_s_number, :salutation_value, :correspondence_language,
:grade_of_school, :brother_and_sisters, :entry_date, :leaving_date
end
end

end
3 changes: 3 additions & 0 deletions app/views/roles/_fields_pbs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

= f.labeled(:deleted_at) do
= f.date_field(:deleted_at, class: 'date span6', value: f(@role.deleted_at.try(:to_date)))

= field_set_tag t('.notification') do
%p= t('.notification_hint')
5 changes: 5 additions & 0 deletions config/locales/models.pbs.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ de:
j_s_number: J+S Personennummer
correspondence_language: Korrespondenzsprache
brother_and_sisters: Geschwister
relations_to_tails: Geschwister

group:
pta: PTA
Expand All @@ -700,6 +701,10 @@ de:
bank_account: Bank-/Postverbindung
description: Beschreibung

people_relation:
kinds:
sibling: Geschwister

census:
year: Jahr
start_at: Ab
Expand Down
11 changes: 11 additions & 0 deletions config/locales/views.pbs.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ de:
membercounts:

people:
fields:
no_sensitive_information: In diesem Feld keine besonders schützenswerte Personendaten erfassen.
fields_pbs:
non_automatic_field: Dies ist kein automatisches Feld und muss manuell angepasst werden.
in_abteilung: (in der Abteilung)
Expand All @@ -67,3 +69,12 @@ de:
please_confirm_census_data: 'Bitte ergänze das Geschlecht aller Mitglieder und bestätige den Bestand deiner Abteilung mit "Bestand bestätigen".'
missing_gender_information: Um den Bestand bestätigen zu können, muss bei allen Mitgliedern das Geschlecht ausgefüllt sein.

roles:
fields_pbs:
notification: Benachrichtigung
notification_hint: Bestehende Personen werden per E-Mail über die Änderung informiert, sofern Du dadurch mehr Personendaten einsehen kannst.

devise:
sessions:
new:
usage_advise: Die Daten in der Mitgliederdatenbank dürfen nur im Zusammenhang mit Aktivitäten der Pfadi verwendet werden, sie dürfen z.B. nicht an Drittpersonen oder Organisationen weiter gegeben werden. Die Bearbeitung und Nutzung hat nach Treu und Glauben zu erfolgen und muss verhältnismässig sein.
4 changes: 2 additions & 2 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Settings relevant for the jubla wagon
# Overrides settings from the main application
application:
#name: Pfadi

languages:
de: Deutsch
Expand All @@ -16,4 +15,5 @@ application:
# The person with this email has root access to everything
# This person should only be used by the operators of the application, not the customers.
# Initially, a password reset token may be mailed from the application to this address to set a password.
root_email: [email protected]
root_email: [email protected]

36 changes: 36 additions & 0 deletions db/seeds/custom_contents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# encoding: utf-8

# Copyright (c) 2012-2014, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_pbs.

CustomContent.seed_once(:key,
{ key: GroupMembershipMailer::CONTENT_GROUP_MEMBERSHIP,
placeholders_required: 'actuator-name, group-link',
placeholders_optional: 'recipient-name' }
)

group_membership_id = CustomContent.where(key: GroupMembershipMailer::CONTENT_GROUP_MEMBERSHIP).first.id

CustomContent::Translation.seed_once(:custom_content_id, :locale,
{ custom_content_id: group_membership_id,
locale: 'de',
label: 'Information bei neuer Gruppenzugehörigkeit',
subject: "Aufnahme in Gruppe",
body: "Hallo {recipient-name}<br/><br/>" \
"{actuator-name} hat dich zur Gruppe {group-link} hinzugefügt.<br/><br/>" \
"Bis bald!" },

{ custom_content_id: group_membership_id,
locale: 'fr',
label: 'Informations pour les nouveau membres du groupe',
subject: 'Admission dans le groupe',
body: "Salut {recipient-name}<br/><br/>" \
"{actuator-name} t\'as ajouté au groupe {group-link}.<br/><br/>" \
"A bientôt!"},

{ custom_content_id: group_membership_id,
locale: 'it',
label: 'Informazioni per la nuova appartenenza al gruppo' }
)
4 changes: 3 additions & 1 deletion db/seeds/development/1_people.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def amount(role_type)
'Pierre Fritsch',
'Andreas Maierhofer',
'Andre Kunz',
'Roland Studer']
'Roland Studer',
'Mathis Hofer',
'Bruno Santschi']

devs = {'Olivier Brian' => '[email protected]'}
puzzlers.each do |puz|
Expand Down
6 changes: 6 additions & 0 deletions lib/hitobito_pbs/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Wagon < Rails::Engine
config.autoload_paths += %W( #{config.root}/app/abilities
#{config.root}/app/domain
#{config.root}/app/jobs
#{config.root}/app/serializers
)

config.to_prepare do
Expand All @@ -28,9 +29,14 @@ class Wagon < Rails::Engine
Person.send :include, Pbs::Person
Role.send :include, Pbs::Role

PeopleRelation.kind_opposites['sibling'] = 'sibling'

GroupAbility.send :include, Pbs::GroupAbility
VariousAbility.send :include, Pbs::VariousAbility

PersonSerializer.send :include, Pbs::PersonSerializer
GroupSerializer.send :include, Pbs::GroupSerializer

PeopleController.permitted_attrs +=
[:salutation, :title, :grade_of_school, :entry_date, :leaving_date,
:j_s_number, :correspondence_language, :brother_and_sisters]
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/tarantula.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ desc "Crawl app with tarantula"
task :tarantula do
sh 'rm -rf ../../../tmp/tarantula'
sh 'rm -rf ../hitobito/tmp/tarantula'
sh "bash -c \"RAILS_ENV=test #{ENV['APP_ROOT']}/bin/with_mysql rake db:test:prepare app:tarantula:test\""
sh "bash -c \"RAILS_ENV=test #{ENV['APP_ROOT']}/bin/with_mysql rake app:tarantula:test\""
end
Loading

0 comments on commit 795f36a

Please sign in to comment.