Implement role authorization

This commit is contained in:
Stella Rouzi 2014-08-12 11:51:59 +03:00
parent 6755328c4c
commit e2fb434dc7
122 changed files with 1386 additions and 751 deletions

View file

@ -14,8 +14,11 @@
= commercial.commercial_type
.flexvideo
= render partial: 'shared/media_item', locals: { commercial_type: commercial.commercial_type, commercial_id: commercial.commercial_id }
= link_to 'Edit', edit_admin_conference_commercial_path(@conference.short_title, commercial.id), class: 'btn btn-primary'
= link_to 'Delete', admin_conference_commercial_path(@conference.short_title, commercial.id),
method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'
%br
- if can? :update, commercial
= link_to 'Edit', edit_admin_conference_commercial_path(@conference.short_title, commercial.id), class: 'btn btn-primary'
- if can? :destroy, commercial
= link_to 'Delete', admin_conference_commercial_path(@conference.short_title, commercial.id),
method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'
- if can? :create, @conference.commercials.new
%br
= link_to 'New Commercial', new_admin_conference_commercial_path, class: 'btn btn-primary'

View file

@ -0,0 +1,29 @@
.roles{ id: 'myroles' }
- unless @role.blank?
%p.text-muted
= @role.first.description
%hr
.row
.col-md-6
= semantic_form_for(:user, url: add_user_admin_conference_path(@conference.short_title, role: @selected), remote: true) do |f|
%h4
= f.input :email, label: "Add role '#{@selected}' to user: ", placeholder: "User's email"
= f.action :submit, as: :button, label: "Add User", button_html: {value: 'Add', class: 'btn btn-primary'}
.row
.col-md-12
%h3 Users with role #{@selected}
%table.table.table-striped.table-bordered.table-hover
%thead
%th ID
%th Name
%th Email
%tbody
- @role_users[@selection].each do |user|
%tr
%td
= link_to remove_user_admin_conference_path(@conference.short_title, user: user, role: @selected), method: :delete, remote: true, title: 'Remove user' do
%i{class: 'fa fa-times'}
= user.id
%td= user.name
%td= user.email

View file

@ -8,25 +8,49 @@
= conference_progress['process'] + '%'
%li{'class'=>class_for_todo(conference_progress['registration'])}
%span{'class'=>icon_for_todo(conference_progress['registration'])}
= link_to 'Set up registration period', edit_admin_conference_path(conference_progress['short_title'], :anchor => 'conference-end-datepicker')
- if can? :update, @conference.registrations.build
= link_to 'Set up registration period', edit_admin_conference_path(conference_progress['short_title'], :anchor => 'conference-end-datepicker')
- else
Set up registration period
%li{'class'=>class_for_todo(conference_progress['cfp'])}
%span{'class'=>icon_for_todo(conference_progress['cfp'])}
= link_to 'Set up call for papers', admin_conference_callforpapers_path(conference_progress['short_title'])
- if can? :update, CallForPapers.new(conference_id: @conference.id)
= link_to 'Set up call for papers', admin_conference_callforpapers_path(conference_progress['short_title'])
- else
Set up call for papers
%li{'class'=>class_for_todo(conference_progress['venue'])}
%span{'class'=>icon_for_todo(conference_progress['venue'])}
= link_to 'Add venue', admin_conference_venue_info_path(conference_progress['short_title'])
- if can? :update, @conference.venue
= link_to 'Add venue', admin_conference_venue_info_path(conference_progress['short_title'])
- else
Add venue
%li{'class'=>class_for_todo(conference_progress['rooms'])}
%span{'class'=>icon_for_todo(conference_progress['rooms'])}
= link_to 'Add rooms', admin_conference_rooms_path(conference_progress['short_title'])
- if can? :update, @conference.rooms.build
= link_to 'Add rooms', admin_conference_rooms_path(conference_progress['short_title'])
- else
Add rooms
%li{'class'=>class_for_todo(conference_progress['tracks'])}
%span{'class'=>icon_for_todo(conference_progress['tracks'])}
= link_to 'Add tracks', admin_conference_tracks_path(conference_progress['short_title'])
- if can? :update, @conference.tracks.build
= link_to 'Add tracks', admin_conference_tracks_path(conference_progress['short_title'])
- else
Add tracks
%li{'class'=>class_for_todo(conference_progress['event_types'])}
%span{'class'=>icon_for_todo(conference_progress['event_types'])}
= link_to 'Add event types', admin_conference_eventtypes_path(conference_progress['short_title'])
- if can? :update, @conference.event_types.build
= link_to 'Add event types', admin_conference_event_types_path(conference_progress['short_title'])
- else
Add event types
%li{'class'=>class_for_todo(conference_progress['difficulty_levels'])}
%span{'class'=>icon_for_todo(conference_progress['difficulty_levels'])}
= link_to 'Add difficulty levels', admin_conference_difficulty_levels_path(conference_progress['short_title'])
- if can? :update, @conference.difficulty_levels.build
= link_to 'Add difficulty levels', admin_conference_difficulty_levels_path(conference_progress['short_title'])
- else
Add difficulty levels
%li{class: class_for_todo(conference_progress['make_conference_public'])}
%span{'class'=>icon_for_todo(conference_progress['make_conference_public'])}
= link_to 'Make Splash Page Public for Visitors', edit_admin_conference_path(conference_progress['short_title'])
- if can? :update, @conference
= link_to 'Make Splash Page Public for Visitors', edit_admin_conference_path(conference_progress['short_title'])
- else
Make Splash Page Public for Visitors

