Skip to content

Commit

Permalink
working on vestry forum & roles
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasConnolly committed Jul 25, 2023
1 parent 36223e9 commit 7082320
Show file tree
Hide file tree
Showing 11 changed files with 1,657 additions and 273 deletions.
3 changes: 2 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def user_params
end

def admin_only
redirect_to(root_path, alert: "Access is restricted.") unless current_user.admin?
redirect_to(root_path, alert: "Access is restricted.") unless
current_user.roles.include? ("admin")?
end
end
7 changes: 4 additions & 3 deletions app/controllers/vnotes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create
@vnote = current_user.vnotes.build(vnote_params)
@vnote.save
redirect_to(vnotes_path(@vnote))
VnoteCommentMailer.vnote_comment_created(@vnote).deliver_later
VnoteMailer.vnote_created(@vnote).deliver_later
end

def update
Expand All @@ -60,8 +60,9 @@ def vnote_params
end

def vestry_only
unless current_user.vestry? || current_user.admin?
redirect_to(root_path, alert: "You must be a member of the St. Paul Vestry to use this function.")
unless current_user.roles.include? ("vestry")
redirect_to root_path, alert: "You must be a member of the St. Paul
Vestry to use this function."
end
end
end
4 changes: 2 additions & 2 deletions app/mailers/comment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def new_comment(comment)
def get_recipients(comment)
case comment.commentable_type
when "Vnote"
User.where(role: "vestry").where.not(id: comment_user_id).pluck(:email)
User.where(roles.include? "vestry").where.not(id: comment_user_id).pluck(:email)
when "Post"
User.where.not(email: nil).pluck(:email)
when "StoryIdea"
User.where(role: "communicator").where.not(id: comment_user_id).pluck(:email)
User.where(roles.include? "communicator").where.not(id: comment_user_id).pluck(:email)
end
end
end
2 changes: 1 addition & 1 deletion app/mailers/vnote_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class VnoteMailer < ApplicationMailer
default to: proc { User.where(role: "vestry").pluck(:email) }
default to: proc { User.where(" 'vestry' = ANY (roles)").pluck(:email) }

def vnote_created(vnote)
@vnote = vnote
Expand Down
21 changes: 8 additions & 13 deletions app/models/anniversary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
class Anniversary < ApplicationRecord
acts_as_birthday :marriage

# around_update :set_yday
# def set_yday
# self.yday = marriage.yday unless marriage.nil?
# def class << self.assign_from_row(row)
# anniversary = find_by_salutation(row[:salutation]) || new
# anniversary.assign_attributes(row.to_hash.slice(
# :salutation,
# :last_name,
# :marriage,
# ))
# anniversary
# end

def class << self.assign_from_row(row)
anniversary = find_by_salutation(row[:salutation]) || new
anniversary.assign_attributes(row.to_hash.slice(
:salutation,
:last_name,
:marriage,
))
anniversary
end
end


24 changes: 15 additions & 9 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class User < ApplicationRecord
after_create :set_username
validates :email, presence: true, uniqueness: { case_sensitive: false }
after_save :add_profile
after_initialize :set_default_role, if: :new_record?

after_create :set_default_role, if: :new_record?
after_save :maybe_add_stripe_id
after_destroy :cancel_stripe_customer
has_many :posts, dependent: :destroy
Expand All @@ -59,13 +58,7 @@ class User < ApplicationRecord
# honey used to prevent bots-filled forms from being saved to db
validates :honey, absence: true

def set_username
self.username = "#{ first_name }" + " " + "#{ last_name }"
end

def set_default_role
self.roles ||= ["member"]
end


# Include default devise modules
# Others available are:
Expand Down Expand Up @@ -106,4 +99,17 @@ def self.find_for_database_authentication(warden_conditions)
where(conditions.to_h).first
end
end


private

def set_username
self.username = "#{ first_name }" + " " + "#{ last_name }"
self.save
end

def set_default_role
self.roles ||= ["member"]
self.save
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<%= link_to "Clergy and staff" , leadership_index_path, {class: "dropdown-item" } %><br>
<%= link_to "Vestry" , leadership_index_path, {class: "dropdown-item" } %><br>
<%= link_to "Vestry minutes" , vestry_minutes_path, {class: "dropdown-item" } %><br>
<% if current_user && current_user.vestry? %>
<% if current_user && current_user.roles.include?("vestry") %>
<%= link_to "Vestry Forum" , vnotes_path, {class: "dropdown-item" } %>
<% end %>
<%= link_to "Parish profile" ,
Expand Down
Binary file modified dump.rdb
Binary file not shown.
1,279 changes: 1,279 additions & 0 deletions log/development.log

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
"anymatch": "^3.1.2",
"bootstrap": "5.3.0",
"bootstrap-icons": "^1.7.2",
"braces": "^3.0.2",
"check-files": "^0.0.2",
"esbuild": "^0.17.11",
"esbuild-rails": "^1.0.3",
"extend": "^3.0.2",
"flatpickr": "^4.6.13",
"glob-parent": "^6.0.2",
"popper": "^1.0.1",
"request": "^2.88.2",
"sass": "^1.54.8",
"stimulus": "^3.1.0",
"stimulus-flatpickr": "^1.4.0",
"tough-cookie": "^4.1.3",
"trix": "^2.0.4"
},
"scripts": {
Expand Down
Loading

0 comments on commit 7082320

Please sign in to comment.