Made having a confirmed email required to manage forum groups.

This commit is contained in:
Logan Fick
2017-11-10 16:00:18 -05:00
parent e7cd6d6e99
commit b807a8f4ab
3 changed files with 38 additions and 18 deletions

View File

@@ -9,7 +9,7 @@ class ForumgroupsController < ApplicationController
end end
def edit def edit
if admin? if admin? && current_user.confirmed?
@group = Forumgroup.find(params[:id]) @group = Forumgroup.find(params[:id])
else else
flash[:alert] = "You are not allowed to edit forum groups." flash[:alert] = "You are not allowed to edit forum groups."
@@ -17,7 +17,7 @@ class ForumgroupsController < ApplicationController
end end
def update def update
if admin? if admin? && current_user.confirmed?
@group = Forumgroup.find(params[:id]) @group = Forumgroup.find(params[:id])
if @group.update_attributes(group_params) if @group.update_attributes(group_params)
flash[:notice] = "Forum group updated" flash[:notice] = "Forum group updated"
@@ -32,7 +32,7 @@ class ForumgroupsController < ApplicationController
end end
def new def new
if admin? if admin? && current_user.confirmed?
@group = Forumgroup.new @group = Forumgroup.new
else else
flash[:alert] = "You are not allowed to create forum groups." flash[:alert] = "You are not allowed to create forum groups."
@@ -41,7 +41,7 @@ class ForumgroupsController < ApplicationController
end end
def create def create
if admin? if admin? && current_user.confirmed?
@group = Forumgroup.new(group_params) @group = Forumgroup.new(group_params)
if @group.save if @group.save
flash[:notice] = "Forum group created." flash[:notice] = "Forum group created."
@@ -57,7 +57,7 @@ class ForumgroupsController < ApplicationController
end end
def destroy def destroy
if admin? if admin? && current_user.confirmed?
@group = Forumgroup.find(params[:id]) @group = Forumgroup.find(params[:id])
if @group.destroy if @group.destroy
flash[:notice] = "forum group deleted." flash[:notice] = "forum group deleted."

View File

@@ -1,5 +1,11 @@
<% title "Manage Forums" %> <% title "Manage Forums" %>
<%
def can_edit?
admin? && current_user.confirmed?
end
%>
<h1>Manage Forums</h1> <h1>Manage Forums</h1>
<div class="item-group"> <div class="item-group">
<div class="header"> <div class="header">
@@ -19,22 +25,26 @@
<table> <table>
<tr> <tr>
<td><%= f.label :name %></td> <td><%= f.label :name %></td>
<td><%= f.text_field :name, placeholder: "Name" %></td> <td><%= f.text_field :name, placeholder: "Name", disabled: !can_edit? %></td>
</tr> </tr>
<tr> <tr>
<td><%= f.label :position %></td> <td><%= f.label :position %></td>
<td><%= f.number_field :position, placeholder: "Position" %></td> <td><%= f.number_field :position, placeholder: "Position", disabled: !can_edit? %></td>
</tr> </tr>
<tr> <tr>
<td><%= f.label :role_read_id, "Min. read role" %></td> <td><%= f.label :role_read_id, "Min. read role" %></td>
<td><%= f.select :role_read_id, role_selection, include_blank: "None" %></td> <td><%= f.select :role_read_id, role_selection, { include_blank: "None" }, { disabled: !can_edit? } %></td>
</tr> </tr>
<tr> <tr>
<td><%= f.label :role_write_id, "Min. write role" %></td> <td><%= f.label :role_write_id, "Min. write role" %></td>
<td><%= f.select :role_write_id, role_selection, include_blank: false %></td> <td><%= f.select :role_write_id, role_selection, { include_blank: false }, { disabled: !can_edit? } %></td>
</tr> </tr>
</table> </table>
<p><%= f.submit "Update group", class: "btn blue left" %></p> <p><%= f.submit "Update group", class: "btn blue left", disabled: !can_edit? %></p>
<% end %>
<p><%= button_to "Delete group", @group, :method => "delete", data: {confirm: "Delete group?\nForums + Threads will not be accessible!"}, class: "btn red right", disabled: !can_edit? %></p>
<div class="clear"></div>
<% if !current_user.confirmed? %>
<span class='red-alert'>You must confirm your email before you can edit forum groups.</span>
<% end %> <% end %>
<p><%= button_to "Delete group", @group, :method => "delete", data: {confirm: "Delete group?\nForums + Threads will not be accessible!"}, class: "btn red right" %></p>
<div class="clear"></div>

View File

@@ -1,26 +1,36 @@
<% title "New Forum: #{@group.name}" %> <% title "New Forum: #{@group.name}" %>
<%
def can_create?
admin? && current_user.confirmed?
end
%>
<h1>New forum group</h1> <h1>New forum group</h1>
<% role_selection = Role.all_from_to(:normal, :admin).collect{|p|[p.name, p.id]} %> <% role_selection = Role.all_from_to(:normal, :admin).collect{|p|[p.name, p.id]} %>
<%= form_for @group do |f|%> <%= form_for @group do |f|%>
<table> <table>
<tr> <tr>
<td><%= f.label :name %></td> <td><%= f.label :name %></td>
<td><%= f.text_field :name, placeholder: "Name" %></td> <td><%= f.text_field :name, placeholder: "Name", disabled: !can_create? %></td>
</tr> </tr>
<tr> <tr>
<td><%= f.label :position %></td> <td><%= f.label :position %></td>
<td><%= f.number_field :position, placeholder: "Position" %></td> <td><%= f.number_field :position, placeholder: "Position", disabled: !can_create? %></td>
</tr> </tr>
<tr> <tr>
<td><%= f.label :role_read_id, "Min. read role" %></td> <td><%= f.label :role_read_id, "Min. read role" %></td>
<td><%= f.select :role_read_id, role_selection, include_blank: "None" %></td> <td><%= f.select :role_read_id, role_selection, { include_blank: "None" }, { disabled: !can_create? } %></td>
</tr> </tr>
<tr> <tr>
<td><%= f.label :role_write_id, "Min. write role" %></td> <td><%= f.label :role_write_id, "Min. write role" %></td>
<td><%= f.select :role_write_id, role_selection, include_blank: false %></td> <td><%= f.select :role_write_id, role_selection, { include_blank: false }, { disabled: !can_create? } %></td>
</tr> </tr>
</table> </table>
<p><%= f.submit "Create group", class: "btn blue left" %></p> <p><%= f.submit "Create group", class: "btn blue left", disabled: !can_create? %></p>
<div class="clear"></div> <div class="clear"></div>
<% end %>
<% if !current_user.confirmed? %>
<span class='red-alert'>You must confirm your email before you can create new forum groups.</span>
<% end %>
<% end %>