From b807a8f4ab773a2d8581ae0861604ef0a37f747c Mon Sep 17 00:00:00 2001 From: Logan Fick Date: Fri, 10 Nov 2017 16:00:18 -0500 Subject: Made having a confirmed email required to manage forum groups. --- app/controllers/forumgroups_controller.rb | 10 +++++----- app/views/forumgroups/edit.html.erb | 24 +++++++++++++++++------- app/views/forumgroups/new.html.erb | 22 ++++++++++++++++------ 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/app/controllers/forumgroups_controller.rb b/app/controllers/forumgroups_controller.rb index fe359af..3e53b4a 100644 --- a/app/controllers/forumgroups_controller.rb +++ b/app/controllers/forumgroups_controller.rb @@ -9,7 +9,7 @@ class ForumgroupsController < ApplicationController end def edit - if admin? + if admin? && current_user.confirmed? @group = Forumgroup.find(params[:id]) else flash[:alert] = "You are not allowed to edit forum groups." @@ -17,7 +17,7 @@ class ForumgroupsController < ApplicationController end def update - if admin? + if admin? && current_user.confirmed? @group = Forumgroup.find(params[:id]) if @group.update_attributes(group_params) flash[:notice] = "Forum group updated" @@ -32,7 +32,7 @@ class ForumgroupsController < ApplicationController end def new - if admin? + if admin? && current_user.confirmed? @group = Forumgroup.new else flash[:alert] = "You are not allowed to create forum groups." @@ -41,7 +41,7 @@ class ForumgroupsController < ApplicationController end def create - if admin? + if admin? && current_user.confirmed? @group = Forumgroup.new(group_params) if @group.save flash[:notice] = "Forum group created." @@ -57,7 +57,7 @@ class ForumgroupsController < ApplicationController end def destroy - if admin? + if admin? && current_user.confirmed? @group = Forumgroup.find(params[:id]) if @group.destroy flash[:notice] = "forum group deleted." diff --git a/app/views/forumgroups/edit.html.erb b/app/views/forumgroups/edit.html.erb index bb3bf5a..e69acd4 100644 --- a/app/views/forumgroups/edit.html.erb +++ b/app/views/forumgroups/edit.html.erb @@ -1,5 +1,11 @@ <% title "Manage Forums" %> +<% + def can_edit? + admin? && current_user.confirmed? + end +%> +

Manage Forums

@@ -19,22 +25,26 @@ - + - + - + - +
<%= f.label :name %><%= f.text_field :name, placeholder: "Name" %><%= f.text_field :name, placeholder: "Name", disabled: !can_edit? %>
<%= f.label :position %><%= f.number_field :position, placeholder: "Position" %><%= f.number_field :position, placeholder: "Position", disabled: !can_edit? %>
<%= f.label :role_read_id, "Min. read role" %><%= f.select :role_read_id, role_selection, include_blank: "None" %><%= f.select :role_read_id, role_selection, { include_blank: "None" }, { disabled: !can_edit? } %>
<%= f.label :role_write_id, "Min. write role" %><%= f.select :role_write_id, role_selection, include_blank: false %><%= f.select :role_write_id, role_selection, { include_blank: false }, { disabled: !can_edit? } %>
-

<%= f.submit "Update group", class: "btn blue left" %>

+

<%= f.submit "Update group", class: "btn blue left", disabled: !can_edit? %>

+<% end %> +

<%= button_to "Delete group", @group, :method => "delete", data: {confirm: "Delete group?\nForums + Threads will not be accessible!"}, class: "btn red right", disabled: !can_edit? %>

+
+ +<% if !current_user.confirmed? %> + You must confirm your email before you can edit forum groups. <% end %> -

<%= button_to "Delete group", @group, :method => "delete", data: {confirm: "Delete group?\nForums + Threads will not be accessible!"}, class: "btn red right" %>

-
\ No newline at end of file diff --git a/app/views/forumgroups/new.html.erb b/app/views/forumgroups/new.html.erb index 9802260..70cf4dc 100644 --- a/app/views/forumgroups/new.html.erb +++ b/app/views/forumgroups/new.html.erb @@ -1,26 +1,36 @@ <% title "New Forum: #{@group.name}" %> +<% + def can_create? + admin? && current_user.confirmed? + end +%> +

New forum group

<% role_selection = Role.all_from_to(:normal, :admin).collect{|p|[p.name, p.id]} %> <%= form_for @group do |f|%> - + - + - + - +
<%= f.label :name %><%= f.text_field :name, placeholder: "Name" %><%= f.text_field :name, placeholder: "Name", disabled: !can_create? %>
<%= f.label :position %><%= f.number_field :position, placeholder: "Position" %><%= f.number_field :position, placeholder: "Position", disabled: !can_create? %>
<%= f.label :role_read_id, "Min. read role" %><%= f.select :role_read_id, role_selection, include_blank: "None" %><%= f.select :role_read_id, role_selection, { include_blank: "None" }, { disabled: !can_create? } %>
<%= f.label :role_write_id, "Min. write role" %><%= f.select :role_write_id, role_selection, include_blank: false %><%= f.select :role_write_id, role_selection, { include_blank: false }, { disabled: !can_create? } %>
-

<%= f.submit "Create group", class: "btn blue left" %>

+

<%= f.submit "Create group", class: "btn blue left", disabled: !can_create? %>

-<% end %> \ No newline at end of file + + <% if !current_user.confirmed? %> + You must confirm your email before you can create new forum groups. + <% end %> +<% end %> -- cgit v1.2.3