Class: Back::SuperusersController

Inherits:
BackController
  • Object
show all
Defined in:
app/controllers/lato_core/back/superusers_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/lato_core/back/superusers_controller.rb', line 32

def create
  @superuser = LatoCore::Superuser.new(superuser_params)

  if !@superuser.save
    flash[:danger] = @superuser.errors.full_messages.to_sentence
    redirect_to lato_core.new_superuser_path
    return
  end
  
  flash[:success] = LANGUAGES[:lato_core][:flashes][:superuser_create_success]
  redirect_to lato_core.superuser_path(@superuser.id)
end

#destroyObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/lato_core/back/superusers_controller.rb', line 89

def destroy
  @superuser = LatoCore::Superuser.find_by(id: params[:id])

  if !@superuser
    flash[:warning] = LANGUAGES[:lato_core][:flashes][:superuser_not_found]
    redirect_to lato_core.superusers_path
    return
  end

  if @superuser.permission >= @core__current_superuser.permission && @superuser.id != @core__current_superuser.id
    flash[:warning] = LANGUAGES[:lato_core][:flashes][:superuser_not_permission]
    redirect_to lato_core.superusers_path
    return
  end

  if !@superuser.destroy
    flash[:danger] = @superuser.errors.full_messages.to_sentence
    redirect_to lato_core.superusers_path
    return
  end

  flash[:success] = LANGUAGES[:lato_core][:flashes][:superuser_destroy_success]
  redirect_to lato_core.superusers_path
end

#editObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/lato_core/back/superusers_controller.rb', line 45

def edit
  core__set_header_active_page_title(LANGUAGES[:lato_core][:pages][:superusers_edit])
  @superuser = LatoCore::Superuser.find_by(id: params[:id])

  if !@superuser
    flash[:warning] = LANGUAGES[:lato_core][:flashes][:superuser_not_found]
    redirect_to lato_core.superusers_path
    return
  end

  if @superuser.permission >= @core__current_superuser.permission && @superuser.id != @core__current_superuser.id
    flash[:warning] = LANGUAGES[:lato_core][:flashes][:superuser_not_permission]
    redirect_to lato_core.superusers_path
    return
  end

  fetch_external_objects
end

#indexObject



9
10
11
12
13
# File 'app/controllers/lato_core/back/superusers_controller.rb', line 9

def index
  core__set_header_active_page_title(LANGUAGES[:lato_core][:pages][:superusers])
  @superusers = LatoCore::Superuser.all
  @widget_index_superusers = core__widgets_index(@superusers, search: 'surname', pagination: 10)
end

#newObject



26
27
28
29
30
# File 'app/controllers/lato_core/back/superusers_controller.rb', line 26

def new
  core__set_header_active_page_title(LANGUAGES[:lato_core][:pages][:superusers_new])
  @superuser = LatoCore::Superuser.new
  fetch_external_objects
end

#showObject



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/lato_core/back/superusers_controller.rb', line 15

def show
  core__set_header_active_page_title(LANGUAGES[:lato_core][:pages][:superusers_show])
  @superuser = LatoCore::Superuser.find_by(id: params[:id])

  if !@superuser
    flash[:warning] = LANGUAGES[:lato_core][:flashes][:superuser_not_found]
    redirect_to lato_core.superusers_path
    return
  end
end

#updateObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/lato_core/back/superusers_controller.rb', line 64

def update
  @superuser = LatoCore::Superuser.find_by(id: params[:id])

  if !@superuser
    flash[:warning] = LANGUAGES[:lato_core][:flashes][:superuser_not_found]
    redirect_to lato_core.superusers_path
    return
  end

  if @superuser.permission >= @core__current_superuser.permission && @superuser.id != @core__current_superuser.id
    flash[:warning] = LANGUAGES[:lato_core][:flashes][:superuser_not_permission]
    redirect_to lato_core.superusers_path
    return
  end

  if !@superuser.update(superuser_params)
    flash[:danger] = @superuser.errors.full_messages.to_sentence
    redirect_to lato_core.edit_superuser_path(@superuser.id)
    return
  end

  flash[:success] = LANGUAGES[:lato_core][:flashes][:superuser_update_success]
  redirect_to lato_core.superuser_path(@superuser.id)
end