Skip to content

Commit

Permalink
Merge pull request #6275 from mdeniz/staging_workflow/staging_manager…
Browse files Browse the repository at this point in the history
…s_group

Staging workflow managers group
  • Loading branch information
DavidKang committed Nov 19, 2018
2 parents 4fc35e0 + 6389802 commit 0b8bad4
Show file tree
Hide file tree
Showing 24 changed files with 268 additions and 47 deletions.
18 changes: 18 additions & 0 deletions src/api/app/assets/javascripts/webui2/staging_workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,21 @@ function setSpinnersForDeletion() { // jshint ignore:line
$(this).find('.delete-spinner').addClass('d-none');
});
}

function autocompleteStagingManagersGroup() { // jshint ignore:line
$('#managers_title').autocomplete({
appendTo: '#assign-managers-group-modal-input',
source: $('#managers_title').data('autocompleteGroupsUrl'),
search: function() {
var icon = $('#assign-managers-group-search-icon i:first-child');
icon.addClass('d-none');
icon.next().removeClass('d-none');
},
response: function() {
var icon = $('#assign-managers-group-search-icon i:first-child');
icon.removeClass('d-none');
icon.next().addClass('d-none');
},
minLength: 2
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def set_staging_workflow
return if @staging_workflow

redirect_back(fallback_location: root_path)
flash[:error] = "StagingWorkflow with id = #{params[:staging_workflow_id]} doesn't exist"
flash[:error] = "Staging with id = #{params[:staging_workflow_id]} doesn't exist"
return
end
end
Expand Down
26 changes: 21 additions & 5 deletions src/api/app/controllers/webui/staging/workflows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ def create
staging_workflow = @project.build_staging
authorize staging_workflow

staging_workflow.managers_group = Group.find_by(title: params[:managers_title])

if staging_workflow.save
flash[:success] = "Staging Workflow for #{@project.name} was successfully created"
flash[:success] = "Staging for #{@project} was successfully created"
redirect_to staging_workflow_path(staging_workflow)
else
flash[:error] = "Staging Workflow for #{@project.name} couldn't be created"
flash[:error] = "Staging for #{@project} couldn't be created"
render :new
end
end
Expand All @@ -39,6 +41,7 @@ def show
@ignored_requests = @staging_workflow.ignored_requests.first(5)
@more_ignored_requests = @staging_workflow.ignored_requests.count - @ignored_requests.size
@empty_projects = @staging_workflow.staging_projects.without_staged_requests
@managers = @staging_workflow.managers_group
end

def edit
Expand All @@ -58,14 +61,27 @@ def destroy
@staging_workflow.staging_projects.where(id: params[:staging_project_ids]).destroy_all

if @staging_workflow.destroy
flash[:success] = "Staging Workflow for #{@project.name} was successfully deleted."
flash[:success] = "Staging for #{@project} was successfully deleted."
render js: "window.location='#{project_show_path(@project)}'"
else
flash[:error] = "Staging Workflow for #{@project.name} couldn't be deleted: #{@staging_workflow.errors.full_messages.to_sentence}."
flash[:error] = "Staging for #{@project} couldn't be deleted: #{@staging_workflow.errors.full_messages.to_sentence}."
render js: "window.location='#{staging_workflow_path(@staging_workflow)}'"
end
end

def update
authorize @staging_workflow

@staging_workflow.managers_group = Group.find_by(title: params[:managers_title])
if @staging_workflow.save
flash[:success] = 'Managers group was successfully assigned'
else
flash[:error] = "Managers group couldn't be assigned: #{@staging_workflow.errors.full_messages.to_sentence}."
end

redirect_to edit_staging_workflow_path(@staging_workflow)
end

private

def set_bootstrap_views
Expand All @@ -77,7 +93,7 @@ def set_staging_workflow
return if @staging_workflow

redirect_back(fallback_location: root_path)
flash[:error] = "StagingWorkflow with id = #{params[:id]} doesn't exist"
flash[:error] = "Staging with id = #{params[:id]} doesn't exist"
return
end
end
1 change: 1 addition & 0 deletions src/api/app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Groups have an arbitrary number of roles and users assigned to them.
#
class Group < ApplicationRecord
has_one :staging_workflow, class_name: 'Staging::Workflow', foreign_key: :managers_group_id, dependent: :nullify
has_many :groups_users, inverse_of: :group, dependent: :destroy
has_many :users, -> { distinct }, through: :groups_users
has_many :group_maintainers, inverse_of: :group, dependent: :destroy
Expand Down
16 changes: 16 additions & 0 deletions src/api/app/models/staging/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class StagingProject < Project

after_save :update_staging_workflow_on_backend
after_destroy :update_staging_workflow_on_backend
before_create :add_managers_group

def staging_identifier
name[/.*:Staging:(.*)/, 1]
Expand Down Expand Up @@ -88,6 +89,17 @@ def problems
@problems ||= cache_problems
end

def assign_managers_group(managers)
role = Role.find_by_title!('maintainer')
return if relationships.find_by(group: managers, role: role)
Relationship.add_group(self, managers, role, nil, true)
end

def unassign_managers_group(managers)
role = Role.find_by_title!('maintainer')
relationships.find_by(group: managers, role: role).try(:destroy!)
end

private

def cache_problems
Expand Down Expand Up @@ -185,5 +197,9 @@ def update_staging_workflow_on_backend
staging_workflow.reload
staging_workflow.write_to_backend
end

def add_managers_group
assign_managers_group(staging_workflow.managers_group)
end
end
end
22 changes: 22 additions & 0 deletions src/api/app/models/staging/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def self.table_name_prefix
include CanRenderModel

belongs_to :project, inverse_of: :staging
belongs_to :managers_group, class_name: 'Group'

has_many :staging_projects, class_name: 'Staging::StagingProject', inverse_of: :staging_workflow, dependent: :nullify,
foreign_key: 'staging_workflow_id' do
def without_staged_requests
Expand All @@ -25,7 +27,10 @@ def ready_to_stage

has_many :staged_requests, class_name: 'BsRequest', through: :staging_projects

validates :managers_group, presence: true

after_create :create_staging_projects
before_update :update_staging_projects_managers_group

def unassigned_requests
target_of_bs_requests.stageable.where.not(id: ignored_requests | staged_requests)
Expand Down Expand Up @@ -56,4 +61,21 @@ def create_staging_projects
staging_project.store
end
end

def update_staging_projects_managers_group
return unless changes[:managers_group_id]

old_managers_group = Group.find(changes[:managers_group_id].first)
new_managers_group = managers_group

staging_projects.each do |staging_project|
staging_project.unassign_managers_group(old_managers_group)
staging_project.assign_managers_group(new_managers_group)
staging_project.store
end

# FIXME: This assignation is need because after store a staging_project
# the object is reloaded and we lost the changes.
self.managers_group = new_managers_group
end
end
4 changes: 4 additions & 0 deletions src/api/app/policies/staging/workflow_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def update?
ProjectPolicy.new(@user, @record.project).update?
end

def assign_managers_group?
update?
end

def edit?
update?
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/models/staging/_workflow.xml.builder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xml.workflow(project: my_model.project.name) do
xml.workflow(project: my_model.project.name, managers: my_model.managers_group.title) do
my_model.staging_projects.each do |staging_project|
xml.staging_project(name: staging_project.name)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
= render partial: 'webui/project/breadcrumb_items'
- if controller_name == 'workflows' && action_name == 'show'
%li.breadcrumb-item.active{ 'aria-current' => 'page' }
Staging Projects
Staging
- elsif controller_name == 'workflows' && action_name == 'new'
%li.breadcrumb-item.active{ 'aria-current' => 'page' }
Create Staging Projects
- else
%li.breadcrumb-item
= link_to 'Staging Projects', staging_workflow_path(@staging_workflow)
= link_to 'Staging', staging_workflow_path(@staging_workflow)
- if controller_name == 'workflows' && action_name == 'edit'
%li.breadcrumb-item.active{ 'aria-current' => 'page' }
Edit
Configure
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
.modal-content
.modal-header
%h5.modal-title
Do you want to delete the staging workflow for #{project.name}?
Do you want to delete the staging for #{project.name}?
.modal-body
%p Please confirm deletion of the staging workflow for #{project.name}
%p Please confirm deletion of the staging for #{project.name}
= form_tag staging_workflow_path, method: :delete, remote: true, id: 'staging-workflow-delete' do
- if @staging_workflow.staging_projects.any?
%p Check the staging projects you want to be deleted:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
%h5.card-header Infos
.card-body
%dl
%dt Managers:
%dd
%ul.pl-2.list-unstyled
%li= link_to managers.title, group_show_path(managers)

%dt Empty projects:
%dd= render 'empty_projects_list', projects: empty_projects

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- actual_group = staging_workflow.managers_group ? staging_workflow.managers_group.title : 'None assigned'
.modal.fade#staging-managers-group-modal{ tabindex: -1, role: 'dialog', aria: { labelledby: 'staging-managers-group-modal-label', hidden: true } }
.modal-dialog.modal-dialog-centered{ role: 'document' }
.modal-content
= form_tag(staging_workflow_path(staging_workflow), method: :put) do
.modal-header
%h5.modal-title#staging-managers-group-modal-label Assign other group
.modal-body
.form-group#assign-managers-group-modal-input
.mb-4
Assigned group is:
%strong= actual_group

= label_tag(:managers_title, 'Replace the group with:')
.input-group
.input-group-prepend
%span.input-group-text#assign-managers-group-search-icon
%i.fa.fa-search
%i.fas.fa-spinner.fa-spin.d-none
= text_field_tag 'managers_title', '', required: true, placeholder: 'Type to autocomplete...', class: 'form-control',
data: { autocomplete_groups_url: url_for(controller: '/webui/groups', action: 'autocomplete') }

.modal-footer
= render partial: 'webui2/shared/dialog_action_buttons'

- content_for :ready_function do
autocompleteStagingManagersGroup();
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
= render partial: 'delete_staging_project_modal', locals: { staging_workflow: staging_workflow, staging_project: staging_project }

- content_for :ready_function do
$('#staging-projects-datatable').DataTable({ responsive: true });
$('#staging-projects-datatable').DataTable({responsive: true, paging: false, ordering: false, searching: false, info: false});
16 changes: 11 additions & 5 deletions src/api/app/views/webui2/webui/staging/workflows/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
- @pagetitle = "Edit Staging Workflow for #{@project}"
- @pagetitle = "Configure Staging for #{@project}"

.row
.col-xl-12
.card.mb-3
= render(partial: 'webui2/webui/project/tabs', locals: { project: @project })
.card-body
%h3= @pagetitle
%ul.list-inline.mb-0
%li.list-inline-item
= link_to('#', class: 'nav-link', data: { toggle: 'modal', target: '#create-staging-projects-modal' }) do
%i.fas.fa-plus-circle.text-success
Create Project
%li.list-inline-item
= link_to('#', class: 'nav-link', data: { toggle: 'modal', target: '#staging-managers-group-modal' }) do
%i.fas.fa-users.text-warning
Managers

= render(partial: 'staging_projects_table',
locals: { staging_workflow: @staging_workflow, staging_projects: @staging_projects, display_actions_column: true })

= link_to('#', class: 'nav-link', data: { toggle: 'modal', target: '#create-staging-projects-modal' }) do
%i.fas.fa-plus-circle.text-success
Create Staging Project

= render partial: 'create_staging_project', locals: { staging_workflow: @staging_workflow }
= render partial: 'staging_managers_group', locals: { staging_workflow: @staging_workflow }
17 changes: 15 additions & 2 deletions src/api/app/views/webui2/webui/staging/workflows/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
.mb-3
Adding the staging capability to this project will enable you to group
requests into staging projects and being able to see how they build together.
.text-center
.mb-3.w-50.m-auto
= form_for @staging_workflow, method: :post do |f|
= hidden_field_tag :project_name, @project
= f.submit 'Create Staging Projects', class: 'btn btn-primary'
.form-group#assign-managers-group-modal-input
= label_tag(:managers_title, 'Managers:')
.input-group
.input-group-prepend
%span.input-group-text#assign-managers-group-search-icon
%i.fa.fa-search
%i.fas.fa-spinner.fa-spin.d-none
= text_field_tag 'managers_title', '', required: true, placeholder: 'Type to autocomplete...', class: 'form-control',
data: { autocomplete_groups_url: url_for(controller: '/webui/groups', action: 'autocomplete') }
.text-center
= f.submit 'Create Staging Projects', class: 'btn btn-primary'

- content_for :ready_function do
autocompleteStagingManagersGroup();
28 changes: 14 additions & 14 deletions src/api/app/views/webui2/webui/staging/workflows/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
- @pagetitle = "Staging Projects for #{@project}"
- @pagetitle = "Staging for #{@project}"

.row
.col-xl-10
.card.mb-3
= render(partial: 'webui2/webui/project/tabs', locals: { project: @project })
.card-body
%h3= @pagetitle

%hr
%ul.list-inline.mb-0
- if policy(@staging_workflow).update?
%li.list-inline-item
= link_to(edit_staging_workflow_path(@staging_workflow), class: 'nav-link') do
%i.fas.fa-edit.text-info
Configure
- if policy(@staging_workflow).destroy?
%li.list-inline-item
= link_to('#', class: 'nav-link', data: { toggle: 'modal', target: '#delete-staging-workflow' }) do
%i.fas.fa-times-circle.text-danger
Delete
= render(partial: 'delete', locals: { project: @project })

= render(partial: 'staging_projects_table',
locals: { staging_workflow: @staging_workflow, staging_projects: @staging_projects, display_actions_column: false })

%ul.list-inline
%li.list-inline-item
= link_to(edit_staging_workflow_path(@staging_workflow)) do
%i.fas.fa-edit.text-info
Edit
- if policy(@staging_workflow).destroy?
%a{ data: { toggle: 'modal', target: '#delete-staging-workflow' }, href: '#' }
%i.fas.fa-times-circle.text-danger
Delete
= render(partial: 'webui2/webui/staging/workflows/delete', locals: { project: @project })
.col-xl-2
= render partial: 'legend'
= render partial: 'infos', locals: { staging_workflow: @staging_workflow, empty_projects: @empty_projects,
unassigned_requests: @unassigned_requests, more_unassigned_requests: @more_unassigned_requests,
ready_requests: @ready_requests, more_ready_requests: @more_ready_requests,
ignored_requests: @ignored_requests, more_ignored_requests: @more_ignored_requests,
project: @project }
project: @project, managers: @managers }
2 changes: 1 addition & 1 deletion src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def self.public_or_about_path?(request)
get 'published/:project(/:repository(/:arch(/:binary)))' => 'published#index', constraints: cons
get 'published/' => 'source#index', via: :get

resources :staging_workflows, except: [:index, :update], controller: 'webui/staging/workflows', constraints: cons do
resources :staging_workflows, except: :index, controller: 'webui/staging/workflows', constraints: cons do
resources :staging_projects, only: [:create, :destroy], controller: 'webui/staging/projects', param: :project_name, constraints: cons
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddStagingManagersGroup < ActiveRecord::Migration[5.2]
def change
change_table :staging_workflows do |t|
t.references :managers_group, index: true, type: :integer
end
end
end

0 comments on commit 0b8bad4

Please sign in to comment.