Skip to content

Commit

Permalink
Rename Roster::Role to Capability
Browse files Browse the repository at this point in the history
This does not affect other roles such as homepage link roles, and
notification roles, but only the roles attached to positions.  These
weren't actually roles, so the name brings them more in line with their
actual purpose (capabilities), and reduces confusion.

This is another wide, but not deep, change.

Issue #185: Change entity names
  • Loading branch information
Frank Duncan committed Jun 16, 2020
1 parent 6825d00 commit d08bcc4
Show file tree
Hide file tree
Showing 67 changed files with 250 additions and 240 deletions.
6 changes: 3 additions & 3 deletions app/admin/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def initialize(region)

def initialize(person)

is_config = person.has_role 'region_config'
is_config = person.has_capability 'region_config'

if is_config # is site manager
can [:read, :update], Roster::Region
can :manage, Roster::ShiftTerritory
can :manage, Roster::Position
can :manage, Roster::CellCarrier
can :manage, Roster::Person
can :manage, Roster::Role
can :manage, Roster::Capability

can :manage, Scheduler::DispatchConfig
can :manage, Scheduler::Shift
Expand Down Expand Up @@ -46,7 +46,7 @@ def initialize(person)
can :manage, :all
end

is_admin = person.has_role 'region_admin'
is_admin = person.has_capability 'region_admin'
if is_admin
region = person.region_id
can :read, [Roster::Person, Roster::ShiftTerritory, Roster::Position], region_id: region
Expand Down
30 changes: 30 additions & 0 deletions app/admin/roster/capabilities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ActiveAdmin.register Roster::Capability, as: 'Capability' do
menu parent: 'Roster'

controller do
def resource_params
[params.fetch(resource_request_name, {}).permit(:name, :grant_name)]
end

def collection
@coll ||= apply_scopes(super).preload{[capability_memberships.position, capability_memberships.capability_scopes]}
end
end

index do
column :name
column :grant_name
column :positions do |capability|
safe_join(capability.capability_memberships.map{|pm| "#{pm.position.name if pm.position} (#{pm.capability_scopes.map(&:scope).join ','})"}, tag(:br))
end
actions
end

form do |f|
f.inputs
f.actions
end

filter :name
filter :grant_name
end
12 changes: 6 additions & 6 deletions app/admin/roster/positions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
column :name
#column :vc_regex_raw
column :hidden
column :roles do |pos|
safe_join(pos.role_memberships.map(&:display_name), tag(:br))
column :capabilities do |pos|
safe_join(pos.capability_memberships.map(&:display_name), tag(:br))
end
actions
end
Expand Down Expand Up @@ -45,16 +45,16 @@ def update

def resource_params
[params.fetch(resource_request_name, {}).permit(:name, :abbrev, :vc_regex_raw, :hidden, :region_id, :watchfire_role,
:role_memberships_attributes => [:id, :_destroy, :role_id, role_scopes_attributes: [:scope, :id, :_destroy]])]
:capability_memberships_attributes => [:id, :_destroy, :capability_id, capability_scopes_attributes: [:scope, :id, :_destroy]])]
end
end

form do |f|
f.inputs
f.inputs do
f.has_many :role_memberships, allow_destroy: true do |f|
f.input :role
f.has_many :role_scopes, allow_destroy: true do |f|
f.has_many :capability_memberships, allow_destroy: true do |f|
f.input :capability
f.has_many :capability_scopes, allow_destroy: true do |f|
f.input :scope
end
end
Expand Down
30 changes: 0 additions & 30 deletions app/admin/roster/roles.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/admin/scheduler/people.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
table_for person.position_memberships do
column( :name) { |rec| rec.position && rec.position.name }
column(:persistent) { |rec| rec.persistent ? 'Yes' : ''}
column(:roles) {|rec| safe_join rec.position.role_memberships.map(&:display_name), tag(:br)}
column(:capabilities) {|rec| safe_join rec.position.capability_memberships.map(&:display_name), tag(:br)}
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/admin/scheduler/shifts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
filter :region
filter :name
filter :abbrev
filter :dispatch_role
filter :shift_ends

