Skip to content

Commit

Permalink
Assing Managers group via UI
Browse files Browse the repository at this point in the history
At editing a StagingWorkflow now the user is able to assign a group of
users as managers.
  • Loading branch information
Moises Deniz Aleman committed Nov 19, 2018
1 parent 853386d commit 82d9df5
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 2 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
});
}
13 changes: 13 additions & 0 deletions src/api/app/controllers/webui/staging/workflows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ def destroy
end
end

def update
authorize @staging_workflow

@staging_workflow.managers = Group.find_by(title: params[:managers_id])

if @staging_workflow.save
flash[:success] = 'Managers group for Staging Workflow was successfully assigned'
else
flash[:error] = "Sorry the group couldn't be assigned to this Staging Workflow"
end
redirect_to edit_staging_workflow_path(@staging_workflow)
end

private

def set_bootstrap_views
Expand Down
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
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();
12 changes: 11 additions & 1 deletion src/api/app/views/webui2/webui/staging/workflows/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
- @pagetitle = "Edit Staging Workflow for #{@project}"
- @pagetitle = "Edit Staging Projects 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
Select Managers

= render(partial: 'staging_projects_table',
locals: { staging_workflow: @staging_workflow, staging_projects: @staging_projects, display_actions_column: true })
Expand All @@ -15,3 +24,4 @@
Create Staging Project

= render partial: 'create_staging_project', locals: { staging_workflow: @staging_workflow }
= render partial: 'staging_managers_group', locals: { staging_workflow: @staging_workflow }
13 changes: 13 additions & 0 deletions src/api/app/views/webui2/webui/staging/workflows/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@
.text-center
= form_for @staging_workflow, method: :post do |f|
= hidden_field_tag :project_name, @project
.form-group#assign-managers-group-modal-input
= label_tag(:managers_id, "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_id', '', required: true, placeholder: 'Type to autocomplete...', class: 'form-control',
data: { autocomplete_groups_url: url_for(controller: '/webui/groups', action: 'autocomplete')}

= f.submit 'Create Staging Projects', class: 'btn btn-primary'

- content_for :ready_function do
autocompleteStagingManagersGroup();
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

0 comments on commit 82d9df5

Please sign in to comment.