View file

@ -0,0 +1,22 @@
.row
.col-md-6
= semantic_form_for(:user, url: roles_admin_conference_path(@conference.short_title), remote: true) do |f|
%h4
= f.input :roles, collection: @roles, label: 'Show users for role: '
= render partial: 'roles'
:javascript
$("#user_roles_input").change(function () {
var url = document.forms[0].action;
var selected_role = $(this).find('option:selected').attr('value');
$.ajax({
url: url,
type: "POST",
data: {user: { roles: selected_role } },
dataType: "script"
});
});

View file

@ -0,0 +1 @@
$('#myroles').html("<%= escape_javascript(render partial: 'roles').html_safe %>");

View file

@ -1,5 +1,5 @@
.row
.col-md-8
= semantic_form_for(@conference, url: admin_conference_eventtypes_path(@conference.short_title, @conference.event_types)) do |f|
= semantic_form_for(@conference, url: admin_conference_event_types_path(@conference.short_title, @conference.event_types)) do |f|
= dynamic_association :event_types, "Event Types", f
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}

View file

@ -18,11 +18,11 @@
= ','
= label_tag dom_id(q), "Answers: #{q.answers.map {|a| a.title}.join(', ')}"
%td= link_to 'Edit', edit_admin_conference_question_path(@conference.short_title, q),
class: 'btn btn-primary',
disabled: q.global == true && !has_role?(current_user, 'Admin')
- if can? :update, q
%td= link_to 'Edit', edit_admin_conference_question_path(@conference.short_title, q),
class: 'btn btn-primary', disabled: q.global == true
%td= link_to 'Delete', admin_conference_question_path(@conference.short_title, q),
method: :delete, remote: true, class: 'btn btn-danger',
confirm: "Delete question '#{q.title}'?",
disabled: q.global == true && !has_role?(current_user, "Admin")
- if can? :destroy, q
%td= link_to 'Delete', admin_conference_question_path(@conference.short_title, q),
method: :delete, remote: true, class: 'btn btn-danger',
confirm: "Delete question '#{q.title}'?", disabled: q.global == true

View file

@ -7,9 +7,11 @@
= "(#{@registrations.length})"
= " - Attended (#{@attended})"
.btn-group.pull-right
= link_to "New", new_admin_conference_registration_path(@conference.short_title), :class => "btn btn-default"
= link_to "Export PDF", admin_conference_registrations_path(@conference.short_title, :format => :pdf), :class => "btn btn-default"
= link_to "Export XLS", {:format => :xlsx}, :class => "btn btn-default"
- if can? :create, Registration
= link_to "New", new_admin_conference_registration_path(@conference.short_title), :class => "btn btn-default"
- if can? :read, Registration
= link_to "Export PDF", admin_conference_registrations_path(@conference.short_title, :format => :pdf), :class => "btn btn-default"
= link_to "Export XLS", {:format => :xlsx}, :class => "btn btn-default"
%table.table.table-bordered.table-striped.table-hover#registrations
%thead
%th
@ -21,7 +23,7 @@
%th
%th
%th
- counter = 0
- counter = 0
- @registrations.each do |registration|
%tr
%td
@ -33,7 +35,7 @@
- if registration.supporter_level && registration.supporter_level.title != 'Free'
%p{:style => "color:red"}
= registration.supporter_level.title
-elsif field == 'attended'
= link_to "#{registration.send(field.to_sym)}", admin_conference_registrations_change_field_path(@conference.short_title, :id => registration.id, :view_field => "#{field}"), :method => :patch, ":#{field}" => registration.send(field.to_sym), :class => "btn btn-success"
@ -64,11 +66,11 @@
"bLengthChange": false
} );
} );
function toggle(rowid) {
if( document.getElementById(rowid).style.display=='none' ){
document.getElementById(rowid).style.display = '';
}else{
document.getElementById(rowid).style.display = 'none';
}
};
};