scope :all do |shifts|
Expand Down Expand Up @@ -94,7 +93,7 @@

controller do
def resource_params
[params.fetch(resource_request_name, {}).permit(:name, :abbrev, :shift_category_id, :max_signups, :shift_territory_id, :ordinal, :spreadsheet_ordinal, :dispatch_role, :shift_begins, :shift_ends, :signups_frozen_before, :min_desired_signups, :max_advance_signup, :min_advance_signup, :ignore_shift_territory, :vc_hours_type, :show_in_dispatch_console, :exclusive, :position_ids => [], :shift_time_ids => [])]
[params.fetch(resource_request_name, {}).permit(:name, :abbrev, :shift_category_id, :max_signups, :shift_territory_id, :ordinal, :spreadsheet_ordinal, :shift_begins, :shift_ends, :signups_frozen_before, :min_desired_signups, :max_advance_signup, :min_advance_signup, :ignore_shift_territory, :vc_hours_type, :show_in_dispatch_console, :exclusive, :position_ids => [], :shift_time_ids => [])]
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def inactive

expose(:homepage_links) {
links = HomepageLink.for_region(current_region).order{[group_ordinal.asc, ordinal.asc]}.includes{roles}.to_a
scopes = current_user.scope_for_role 'homepage_link'
scopes = current_user.scope_for_capability 'homepage_link'
links.select{|l| l.role_ids.blank? || (l.roles.map(&:role_scope) & scopes).present? }.group_by(&:group)
}
end
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ApplicationHelper
def has_admin_dashboard_access
@_admin_access = current_user && (current_user.has_role('region_config') || current_user.has_role('region_admin'))
@_admin_access = current_user && (current_user.has_capability('region_config') || current_user.has_capability('region_admin'))
end

def current_messages
Expand Down
20 changes: 10 additions & 10 deletions app/models/incidents/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class Incidents::Ability
def initialize(person)
@person = person
@region_scope = [@person.region_id] + Roster::Region.with_incidents_delegate_region_value(@person.region_id).ids
is_admin = person.has_role 'incidents_admin'
is_admin = person.has_capability 'incidents_admin'

scopes
personal

dispatch_console if is_admin or person.has_role 'dispatch_console'
create_incident if person.has_role 'create_incident'
submit_incident_report if is_admin or person.has_role 'submit_incident_report'
cas_admin if is_admin or person.has_role 'cas_admin'
incident_details if is_admin or person.has_role 'incident_details'
cas_details if is_admin or person.has_role 'cas_details'
see_responses if is_admin or person.has_role 'see_responses'
approve_iir if is_admin or person.has_role 'approve_iir'
dispatch_console if is_admin or person.has_capability 'dispatch_console'
create_incident if person.has_capability 'create_incident'
submit_incident_report if is_admin or person.has_capability 'submit_incident_report'
cas_admin if is_admin or person.has_capability 'cas_admin'
incident_details if is_admin or person.has_capability 'incident_details'
cas_details if is_admin or person.has_capability 'cas_details'
see_responses if is_admin or person.has_capability 'see_responses'
approve_iir if is_admin or person.has_capability 'approve_iir'
incidents_admin if is_admin

read_only if ENV['READ_ONLY']
Expand Down Expand Up @@ -92,7 +92,7 @@ def see_responses
end

def dispatch_console
scopes = person.scope_for_role('dispatch_console').map(&:to_i)
scopes = person.scope_for_capability('dispatch_console').map(&:to_i)
can :dispatch_console, Incidents::Scope, {id: scopes}


Expand Down
4 changes: 2 additions & 2 deletions app/models/roster/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def initialize(person)
end
end

