Skip to content

Commit

Permalink
Save option to display only own label formats in users (issue hitobit…
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasSkywalker committed Dec 14, 2016
1 parent ac70977 commit 1c88aba
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/abilities/person_ability.rb
Expand Up @@ -13,7 +13,8 @@ class PersonAbility < AbilityDsl::Base
class_side(:index, :query).everybody

permission(:any).may(:show, :show_full, :history, :update,
:update_email, :primary_group, :log).
:update_email, :primary_group, :log,
:label_format_settings).
herself

permission(:contact_data).may(:show).other_with_contact_data
Expand Down
21 changes: 21 additions & 0 deletions app/controllers/label_format/settings_controller.rb
@@ -0,0 +1,21 @@
class LabelFormat::SettingsController < ApplicationController
before_action :authorize

def update
if params[:display_only_own_label_formats].blank?
user.update!(display_only_own_label_formats: false)
else
user.update!(display_only_own_label_formats: true)
end
end

private

def user
current_user
end

def authorize
authorize!(:label_format_settings, current_user)
end
end
6 changes: 5 additions & 1 deletion app/helpers/dropdown/people_export.rb
Expand Up @@ -74,7 +74,11 @@ def add_last_used_format_item(parent)
end

def add_label_format_items(parent)
LabelFormat.list.for_user(user).each do |label_format|
label_formats = LabelFormat.all
if user.display_only_own_label_formats?
label_formats = label_formats.where(user: user)
end
label_formats.list.for_user(user).each do |label_format|
parent.sub_items << Item.new(label_format, export_label_format_path(label_format.id),
target: :new, class: 'export-label-format')
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/label_format.rb
Expand Up @@ -33,6 +33,8 @@ def available_page_sizes

has_many :people, foreign_key: :last_label_format_id, dependent: :nullify

belongs_to :user


validates :name, presence: true, length: { maximum: 255, allow_nil: true }
validates :page_size, inclusion: available_page_sizes
Expand Down
2 changes: 2 additions & 0 deletions app/views/label_format/settings/update.js.haml
@@ -0,0 +1,2 @@
var onlyOwn = $('#display_only_own_label_formats').get(0).checked;
// do something?
14 changes: 11 additions & 3 deletions app/views/label_formats/index.html.haml
Expand Up @@ -7,9 +7,17 @@

#main
-if can?(:manage_global, LabelFormat)
%label
%input#admin_toggle{ type: 'checkbox', data: {hide: 'admin_labels'} }
= I18n.t('label_formats.see_own_labels')
= check_box_tag(:display_only_own_label_formats,
true,
current_user.display_only_own_label_formats,
id: 'display_only_own_label_formats',
class: 'switcher',
data: { remote: true,
url: label_format_settings_path,
method: :put })
%label{for: 'display_only_own_label_formats'}
&nbsp;
%strong= t('label_formats.see_own_labels')

%h2= I18n.t('label_formats.own_labels')
= render 'list'
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Expand Up @@ -176,7 +176,11 @@

resources :qualification_kinds

resources :label_formats
resources :label_formats do
collection do
resource :settings, controller: 'label_format/settings', as: 'label_format_settings'
end
end

resources :custom_contents, only: [:index, :edit, :update]
get 'custom_contents/:id' => 'custom_contents#edit'
Expand Down
@@ -0,0 +1,5 @@
class AddDisplayOnlyOwnLabelFormatsToPeople < ActiveRecord::Migration
def change
add_column :people, :display_only_own_label_formats, :boolean, default: false
end
end

0 comments on commit 1c88aba

Please sign in to comment.