Refactor user my modules code

This commit is contained in:
Luka Murn 2016-11-22 15:07:18 +01:00
parent e0607f7891
commit 201b1a48d5
3 changed files with 3 additions and 77 deletions

View file

@ -1,24 +1,9 @@
class UserMyModulesController < ApplicationController
before_action :load_vars
before_action :check_view_permissions, only: [ :index ]
before_action :check_edit_permissions, only: [ :index_edit ]
before_action :check_edit_permissions, only: [:index_edit]
before_action :check_create_permissions, only: [:create]
before_action :check_delete_permisisons, only: [:destroy]
def index
@user_my_modules = @my_module.user_my_modules
respond_to do |format|
format.json {
render :json => {
:html => render_to_string({
:partial => "index.html.erb"
})
}
}
end
end
def index_edit
@user_my_modules = @my_module.user_my_modules
@unassigned_users = @my_module.unassigned_users
@ -40,11 +25,6 @@ class UserMyModulesController < ApplicationController
@um = UserMyModule.new(um_params.merge(my_module: @my_module))
@um.assigned_by = current_user
if @um.save
flash_success = t(
"user_my_modules.create.success_flash",
user: @um.user.full_name,
module: @um.my_module.name)
# Create activity
message = t(
"activities.assign_user_to_module",
@ -60,25 +40,12 @@ class UserMyModulesController < ApplicationController
type_of: :assign_user_to_module
)
respond_to do |format|
format.html {
flash[:success] = flash_success
redirect_to session.delete(:return_to)
}
format.json {
redirect_to :action => :index_edit, :format => :json
}
end
else
flash_error = t("user_my_modules.create.error_flash",
user: @um.user.full_name,
module: @um.my_module.name)
respond_to do |format|
format.html {
flash[:error] = flash_error
init_gui
render :new
}
format.json {
render :json => {
:errors => [
@ -90,14 +57,7 @@ class UserMyModulesController < ApplicationController
end
def destroy
session[:return_to] ||= request.referer
if @um.destroy
flash_success = t(
"user_my_modules.destroy.success_flash",
user: @um.user.full_name,
module: @um.my_module.name)
# Create activity
message = t(
"activities.unassign_user_from_module",
@ -115,25 +75,12 @@ class UserMyModulesController < ApplicationController
)
respond_to do |format|
format.html {
flash[:success] = flash_success
redirect_to session.delete(:return_to), :status => 303
}
format.json {
redirect_to my_module_users_edit_path(format: :json), :status => 303
}
end
else
flash_error = t("user_my_modules.destroy.error_flash",
user: @um.user.full_name,
module: @um.my_module.name)
respond_to do |format|
format.html {
flash[:error] = flash_error
init_gui
render :new
}
format.json {
render :json => {
:errors => [
@ -164,12 +111,6 @@ class UserMyModulesController < ApplicationController
end
end
def check_view_permissions
unless can_view_module_users(@my_module)
render_403
end
end
def check_edit_permissions
unless can_edit_users_on_module(@my_module)
render_403

View file

@ -1000,21 +1000,6 @@ en:
assign_sample: "<i>%{user}</i> assigned sample(s) <strong>%{samples}</strong> to task(s) <strong>%{tasks}</strong>."
unassign_sample: "<i>%{user}</i> unassigned sample(s) <strong>%{samples}</strong> from task(s) <strong>%{tasks}</strong>."
user_my_modules:
new:
head_title: "%{project} | %{module} | Add user"
title: "Add user to task %{module}"
create: "Add user to task"
no_users_available: "All users of the current project all already added to this task."
assign_user: "Add user"
back_button: "Back to task"
create:
success_flash: "Successfully added user %{user} to task <strong>%{module}</strong>."
error_flash: "User %{user} could not be added to task <strong>%{module}</strong>."
destroy:
success_flash: "Successfully removed user %{user} from task <strong>%{module}</strong>."
error_flash: "User %{user} could not be removed from task <strong>%{module}</strong>."
users:
enums:
status:

View file

@ -172,9 +172,9 @@ Rails.application.routes.draw do
# Show action is a popup (JSON) for individual module in full-zoom canvas,
# as well as "module info" page for single module (HTML)
resources :my_modules, path: '/modules', only: [:show, :update] do
resources :my_module_tags, path: "/tags", only: [:index, :create, :destroy]
resources :my_module_tags, path: "/tags", only: [:create, :destroy]
resources :user_my_modules, path: '/users',
only: [:index, :create, :destroy]
only: [:create, :destroy]
resources :my_module_comments,
path: '/comments',
only: [:index, :create, :edit, :update, :destroy]