if person.has_role 'region_dat_admin'
if person.has_capability 'region_dat_admin'
can [:read, :update], Roster::Person, region_id: person.region_id
end

admin_shift_territory_ids = person.scope_for_role('shift_territory_dat_admin')
admin_shift_territory_ids = person.scope_for_capability('shift_territory_dat_admin')
if admin_shift_territory_ids.present? # is dat shift_territory admin
can [:read, :update], Roster::Person, shift_territory_memberships: {shift_territory_id: admin_shift_territory_ids}
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/roster/capability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Roster::Capability < ActiveRecord::Base
has_many :capability_memberships, class_name: 'Roster::CapabilityMembership'
validates :name, :grant_name, presence: true

def display_name
"#{name} (#{grant_name})"
end
end
12 changes: 12 additions & 0 deletions app/models/roster/capability_membership.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Roster::CapabilityMembership < ActiveRecord::Base
belongs_to :position
belongs_to :capability
has_many :capability_scopes

accepts_nested_attributes_for :capability_scopes, allow_destroy: true
validates :position, :capability, presence: true

def display_name
"#{capability.try :name} - (#{capability_scopes.map(&:scope).join ','})"
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Roster::RoleScope < ActiveRecord::Base
belongs_to :role_membership
class Roster::CapabilityScope < ActiveRecord::Base
belongs_to :capability_membership

def scope
val = super
Expand Down
22 changes: 11 additions & 11 deletions app/models/roster/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Roster::Person < ActiveRecord::Base

has_many :position_memberships, class_name: 'Roster::PositionMembership'
has_many :positions, class_name: 'Roster::Position', through: :position_memberships
has_many :role_memberships, class_name: 'Roster::RoleMembership', through: :positions
has_many :capability_memberships, class_name: 'Roster::CapabilityMembership', through: :positions

belongs_to :home_phone_carrier, class_name: 'Roster::CellCarrier'
belongs_to :cell_phone_carrier, class_name: 'Roster::CellCarrier'
Expand All @@ -26,8 +26,8 @@ class Roster::Person < ActiveRecord::Base

scope :for_region, ->(region){where{region_id == region}}

