parent
06308e1293
commit
a06120db10
@ -0,0 +1,64 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Roles |
||||
class BaseContract < ::ModelContract |
||||
attribute :name |
||||
attribute :assignable |
||||
|
||||
def assignable_permissions |
||||
if model.is_a?(GlobalRole) |
||||
assignable_global_permissions |
||||
else |
||||
assignable_member_permissions |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def assignable_member_permissions |
||||
permissions_to_remove = case model.builtin |
||||
when Role::BUILTIN_NON_MEMBER |
||||
[Redmine::AccessControl.members_only_permissions] |
||||
when Role::BUILTIN_ANONYMOUS |
||||
[Redmine::AccessControl.loggedin_only_permissions] |
||||
else |
||||
[] |
||||
end |
||||
|
||||
Redmine::AccessControl.permissions - |
||||
Redmine::AccessControl.public_permissions - |
||||
Redmine::AccessControl.global_permissions - |
||||
permissions_to_remove |
||||
end |
||||
|
||||
def assignable_global_permissions |
||||
Redmine::AccessControl.global_permissions |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,47 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Roles |
||||
class CreateContract < BaseContract |
||||
attribute :type |
||||
|
||||
def validate |
||||
type_in_allowed |
||||
|
||||
super |
||||
end |
||||
|
||||
private |
||||
|
||||
def type_in_allowed |
||||
unless [Role.name, GlobalRole.name].include?(model.type) |
||||
errors.add(:type, :inclusion) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,32 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Roles |
||||
class UpdateContract < BaseContract |
||||
end |
||||
end |
@ -0,0 +1,63 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Roles::CreateService < ::BaseServices::Create |
||||
include Roles::NotifyMixin |
||||
|
||||
private |
||||
|
||||
def create(params) |
||||
copy_workflow_id = params.delete(:copy_workflow_from) |
||||
|
||||
super_call = super |
||||
|
||||
if super_call.success? |
||||
copy_workflows(copy_workflow_id, super_call.result) |
||||
|
||||
notify_changed_roles(:added, super_call.result) |
||||
end |
||||
|
||||
super_call |
||||
end |
||||
|
||||
def new_instance(params) |
||||
if params.delete(:global_role) |
||||
GlobalRole.new |
||||
else |
||||
super |
||||
end |
||||
end |
||||
|
||||
def copy_workflows(copy_workflow_id, role) |
||||
if copy_workflow_id.present? && (copy_from = Role.find_by(id: copy_workflow_id)) |
||||
role.workflows.copy_from_role(copy_from) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Roles::NotifyMixin |
||||
private |
||||
|
||||
def notify_changed_roles(action, changed_role) |
||||
OpenProject::Notifications.send(:roles_changed, action: action, role: changed_role) |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Roles |
||||
class SetAttributesService < ::BaseServices::SetAttributes |
||||
def set_default_attributes |
||||
model.permissions = Role.non_member.permissions if model.permissions.nil? || model.permissions.empty? |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Roles::UpdateService < ::BaseServices::Update |
||||
include Roles::NotifyMixin |
||||
|
||||
private |
||||
|
||||
def after_safe |
||||
notify_changed_roles(:updated, model) |
||||
end |
||||
end |
@ -1,65 +0,0 @@ |
||||
<%#-- copyright |
||||
OpenProject Global Roles Plugin |
||||
|
||||
Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF) |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
version 3. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
++#%> |
||||
|
||||
<%= render :partial => 'shared/global_roles_header' %> |
||||
|
||||
<% roles ||= nil %> |
||||
|
||||
<%= error_messages_for :role %> |
||||
<div class="form--field -required"> |
||||
<%= f.text_field :name, required: true, container_class: '-slim' %> |
||||
</div> |
||||
<div class="form--field"> |
||||
<% if role.new_record? %> |
||||
<%= styled_label_tag :global_role, l(:label_global_role) %> |
||||
<div class="form--field-container"> |
||||
<%= styled_check_box_tag("global_role", "1", role.is_a?(GlobalRole))%> |
||||
</div> |
||||
<% else %> |
||||
<%= styled_label_tag :unchangeable, "#{l(:label_role_type)} #{l(:label_not_changeable)}" %> |
||||
<div class="form--field-container"> |
||||
<%= (role.is_a?(GlobalRole) ? l(:label_global_role) : l(:label_member_role))%> |
||||
</div> |
||||
<% end %> |
||||
</div> |
||||
|
||||
<% if role.new_record? || role.is_a?(GlobalRole) %> |
||||
<div id="global_attributes" style="display:none"> |
||||
<%= render partial: "global_attributes", locals: { f: f, role: role, roles: roles&.select {|r| r.is_a?(GlobalRole)} }%> |
||||
</div> |
||||
<% end %> |
||||
|
||||
<% if role.new_record? || !role.is_a?(GlobalRole) %> |
||||
<div id="member_attributes"> |
||||
<%= render partial: "member_attributes", locals: { f: f, role: role, roles: roles&.select {|r| !r.is_a?(GlobalRole)} }%> |
||||
</div> |
||||
<% end %> |
||||
|
||||
<% if role.new_record? || role.is_a?(GlobalRole) %> |
||||
<div id="global_permissions" style=<%= role.new_record? && !role.is_a?(GlobalRole) ? "display:none" : ""%> > |
||||
<%= render partial: "permissions", locals: {permissions: @global_permissions, role: role, showGlobalRole: true }%> |
||||
</div> |
||||
<% end %> |
||||
<% if role.new_record? || !role.is_a?(GlobalRole) %> |
||||
<div id="member_permissions" style=<%= role.new_record? && role.is_a?(GlobalRole) ? "display:none" : ""%>> |
||||
<%= render partial: "permissions", locals: {permissions: @permissions, role: role, showGlobalRole: false }%> |
||||
</div> |
||||
<% end %> |
||||
|
@ -1,31 +0,0 @@ |
||||
<%#-- copyright |
||||
OpenProject Global Roles Plugin |
||||
|
||||
Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF) |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
version 3. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
++#%> |
||||
|
||||
<% html_title l(:label_administration), "#{l(:label_edit)} #{Role.model_name.human} #{@role.name}" %> |
||||
|
||||
<% local_assigns[:additional_breadcrumb] = @role.name %> |
||||
<%= breadcrumb_toolbar @role.name %> |
||||
|
||||
<%= labelled_tabular_form_for @role, :url => { :action => 'update' }, :html => {:id => 'role_form'}, :as => :role do |f| %> |
||||
<%= hidden_field_tag :id, @role.id %> |
||||
<%= render partial: 'form', locals: { f: f , role: @role } %> |
||||
<br/> |
||||
<%= styled_button_tag l(:button_save), class: '-with-icon icon-checkmark' %> |
||||
<% end %> |
@ -1,105 +0,0 @@ |
||||
<%#-- copyright |
||||
OpenProject Global Roles Plugin |
||||
|
||||
Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF) |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
version 3. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
++#%> |
||||
<% html_title l(:label_administration), l("label_role_plural") %> |
||||
<%= toolbar title: Role.model_name.human(count: 2) do %> |
||||
<li class="toolbar-item"> |
||||
<%= link_to({ action: 'new'}, |
||||
{ class: 'button -alt-highlight', |
||||
aria: {label: t(:label_role_new)}, |
||||
title: t(:label_role_new)}) do %> |
||||
<%= op_icon('button--icon icon-add') %> |
||||
<span class="button--text"><%= Role.model_name.human %></span> |
||||
<% end %> |
||||
</li> |
||||
<% end %> |
||||
|
||||
<div class="generic-table--container"> |
||||
<div class="generic-table--results-container"> |
||||
<table class="generic-table"> |
||||
<colgroup> |
||||
<col highlight-col> |
||||
<col highlight-col> |
||||
<col highlight-col> |
||||
<col> |
||||
</colgroup> |
||||
<thead> |
||||
<tr> |
||||
<th> |
||||
<div class="generic-table--sort-header-outer"> |
||||
<div class="generic-table--sort-header"> |
||||
<span> |
||||
<%= Role.model_name.human %> |
||||
</span> |
||||
</div> |
||||
</div> |
||||
</th> |
||||
<th> |
||||
<div class="generic-table--sort-header-outer"> |
||||
<div class="generic-table--sort-header"> |
||||
<span> |
||||
<%=l(:label_global)%> |
||||
</span> |
||||
</div> |
||||
</div> |
||||
</th> |
||||
<th> |
||||
<div class="generic-table--sort-header-outer"> |
||||
<div class="generic-table--sort-header"> |
||||
<span> |
||||
<%=l(:button_sort)%> |
||||
</span> |
||||
</div> |
||||
</div> |
||||
</th> |
||||
<th><div class="generic-table--empty-header"></div></th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<% for role in @roles %> |
||||
<tr> |
||||
<td> |
||||
<%= content_tag(role.builtin? ? 'em' : 'span', link_to(role.name, :action => 'edit', :id => role)) %> |
||||
</td> |
||||
<td> |
||||
<%= icon_wrapper('icon-context icon-checkmark', I18n.t(:general_text_Yes)) if role.is_a?(GlobalRole) %> |
||||
</td> |
||||
<td> |
||||
<% unless role.builtin? %> |
||||
<%= reorder_links('role', {:action => 'update', :id => role}, :method => :put) %> |
||||
<% end %> |
||||
</td> |
||||
<td class="buttons"> |
||||
<%= link_to('', role_path(role), |
||||
method: :delete, |
||||
data: { confirm: l(:text_are_you_sure) }, |
||||
class: 'icon icon-delete', |
||||
title: t(:button_delete)) unless role.builtin? %> |
||||
</td> |
||||
</tr> |
||||
<% end %> |
||||
</tbody> |
||||
</table> |
||||
|
||||
</div> |
||||
</div> |
||||
|
||||
<%= pagination_links_full @roles %> |
||||
|
||||
<p><%= link_to l(:label_permissions_report), :action => 'report' %></p> |
@ -1,31 +0,0 @@ |
||||
<%#-- copyright |
||||
OpenProject Global Roles Plugin |
||||
|
||||
Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF) |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
version 3. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
++#%> |
||||
|
||||
<% html_title t(:label_administration), t(:label_role_new) %> |
||||
|
||||
<% local_assigns[:additional_breadcrumb] = t(:label_role_new) %> |
||||
<%= breadcrumb_toolbar t(:label_role_new) %> |
||||
|
||||
<%= labelled_tabular_form_for @role, :url => { :action => 'create' }, :html => {:id => 'role_form'}, :as => :role do |f| %> |
||||
<%= render partial: 'form', |
||||
locals: { f: f, role: @role, roles: @roles, permissions: @permissions, global_permissions: @global_permissions } %> |
||||
<br/> |
||||
<%= styled_button_tag t(:button_create), class: '-with-icon icon-checkmark' %> |
||||
<% end %> |
@ -1,46 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject Global Roles Plugin |
||||
# |
||||
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# version 3. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
#++ |
||||
|
||||
module OpenProject::GlobalRoles::Patches |
||||
module RolePatch |
||||
def self.included(base) |
||||
base.prepend InstanceMethods |
||||
|
||||
base.class_eval do |
||||
class << self |
||||
prepend ClassMethods |
||||
end |
||||
end |
||||
end |
||||
|
||||
module ClassMethods |
||||
def givable |
||||
super.where(type: 'Role') |
||||
end |
||||
end |
||||
|
||||
module InstanceMethods |
||||
def setable_permissions |
||||
setable_permissions = super |
||||
setable_permissions -= Redmine::AccessControl.global_permissions |
||||
setable_permissions |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,60 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject Global Roles Plugin |
||||
# |
||||
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# version 3. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
#++ |
||||
|
||||
module OpenProject::GlobalRoles::Patches |
||||
module RolesControllerPatch |
||||
def self.included(base) |
||||
base.prepend InstanceMethods |
||||
|
||||
base.class_eval do |
||||
before_action :define_global_permissions |
||||
end |
||||
end |
||||
|
||||
module InstanceMethods |
||||
def create |
||||
if params['global_role'] |
||||
create_global_role |
||||
else |
||||
super |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def define_global_permissions |
||||
@global_permissions = group_permissions_by_module(GlobalRole.setable_permissions) |
||||
end |
||||
|
||||
def create_global_role |
||||
@role = GlobalRole.new permitted_params.role |
||||
if @role.save |
||||
flash[:notice] = l(:notice_successful_create) |
||||
redirect_to action: 'index' |
||||
else |
||||
define_setable_permissions |
||||
@roles = Role.order(Arel.sql('builtin, position')) |
||||
render template: 'roles/new' |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
RolesController.send(:include, OpenProject::GlobalRoles::Patches::RolesControllerPatch) |
@ -1,336 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject Global Roles Plugin |
||||
# |
||||
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# version 3. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
#++ |
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') |
||||
|
||||
describe RolesController, type: :controller do |
||||
before do |
||||
allow(@controller).to receive(:check_if_login_required) |
||||
expect(@controller).to receive(:require_admin) |
||||
disable_flash_sweep |
||||
end |
||||
|
||||
after do |
||||
User.current = nil |
||||
end |
||||
|
||||
shared_examples_for 'index' do |
||||
it {expect(response).to be_successful} |
||||
it {expect(assigns(:roles)).to eql(@roles)} |
||||
it {expect(response).to render_template 'roles/index'} |
||||
end |
||||
|
||||
shared_examples_for 'global assigns' do |
||||
it {expect(assigns(:global_roles)).to eql @global_roles} |
||||
it {expect(assigns(:global_role)).to eql @global_role} |
||||
end |
||||
|
||||
shared_examples_for 'successful create' do |
||||
it {expect(response).to be_redirect} |
||||
it {expect(response).to redirect_to '/admin/roles'} |
||||
it {expect(flash[:notice]).to eql I18n.t(:notice_successful_create)} |
||||
end |
||||
|
||||
shared_examples_for 'failed create' do |
||||
it {expect(response).to be_successful} |
||||
it {expect(response).to render_template 'new'} |
||||
end |
||||
|
||||
describe 'WITH get' do |
||||
describe 'VERB', :index do |
||||
before do |
||||
mock_role_find |
||||
end |
||||
|
||||
describe 'html' do |
||||
before {get 'index'} |
||||
|
||||
it_should_behave_like 'index' |
||||
end |
||||
|
||||
describe 'xhr' do |
||||
before {get :index, xhr: true} |
||||
|
||||
it_should_behave_like 'index' |
||||
end |
||||
end |
||||
|
||||
describe 'VERB', :new do |
||||
before do |
||||
@member_role = mocks_for_creating Role |
||||
allow(::Redmine::AccessControl).to receive(:sorted_modules).and_return(%w(Foo)) |
||||
allow(GlobalRole).to receive(:setable_permissions).and_return(doubled_permissions) |
||||
@non_member_role = mock_model Role |
||||
mock_permissions_on @non_member_role |
||||
allow(Role).to receive(:non_member).and_return(@non_member_role) |
||||
|
||||
mock_role_find |
||||
get 'new' |
||||
end |
||||
|
||||
it 'renders new' do |
||||
expect(response).to be_successful |
||||
expect(response).to render_template 'roles/new' |
||||
expect(assigns(:permissions)) |
||||
.to eql([['Foo', @member_role.setable_permissions]]) |
||||
expect(assigns(:roles)).to eql @roles |
||||
expect(assigns(:role)).to eql @member_role |
||||
end |
||||
end |
||||
|
||||
describe 'VERB', :edit do |
||||
before(:each) do |
||||
@member_role = mocks_for_creating Role |
||||
@global_role = mocks_for_creating GlobalRole |
||||
mock_role_find |
||||
end |
||||
|
||||
describe 'WITH member_role id' do |
||||
before do |
||||
@params = {'id' => '1'} |
||||
allow(Role).to receive(:find).and_return(@member_role) |
||||
end |
||||
|
||||
describe 'RESULT' do |
||||
describe 'success' do |
||||
describe 'html' do |
||||
before do |
||||
allow(::Redmine::AccessControl).to receive(:sorted_modules).and_return(%w(Foo)) |
||||
get :edit, params: @params |
||||
end |
||||
|
||||
|
||||
it do |
||||
expect(response).to be_successful |
||||
expect(response).to render_template 'roles/edit' |
||||
expect(assigns(:role)).to eql @member_role |
||||
expect(assigns(:permissions)) |
||||
.to eql([['Foo', @member_role.setable_permissions]]) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'WITH post' do |
||||
before(:each) do |
||||
@member_role = mocks_for_creating Role |
||||
@global_role = mocks_for_creating GlobalRole |
||||
mock_role_find |
||||
allow(Role).to receive(:find).with('1').and_return(@member_role) |
||||
allow(Role).to receive(:find).with('2').and_return(@global_role) |
||||
end |
||||
|
||||
describe 'VERB', :create do |
||||
describe 'WITH member_role params' do |
||||
before do |
||||
@params = {'role' => {'name' => 'role', |
||||
'permissions' => %w(perm1 perm2 perm3), |
||||
'assignable' => '1'}} |
||||
end |
||||
|
||||
describe 'RESULT' do |
||||
describe 'success' do |
||||
before(:each) do |
||||
expect(Role) |
||||
.to receive(:new) |
||||
.with(ActionController::Parameters.new(@params['role']).permit!) |
||||
.and_return(@member_role) |
||||
allow(@member_role).to receive(:save).and_return(true) |
||||
allow(@member_role).to receive(:errors).and_return([]) |
||||
end |
||||
|
||||
describe 'html' do |
||||
before do |
||||
post 'create', params: @params |
||||
end |
||||
|
||||
it_should_behave_like 'successful create' |
||||
it {expect(assigns(:role)).to eql @member_role} |
||||
end |
||||
end |
||||
|
||||
describe 'failure' do |
||||
before(:each) do |
||||
expect(Role) |
||||
.to receive(:new) |
||||
.with(ActionController::Parameters.new(@params['role']).permit!) |
||||
.and_return(@member_role) |
||||
allow(@member_role).to receive(:save).and_return(false) |
||||
allow(@member_role).to receive(:errors).and_return(['something is wrong']) |
||||
end |
||||
|
||||
describe 'html' do |
||||
before {post 'create', params: @params} |
||||
|
||||
it_should_behave_like 'failed create' |
||||
it {expect(assigns(:role)).to eql @member_role} |
||||
it {expect(assigns(:roles)).to eql Role.all} |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'WITH global_role params' do |
||||
before do |
||||
@params = {'role' => {'name' => 'role', |
||||
'permissions' => %w(perm1 perm2 perm3) |
||||
}, |
||||
'global_role' => '1'} |
||||
end |
||||
|
||||
describe 'RESULTS' do |
||||
describe 'success' do |
||||
before(:each) do |
||||
expect(GlobalRole) |
||||
.to receive(:new) |
||||
.with(ActionController::Parameters.new(@params['role']).permit!) |
||||
.and_return(@global_role) |
||||
allow(@global_role).to receive(:save).and_return(true) |
||||
end |
||||
|
||||
describe 'html' do |
||||
before {post 'create', params: @params} |
||||
|
||||
it_should_behave_like 'successful create' |
||||
end |
||||
end |
||||
|
||||
describe 'failure' do |
||||
before(:each) do |
||||
expect(GlobalRole) |
||||
.to receive(:new) |
||||
.with(ActionController::Parameters.new(@params['role']).permit!) |
||||
.and_return(@global_role) |
||||
allow(@global_role).to receive(:save).and_return(false) |
||||
end |
||||
|
||||
describe 'html' do |
||||
before {post 'create', params: @params} |
||||
|
||||
it_should_behave_like 'failed create' |
||||
it {expect(assigns(:role)).to eql @global_role} |
||||
it {expect(assigns(:roles)).to eql Role.all} |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'VERB', :destroy do |
||||
shared_examples_for 'destroy results' do |
||||
describe 'success' do |
||||
before do |
||||
expect(@role).to receive(:destroy) |
||||
post 'destroy', params: @params |
||||
end |
||||
|
||||
it {expect(response).to be_redirect} |
||||
it {expect(response).to redirect_to '/admin/roles'} |
||||
end |
||||
end |
||||
|
||||
describe 'WITH member_role params' do |
||||
before do |
||||
@params = {'class' => 'Role', 'id' => '1'} |
||||
@role = @member_role |
||||
end |
||||
|
||||
describe 'RESULTS' do |
||||
it_should_behave_like 'destroy results' |
||||
end |
||||
end |
||||
|
||||
describe 'WITH global_role params' do |
||||
before do |
||||
@params = {'class' => 'Role', 'id' => '2'} |
||||
@role = @global_role |
||||
end |
||||
|
||||
describe 'RESULTS' do |
||||
it_should_behave_like 'destroy results' |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'VERB', :update do |
||||
shared_examples_for 'update results' do |
||||
describe 'success' do |
||||
describe 'html' do |
||||
before do |
||||
expect(@role) |
||||
.to receive(:update_attributes) |
||||
.with(ActionController::Parameters.new(@params['role']).permit!) |
||||
.and_return(true) |
||||
allow(@role).to receive(:errors).and_return([]) |
||||
post :update, params: @params |
||||
end |
||||
|
||||
it {expect(response).to be_redirect} |
||||
it {expect(response).to redirect_to '/admin/roles'} |
||||
it {expect(flash[:notice]).to eql I18n.t(:notice_successful_update)} |
||||
end |
||||
end |
||||
|
||||
describe 'failure' do |
||||
describe 'html' do |
||||
before(:each) do |
||||
expect(@role) |
||||
.to receive(:update_attributes) |
||||
.with(ActionController::Parameters.new(@params['role']).permit!) |
||||
.and_return(false) |
||||
allow(@role).to receive(:errors).and_return(['something is wrong']) |
||||
post :update, params: @params |
||||
end |
||||
|
||||
it {expect(response).to render_template 'roles/edit'} |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'WITH member_role params' do |
||||
before do |
||||
@params = {'role' => {'permissions' => %w(permA permB), |
||||
'name' => 'schmu'}, |
||||
'id' => '1'} |
||||
@role = @member_role |
||||
end |
||||
|
||||
describe 'RESULT' do |
||||
it_should_behave_like 'update results' |
||||
end |
||||
end |
||||
|
||||
describe 'WITH global_role params' do |
||||
before do |
||||
@params = {'role' => {'permissions' => %w(permA permB), |
||||
'name' => 'schmu'}, |
||||
'id' => '2'} |
||||
@role = @global_role |
||||
end |
||||
|
||||
describe 'RESULT' do |
||||
it_should_behave_like 'update results' |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,63 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require_relative './shared_contract_examples' |
||||
|
||||
describe Roles::CreateContract do |
||||
it_behaves_like 'roles contract' do |
||||
let(:role) do |
||||
Role.new.tap do |r| |
||||
r.name = role_name |
||||
r.assignable = role_assignable |
||||
end |
||||
end |
||||
|
||||
subject(:contract) { described_class.new(role, current_user) } |
||||
|
||||
describe 'validation' do |
||||
context 'with the type set manually' do |
||||
before do |
||||
role.type = 'GlobalRole' |
||||
end |
||||
|
||||
it_behaves_like 'is valid' |
||||
end |
||||
|
||||
context 'with the type set manually to something other than Role or GlobalRole' do |
||||
before do |
||||
role.type = 'MyRole' |
||||
end |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, type: %i(inclusion)) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,63 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
shared_examples_for 'roles contract' do |
||||
let(:current_user) do |
||||
FactoryBot.build_stubbed(:admin) |
||||
end |
||||
let(:role_name) { 'A role name' } |
||||
let(:role_assignable) { true } |
||||
|
||||
def expect_valid(valid, symbols = {}) |
||||
expect(contract.validate).to eq(valid) |
||||
|
||||
symbols.each do |key, arr| |
||||
expect(contract.errors.symbols_for(key)).to match_array arr |
||||
end |
||||
end |
||||
|
||||
shared_examples 'is valid' do |
||||
it 'is valid' do |
||||
expect_valid(true) |
||||
end |
||||
end |
||||
|
||||
describe 'validation' do |
||||
it_behaves_like 'is valid' |
||||
|
||||
context 'if the name is nil' do |
||||
let(:role_name) { nil } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, name: %i(blank)) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,57 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require_relative './shared_contract_examples' |
||||
|
||||
describe Roles::UpdateContract do |
||||
it_behaves_like 'roles contract' do |
||||
let(:role) do |
||||
FactoryBot.build_stubbed(:role, |
||||
name: 'Some name', |
||||
assignable: !role_assignable).tap do |r| |
||||
r.name = role_name |
||||
r.assignable = role_assignable |
||||
end |
||||
end |
||||
|
||||
subject(:contract) { described_class.new(role, current_user) } |
||||
|
||||
describe 'validation' do |
||||
context 'with the type set manually' do |
||||
before do |
||||
role.type = 'GlobalRole' |
||||
end |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, type: %i(error_readonly)) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue