mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Make permission checks for card selection async [SCI-7157]
This commit is contained in:
parent
0fcedc32ba
commit
e27d063b61
8 changed files with 52 additions and 15 deletions
|
@ -689,7 +689,16 @@ var ProjectsIndex = (function() {
|
|||
selectedProjects.splice(index, 1);
|
||||
}
|
||||
|
||||
updateProjectsToolbar();
|
||||
if (this.checked) {
|
||||
$.get(projectCard.data('permissions-url'), function(result) {
|
||||
PERMISSIONS.forEach((permission) => {
|
||||
projectCard.data(permission, result[permission]);
|
||||
});
|
||||
updateProjectsToolbar();
|
||||
});
|
||||
} else {
|
||||
updateProjectsToolbar();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -220,7 +220,17 @@
|
|||
$(this).closest('.experiment-card').removeClass('selected');
|
||||
selectedExperiments.splice(index, 1);
|
||||
}
|
||||
updateExperimentsToolbar();
|
||||
|
||||
if (this.checked) {
|
||||
$.get(card.data('permissions-url'), function(result) {
|
||||
PERMISSIONS.forEach((permission) => {
|
||||
card.data(permission, result[permission]);
|
||||
});
|
||||
updateExperimentsToolbar();
|
||||
});
|
||||
} else {
|
||||
updateExperimentsToolbar();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,18 @@ class ExperimentsController < ApplicationController
|
|||
}
|
||||
end
|
||||
|
||||
def permissions
|
||||
if stale?([@experiment, @experiment.project])
|
||||
render json: {
|
||||
editable: can_manage_experiment?(@experiment),
|
||||
moveable: can_move_experiment?(@experiment),
|
||||
archivable: can_archive_experiment?(@experiment),
|
||||
restorable: can_restore_experiment?(@experiment),
|
||||
duplicable: can_clone_experiment?(@experiment)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def canvas
|
||||
redirect_to module_archive_experiment_path(@experiment) if @experiment.archived_branch?
|
||||
@project = @experiment.project
|
||||
|
@ -278,7 +290,7 @@ class ExperimentsController < ApplicationController
|
|||
format.json do
|
||||
render json: {
|
||||
workflowimg: render_to_string(
|
||||
partial: 'projects/show/workflow_img',
|
||||
partial: 'projects/show/workflow_img.html.erb',
|
||||
locals: { experiment: @experiment }
|
||||
)
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ class ProjectsController < ApplicationController
|
|||
helper_method :current_folder
|
||||
|
||||
before_action :switch_team_with_param, only: :index
|
||||
before_action :load_vars, only: %i(show edit update notifications
|
||||
before_action :load_vars, only: %i(show permissions edit update notifications
|
||||
sidebar experiments_cards view_type actions_dropdown)
|
||||
before_action :load_current_folder, only: %i(index cards new show)
|
||||
before_action :check_view_permissions, only: %i(show notifications sidebar
|
||||
before_action :check_view_permissions, only: %i(show permissions notifications sidebar
|
||||
experiments_cards view_type actions_dropdown)
|
||||
before_action :check_create_permissions, only: %i(new create)
|
||||
before_action :check_manage_permissions, only: :edit
|
||||
|
@ -82,6 +82,17 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def permissions
|
||||
if stale?([@product, current_team])
|
||||
render json: {
|
||||
editable: can_manage_project?(@project),
|
||||
moveable: can_update_team?(current_team),
|
||||
archivable: can_archive_project?(@project),
|
||||
restorable: can_restore_project?(@project)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def sidebar
|
||||
@current_sort = @project.current_view_state(current_user).state.dig('experiments', params[:view_mode], 'sort')
|
||||
render json: {
|
||||
|
|
|
@ -10,7 +10,7 @@ class RepositorySnapshot < RepositoryBase
|
|||
class_name: 'Repository',
|
||||
inverse_of: :repository_snapshots,
|
||||
optional: true
|
||||
belongs_to :my_module, optional: true
|
||||
belongs_to :my_module, optional: true, touch: true
|
||||
has_one :repository_stock_consumption_column,
|
||||
-> { where(data_type: 'RepositoryStockConsumptionValue') },
|
||||
class_name: 'RepositoryColumn',
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
<div class="card project-card"
|
||||
data-id="<%= project.id %>"
|
||||
data-edit-url="<%= edit_project_path(project) %>"
|
||||
data-editable="<%= can_manage_project?(project) %>"
|
||||
data-moveable="<%= can_update_team?(current_team) %>"
|
||||
data-archivable="<%= project.active? && can_archive_project?(project) %>"
|
||||
data-restorable="<%= project.archived? && can_restore_project?(project) %>">
|
||||
data-permissions-url="<%= permissions_project_path(project) %>">
|
||||
<div class="checkbox-cell table-cell">
|
||||
<div class="sci-checkbox-container">
|
||||
<input value="1" type="checkbox" class="sci-checkbox project-card-selector">
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<div class="card experiment-card"
|
||||
data-id="<%= experiment.id %>"
|
||||
data-edit-url=""
|
||||
data-editable="<%= can_manage_experiment?(experiment) %>"
|
||||
data-moveable="<%= can_move_experiment?(experiment) %>"
|
||||
data-archivable="<%= experiment.active? && can_archive_experiment?(experiment) %>"
|
||||
data-restorable="<%= experiment.archived? && can_restore_experiment?(experiment) %>"
|
||||
data-duplicable="<%= can_clone_experiment?(experiment) %>">
|
||||
data-permissions-url="<%= permissions_experiment_path(experiment) %>">
|
||||
<div class="checkbox-cell table-cell">
|
||||
<% if project_is_managable %>
|
||||
<div class="sci-checkbox-container">
|
||||
|
|
|
@ -300,6 +300,7 @@ Rails.application.routes.draw do
|
|||
member do
|
||||
# Notifications popup for individual project in projects index
|
||||
get 'notifications'
|
||||
get 'permissions'
|
||||
get 'experiments_cards'
|
||||
get 'sidebar'
|
||||
get 'actions_dropdown'
|
||||
|
@ -334,6 +335,7 @@ Rails.application.routes.draw do
|
|||
get 'move_modal', action: :move_modal
|
||||
end
|
||||
member do
|
||||
get 'permissions'
|
||||
get 'canvas' # Overview/structure for single experiment
|
||||
# AJAX-loaded canvas edit mode (from canvas)
|
||||
get 'canvas/edit', to: 'canvas#edit'
|
||||
|
|
Loading…
Reference in a new issue