scope :has_role_for_scope, -> role_name, scope {
joins{roles.role_scopes.outer}.where{(roles.grant_name == role_name) & ((roles.role_scopes.scope == nil) | (roles.role_scopes.scope == scope.to_s))}
scope :has_capability_for_scope, -> capability_name, scope {
joins{capabilities.capability_scopes.outer}.where{(capabilities.grant_name == capability_name) & ((capabilities.capability_scopes.scope == nil) | (capabilities.capability_scopes.scope == scope.to_s))}
}

scope :include_carriers, -> {
Expand Down Expand Up @@ -68,19 +68,19 @@ def self.with_phone_number(number)

accepts_nested_attributes_for :shift_territory_memberships, :position_memberships, allow_destroy: true

def has_role(grant_name)
roles_with_scopes.select{|mem| mem.role.grant_name == grant_name}.present?
def has_capability(grant_name)
capabilities_with_scopes.select{|mem| mem.capability.grant_name == grant_name}.present?
end

def scope_for_role(grant_name)
roles_with_scopes.select{|mem| mem.role.grant_name == grant_name}
.flat_map{|mem| mem.role_scopes.map(&:scope) }
def scope_for_capability(grant_name)
capabilities_with_scopes.select{|mem| mem.capability.grant_name == grant_name}
.flat_map{|mem| mem.capability_scopes.map(&:scope) }
.flat_map{ |scope| scope == 'shift_territory_ids' ? shift_territory_ids : scope}
.compact.uniq
end

def roles_with_scopes
@roles_with_scopes ||= role_memberships.includes{[role, role_scopes]}.joins{role_scopes.outer}.references(:role)
def capabilities_with_scopes
@capabilities_with_scopes ||= capability_memberships.includes{[capability, capability_scopes]}.joins{capability_scopes.outer}.references(:capability)
end

def primary_shift_territory
Expand Down Expand Up @@ -191,6 +191,6 @@ def profile_complete?
end

def is_active?
vc_is_active or has_role 'always_active'
vc_is_active or has_capability 'always_active'
end
end
4 changes: 2 additions & 2 deletions app/models/roster/position.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ class Roster::Position < ActiveRecord::Base
has_many :position_memberships
has_many :people, through: :position_memberships, class_name: 'Roster::Person'

has_many :role_memberships, class_name: 'Roster::RoleMembership'
has_many :capability_memberships, class_name: 'Roster::CapabilityMembership'

validates_presence_of :region, :name

scope :visible, ->{where{hidden != true}}

accepts_nested_attributes_for :role_memberships, allow_destroy: true
accepts_nested_attributes_for :capability_memberships, allow_destroy: true

def vc_regex
@compiled_regex ||= (vc_regex_raw.present? && Regexp.new(vc_regex_raw))
Expand Down
2 changes: 1 addition & 1 deletion app/models/roster/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Roster::Region < ActiveRecord::Base
has_many :shift_territories
has_many :positions
has_many :people
has_many :roles
has_many :capabilities

has_one :vc_import_data

Expand Down
8 changes: 0 additions & 8 deletions app/models/roster/role.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/models/roster/role_membership.rb

This file was deleted.

10 changes: 5 additions & 5 deletions app/models/scheduler/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ def initialize(person)

personal

shift_territory_ids = person.scope_for_role('shift_territory_roster')
shift_territory_ids = person.scope_for_capability('shift_territory_roster')
shift_territory_roster(shift_territory_ids) if shift_territory_ids.present?

admin_shift_territory_ids = person.scope_for_role('shift_territory_scheduler')
if person.has_role 'region_scheduler'
admin_shift_territory_ids = person.scope_for_capability('shift_territory_scheduler')
if person.has_capability 'region_scheduler'
admin_shift_territory_ids.concat person.region.shift_territory_ids
end
admin_shift_territory_ids.uniq!
scheduler admin_shift_territory_ids if admin_shift_territory_ids.present?

region_dat_admin person.region_id if person.has_role 'region_dat_admin'
region_dat_admin person.region_id if person.has_capability 'region_dat_admin'

dat_admin_shift_territories = person.scope_for_role('shift_territory_dat_admin')
dat_admin_shift_territories = person.scope_for_capability('shift_territory_dat_admin')
shift_territory_dat_admin dat_admin_shift_territories if dat_admin_shift_territories.present? # is dat shift_territory admin

read_only if ENV['READ_ONLY']
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/people/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ end
json.positions resource.positions do |position|
json.name position.name
end
json.roles resource.positions.includes{[role_memberships.role_scopes, role_memberships.role]}.flat_map{|p| p.role_memberships.map{|rm| rm.role.grant_name } }
json.capabilities resource.positions.includes{[capability_memberships.capability_scopes, capability_memberships.capability]}.flat_map{|p| p.capability_memberships.map{|rm| rm.capability.grant_name } }
6 changes: 3 additions & 3 deletions app/views/roster/people/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ json.phones resource.phone_order
json.region resource.region, :name, :short_name, :id
json.positions resource.positions, :name, :abbrev, :id
json.shift_territories resource.shift_territories, :name, :abbrev, :id
json.roles resource.role_memberships do |membership|
json.capabilities resource.capability_memberships do |membership|
json.extract! membership, :name
json.extract! membership.role, :grant_name
json.role_scopes membership.role_scopes.map(&:scope) if membership.role_scopes.present?
json.extract! membership.capability, :grant_name
json.capability_scopes membership.capability_scopes.map(&:scope) if membership.capability_scopes.present?
end
Loading

0 comments on commit d08bcc4

Please sign in to comment.