View file

@ -1,8 +1,14 @@
= semantic_form_for [:admin, @user] do |f|
= f.inputs "Basic Information" do
= f.inputs 'Basic Information' do
= f.input :is_admin, hint: 'An admin can create a new conference, manage users and make other users admins.'
= f.input :name, :as => :string
= f.input :email
= f.input :affiliation, :as => :string
= f.input :biography, :input_html => {:rows => 10}
= f.actions do
= f.action :submit, :button_html => {:class => "btn btn-primary"}
= f.input :affiliation, as: :string
= f.input :biography, input_html: { rows: 5, "onkeyup" => "word_count(this, 'biography-count', 150)" }
You have used
%span#biography-count #{@user.biography_word_count}
words. Biographies are limited to 150 words.
%br
%br
= f.actions do
= f.action :submit, button_html: { class: 'btn btn-primary' }

View file

@ -5,7 +5,7 @@
- if @users
= "(#{@users.length})"
= link_to "New User", new_admin_user_path, :class => "btn btn-success pull-right"
= link_to "New User", new_admin_user_path, class: 'btn btn-success pull-right'
.well
%table.table.table-striped.table-bordered.table-hover#users
%thead
@ -18,7 +18,7 @@
%th
%b Name
%th
%b # of Conference Registrations
%b Attended Conferences
%th
%b Roles
%th
@ -38,39 +38,24 @@
%td
= user.name
%td
= user.registrations.count
= user.registrations.where(attended: true).count
%td
.modal.fade{:id => "user-role-selection-#{user.id}", "role" => "dialog", "aria-hidden" => "true"}
.modal-dialog
.modal-content
.modal-header
%button{"type"=>"button", :class=>"close", "data-dismiss"=>"modal", "aria-hidden"=>"true"}
×
%h3{:id => "role-selector-header-#{user.id}"}
Modifying Roles
.modal-body
- if current_user == user
You cannot modify your own role!
%br
%button{:class=> "btn btn-danger", "data-dismiss"=> "modal", "aria-hidden"=>"true"}
Cancel
- else
= "Give #{user.name} (#{user.email}) the following roles:"
= semantic_form_for(user, :url => admin_user_path(user), :method => :put) do |f|
= f.input :roles, :label => false
%button{:class=> "btn btn-danger", "data-dismiss"=> "modal", "aria-hidden"=>"true"}
Cancel
= f.action :submit, :as => :button, :button_html => {:value => "Save", :class => "btn btn-primary"}
=link_to "#{user.roles.map { |role| role.name }.join ', '}", "#", "data-toggle" => "modal", "data-target" => "#user-role-selection-#{user.id}",id: "user-modify-role-#{user.id}"
%td
= link_to "Edit", edit_admin_user_path(user)
%td
= link_to "View", admin_user_path(user)
%td
- if current_user.id == user.id or user.role_ids.include? 3
=link_to 'Delete',admin_user_path(user), :method => :delete , :data => {:confirm => 'Are you sure ?'}, :disabled => true,:class => "btn btn-primary disabled btn-danger",:role => "button"
- else
=link_to 'Delete',admin_user_path(user), :method=> :delete , :data=> {:confirm => 'Are you sure ?'},:class => "btn btn-primary btn-danger"
- unless user.show_roles.blank?
= user.show_roles.first(2).map { |x| x[0].titleize + ' ' + x[1] }.join ', '
- if user.show_roles.count > 2
= '...'
- if can? :show, user
%td
= link_to "View", admin_user_path(user), class: 'btn btn-success'
- if can? :update, user
%td
= link_to "Edit", edit_admin_user_path(user), class: 'btn btn-primary'
- if can? :destroy, user
%td
- if current_user.id == user.id or user.role_ids.include? 3
=link_to 'Delete',admin_user_path(user), :method => :delete , :data => {:confirm => 'Are you sure ?'}, :disabled => true,:class => "btn btn-primary disabled btn-danger",:role => "button"
- else
=link_to 'Delete',admin_user_path(user), :method=> :delete , :data=> {:confirm => 'Are you sure ?'},:class => "btn btn-primary btn-danger"
:javascript

View file

@ -1,7 +1,11 @@
%table.table
- @show_attributes.each do |attr|
%tr
%td
%td{style: 'width:20%'}
%b
= attr.capitalize.gsub('_', ' ')
%td= @user.send(attr)
- if attr == 'roles'
%td
= @user.show_roles.map { |x| x[0].titleize + ' ' + x[1] }.join ', '
- else
%td= @user.send(attr)