مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2026-03-03 14:24:06 +00:00
style(rubocop): fix all safe auto correctable offenses
هذا الالتزام موجود في:
@@ -19,7 +19,7 @@ class AddressEndpointsController < ApplicationController
|
||||
flash[:notice] = params[:return_notice] if params[:return_notice].present?
|
||||
redirect_to_with_json [:return_to, [organization, @server, :address_endpoints]]
|
||||
else
|
||||
render_form_errors 'new', @address_endpoint
|
||||
render_form_errors "new", @address_endpoint
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ class AddressEndpointsController < ApplicationController
|
||||
if @address_endpoint.update(safe_params)
|
||||
redirect_to_with_json [organization, @server, :address_endpoints]
|
||||
else
|
||||
render_form_errors 'edit', @address_endpoint
|
||||
render_form_errors "edit", @address_endpoint
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'authie/session'
|
||||
require "authie/session"
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
@@ -7,37 +7,37 @@ class ApplicationController < ActionController::Base
|
||||
before_action :login_required
|
||||
before_action :set_timezone
|
||||
|
||||
rescue_from Authie::Session::InactiveSession, :with => :auth_session_error
|
||||
rescue_from Authie::Session::ExpiredSession, :with => :auth_session_error
|
||||
rescue_from Authie::Session::BrowserMismatch, :with => :auth_session_error
|
||||
rescue_from Authie::Session::InactiveSession, with: :auth_session_error
|
||||
rescue_from Authie::Session::ExpiredSession, with: :auth_session_error
|
||||
rescue_from Authie::Session::BrowserMismatch, with: :auth_session_error
|
||||
|
||||
private
|
||||
|
||||
def login_required
|
||||
unless logged_in?
|
||||
redirect_to login_path(:return_to => request.fullpath)
|
||||
end
|
||||
return if logged_in?
|
||||
|
||||
redirect_to login_path(return_to: request.fullpath)
|
||||
end
|
||||
|
||||
def admin_required
|
||||
if logged_in?
|
||||
unless current_user.admin?
|
||||
render :plain => "Not permitted"
|
||||
render plain: "Not permitted"
|
||||
end
|
||||
else
|
||||
redirect_to login_path(:return_to => request.fullpath)
|
||||
redirect_to login_path(return_to: request.fullpath)
|
||||
end
|
||||
end
|
||||
|
||||
def require_organization_owner
|
||||
unless organization.owner == current_user
|
||||
redirect_to organization_root_path(organization), :alert => "This page can only be accessed by the organization's owner (#{organization.owner.name})"
|
||||
end
|
||||
return if organization.owner == current_user
|
||||
|
||||
redirect_to organization_root_path(organization), alert: "This page can only be accessed by the organization's owner (#{organization.owner.name})"
|
||||
end
|
||||
|
||||
def auth_session_error(exception)
|
||||
Rails.logger.info "AuthSessionError: #{exception.class}: #{exception.message}"
|
||||
redirect_to login_path(:return_to => request.fullpath)
|
||||
redirect_to login_path(return_to: request.fullpath)
|
||||
end
|
||||
|
||||
def page_title
|
||||
@@ -46,7 +46,7 @@ class ApplicationController < ActionController::Base
|
||||
helper_method :page_title
|
||||
|
||||
def redirect_to_with_return_to(url, *args)
|
||||
if params[:return_to].blank? || !params[:return_to].starts_with?('/')
|
||||
if params[:return_to].blank? || !params[:return_to].starts_with?("/")
|
||||
redirect_to url_with_return_to(url), *args
|
||||
else
|
||||
redirect_to url_with_return_to(url), *args
|
||||
@@ -54,7 +54,7 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def set_timezone
|
||||
Time.zone = logged_in? ? current_user.time_zone : 'UTC'
|
||||
Time.zone = logged_in? ? current_user.time_zone : "UTC"
|
||||
end
|
||||
|
||||
def append_info_to_payload(payload)
|
||||
@@ -64,7 +64,7 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def url_with_return_to(url)
|
||||
if params[:return_to].blank? || !params[:return_to].starts_with?('/')
|
||||
if params[:return_to].blank? || !params[:return_to].starts_with?("/")
|
||||
url_for(url)
|
||||
else
|
||||
params[:return_to]
|
||||
@@ -83,14 +83,14 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
respond_to do |wants|
|
||||
wants.html { redirect_to url }
|
||||
wants.json { render :json => {:redirect_to => url} }
|
||||
wants.json { render json: { redirect_to: url } }
|
||||
end
|
||||
end
|
||||
|
||||
def render_form_errors(action_name, object)
|
||||
respond_to do |wants|
|
||||
wants.html { render action_name }
|
||||
wants.json { render :json => {:form_errors => object.errors.full_messages}, :status => 422 }
|
||||
wants.json { render json: { form_errors: object.errors.full_messages }, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -102,7 +102,7 @@ class ApplicationController < ActionController::Base
|
||||
render options[:render_action]
|
||||
end
|
||||
end
|
||||
wants.json { render :json => {:flash => {type => message}} }
|
||||
wants.json { render json: { flash: { type => message } } }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -111,7 +111,7 @@ class ApplicationController < ActionController::Base
|
||||
auth_session.invalidate!
|
||||
reset_session
|
||||
end
|
||||
Authie::Session.start(self, :user => user)
|
||||
Authie::Session.start(self, user: user)
|
||||
@current_user = user
|
||||
end
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class CredentialsController < ApplicationController
|
||||
if @credential.save
|
||||
redirect_to_with_json [organization, @server, :credentials]
|
||||
else
|
||||
render_form_errors 'new', @credential
|
||||
render_form_errors "new", @credential
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ class CredentialsController < ApplicationController
|
||||
if @credential.update(params.require(:credential).permit(:name, :key, :hold))
|
||||
redirect_to_with_json [organization, @server, :credentials]
|
||||
else
|
||||
render_form_errors 'edit', @credential
|
||||
render_form_errors "edit", @credential
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class DomainsController < ApplicationController
|
||||
@domain = scope.build(params.require(:domain).permit(:name, :verification_method))
|
||||
|
||||
if current_user.admin?
|
||||
@domain.verification_method = 'DNS'
|
||||
@domain.verification_method = "DNS"
|
||||
@domain.verified_at = Time.now
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ class DomainsController < ApplicationController
|
||||
redirect_to_with_json [:verify, organization, @server, @domain]
|
||||
end
|
||||
else
|
||||
render_form_errors 'new', @domain
|
||||
render_form_errors "new", @domain
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,56 +50,57 @@ class DomainsController < ApplicationController
|
||||
|
||||
def verify
|
||||
if @domain.verified?
|
||||
redirect_to [organization, @server, :domains], :alert => "#{@domain.name} has already been verified."
|
||||
redirect_to [organization, @server, :domains], alert: "#{@domain.name} has already been verified."
|
||||
return
|
||||
end
|
||||
|
||||
if request.post?
|
||||
case @domain.verification_method
|
||||
when 'DNS'
|
||||
if @domain.verify_with_dns
|
||||
redirect_to_with_json [:setup, organization, @server, @domain], :notice => "#{@domain.name} has been verified successfully. You now need to configure your DNS records."
|
||||
return unless request.post?
|
||||
|
||||
case @domain.verification_method
|
||||
when "DNS"
|
||||
if @domain.verify_with_dns
|
||||
redirect_to_with_json [:setup, organization, @server, @domain], notice: "#{@domain.name} has been verified successfully. You now need to configure your DNS records."
|
||||
else
|
||||
respond_to do |wants|
|
||||
wants.html { flash.now[:alert] = "We couldn't verify your domain. Please double check you've added the TXT record correctly." }
|
||||
wants.json { render json: { flash: { alert: "We couldn't verify your domain. Please double check you've added the TXT record correctly." } } }
|
||||
end
|
||||
end
|
||||
when "Email"
|
||||
if params[:code]
|
||||
if @domain.verification_token == params[:code].to_s.strip
|
||||
@domain.verify
|
||||
redirect_to_with_json [:setup, organization, @server, @domain], notice: "#{@domain.name} has been verified successfully. You now need to configure your DNS records."
|
||||
else
|
||||
respond_to do |wants|
|
||||
wants.html { flash.now[:alert] = "We couldn't verify your domain. Please double check you've added the TXT record correctly." }
|
||||
wants.json { render :json => {:flash => {:alert => "We couldn't verify your domain. Please double check you've added the TXT record correctly."}}}
|
||||
wants.html { flash.now[:alert] = "Invalid verification code. Please check and try again." }
|
||||
wants.json { render json: { flash: { alert: "Invalid verification code. Please check and try again." } } }
|
||||
end
|
||||
end
|
||||
when 'Email'
|
||||
if params[:code]
|
||||
if @domain.verification_token == params[:code].to_s.strip
|
||||
@domain.verify
|
||||
redirect_to_with_json [:setup, organization, @server, @domain], :notice => "#{@domain.name} has been verified successfully. You now need to configure your DNS records."
|
||||
else
|
||||
respond_to do |wants|
|
||||
wants.html { flash.now[:alert] = "Invalid verification code. Please check and try again." }
|
||||
wants.json { render :json => {:flash => {:alert => "Invalid verification code. Please check and try again."}}}
|
||||
end
|
||||
end
|
||||
elsif params[:email_address].present?
|
||||
raise Postal::Error, "Invalid email address" unless @domain.verification_email_addresses.include?(params[:email_address])
|
||||
AppMailer.verify_domain(@domain, params[:email_address], current_user).deliver
|
||||
if @domain.owner.is_a?(Server)
|
||||
redirect_to_with_json verify_organization_server_domain_path(organization, @server, @domain, :email_address => params[:email_address])
|
||||
else
|
||||
redirect_to_with_json verify_organization_domain_path(organization, @domain, :email_address => params[:email_address])
|
||||
end
|
||||
elsif params[:email_address].present?
|
||||
raise Postal::Error, "Invalid email address" unless @domain.verification_email_addresses.include?(params[:email_address])
|
||||
|
||||
AppMailer.verify_domain(@domain, params[:email_address], current_user).deliver
|
||||
if @domain.owner.is_a?(Server)
|
||||
redirect_to_with_json verify_organization_server_domain_path(organization, @server, @domain, email_address: params[:email_address])
|
||||
else
|
||||
redirect_to_with_json verify_organization_domain_path(organization, @domain, email_address: params[:email_address])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
unless @domain.verified?
|
||||
redirect_to [:verify, organization, @server, @domain], :alert => "You can't set up DNS for this domain until it has been verified."
|
||||
end
|
||||
return if @domain.verified?
|
||||
|
||||
redirect_to [:verify, organization, @server, @domain], alert: "You can't set up DNS for this domain until it has been verified."
|
||||
end
|
||||
|
||||
def check
|
||||
if @domain.check_dns(:manual)
|
||||
redirect_to_with_json [organization, @server, :domains], :notice => "Your DNS records for #{@domain.name} look good!"
|
||||
redirect_to_with_json [organization, @server, :domains], notice: "Your DNS records for #{@domain.name} look good!"
|
||||
else
|
||||
redirect_to_with_json [:setup, organization, @server, @domain], :alert => "There seems to be something wrong with your DNS records. Check below for information."
|
||||
redirect_to_with_json [:setup, organization, @server, @domain], alert: "There seems to be something wrong with your DNS records. Check below for information."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class HTTPEndpointsController < ApplicationController
|
||||
flash[:notice] = params[:return_notice] if params[:return_notice].present?
|
||||
redirect_to_with_json [:return_to, [organization, @server, :http_endpoints]]
|
||||
else
|
||||
render_form_errors 'new', @http_endpoint
|
||||
render_form_errors "new", @http_endpoint
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ class HTTPEndpointsController < ApplicationController
|
||||
if @http_endpoint.update(safe_params)
|
||||
redirect_to_with_json [organization, @server, :http_endpoints]
|
||||
else
|
||||
render_form_errors 'edit', @http_endpoint
|
||||
render_form_errors "edit", @http_endpoint
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class IPAddressesController < ApplicationController
|
||||
if @ip_address.save
|
||||
redirect_to_with_json [:edit, @ip_pool]
|
||||
else
|
||||
render_form_errors 'new', @ip_address
|
||||
render_form_errors "new", @ip_address
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ class IPAddressesController < ApplicationController
|
||||
if @ip_address.update(safe_params)
|
||||
redirect_to_with_json [:edit, @ip_pool]
|
||||
else
|
||||
render_form_errors 'edit', @ip_address
|
||||
render_form_errors "edit", @ip_address
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class IPPoolRulesController < ApplicationController
|
||||
if @ip_pool_rule.save
|
||||
redirect_to_with_json [organization, @server, :ip_pool_rules]
|
||||
else
|
||||
render_form_errors 'new', @ip_pool_rule
|
||||
render_form_errors "new", @ip_pool_rule
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ class IPPoolRulesController < ApplicationController
|
||||
if @ip_pool_rule.update(safe_params)
|
||||
redirect_to_with_json [organization, @server, :ip_pool_rules]
|
||||
else
|
||||
render_form_errors 'edit', @ip_pool_rule
|
||||
render_form_errors "edit", @ip_pool_rule
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -14,25 +14,25 @@ class IPPoolsController < ApplicationController
|
||||
def create
|
||||
@ip_pool = IPPool.new(safe_params)
|
||||
if @ip_pool.save
|
||||
redirect_to_with_json [:edit, @ip_pool], :notice => "IP Pool has been added successfully. You can now add IP addresses to it."
|
||||
redirect_to_with_json [:edit, @ip_pool], notice: "IP Pool has been added successfully. You can now add IP addresses to it."
|
||||
else
|
||||
render_form_errors 'new', @ip_pool
|
||||
render_form_errors "new", @ip_pool
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @ip_pool.update(safe_params)
|
||||
redirect_to_with_json [:edit, @ip_pool], :notice => "IP Pool has been updated."
|
||||
redirect_to_with_json [:edit, @ip_pool], notice: "IP Pool has been updated."
|
||||
else
|
||||
render_form_errors 'edit', @ip_pool
|
||||
render_form_errors "edit", @ip_pool
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@ip_pool.destroy
|
||||
redirect_to_with_json :ip_pools, :notice => "IP pool has been removed successfully."
|
||||
redirect_to_with_json :ip_pools, notice: "IP pool has been removed successfully."
|
||||
rescue ActiveRecord::DeleteRestrictionError => e
|
||||
redirect_to_with_json [:edit, @ip_pool], :alert => "IP pool cannot be removed because it still has associated addresses or servers."
|
||||
redirect_to_with_json [:edit, @ip_pool], alert: "IP pool cannot be removed because it still has associated addresses or servers."
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class MessagesController < ApplicationController
|
||||
class MessagesController < ApplicationController
|
||||
|
||||
include WithinOrganization
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
before_action { params[:id] && @message = @server.message_db.message(params[:id].to_i) }
|
||||
|
||||
def new
|
||||
if params[:direction] == 'incoming'
|
||||
@message = IncomingMessagePrototype.new(@server, request.ip, 'web-ui', {})
|
||||
if params[:direction] == "incoming"
|
||||
@message = IncomingMessagePrototype.new(@server, request.ip, "web-ui", {})
|
||||
@message.from = session[:test_in_from] || current_user.email_tag
|
||||
@message.to = @server.routes.order(:name).first&.description
|
||||
else
|
||||
@message = OutgoingMessagePrototype.new(@server, request.ip, 'web-ui', {})
|
||||
@message = OutgoingMessagePrototype.new(@server, request.ip, "web-ui", {})
|
||||
@message.to = session[:test_out_to] || current_user.email_address
|
||||
if domain = @server.domains.verified.order(:name).first
|
||||
@message.from = "test@#{domain.name}"
|
||||
@@ -22,28 +22,28 @@
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:direction] == 'incoming'
|
||||
if params[:direction] == "incoming"
|
||||
session[:test_in_from] = params[:message][:from] if params[:message]
|
||||
@message = IncomingMessagePrototype.new(@server, request.ip, 'web-ui', params[:message])
|
||||
@message.attachments = [{:name => "test.txt", :content_type => "text/plain", :data => "Hello world!"}]
|
||||
@message = IncomingMessagePrototype.new(@server, request.ip, "web-ui", params[:message])
|
||||
@message.attachments = [{ name: "test.txt", content_type: "text/plain", data: "Hello world!" }]
|
||||
else
|
||||
session[:test_out_to] = params[:message][:to] if params[:message]
|
||||
@message = OutgoingMessagePrototype.new(@server, request.ip, 'web-ui', params[:message])
|
||||
@message = OutgoingMessagePrototype.new(@server, request.ip, "web-ui", params[:message])
|
||||
end
|
||||
if result = @message.create_messages
|
||||
if result.size == 1
|
||||
redirect_to_with_json organization_server_message_path(organization, @server, result.first.last[:id]), :notice => "Message was queued successfully"
|
||||
redirect_to_with_json organization_server_message_path(organization, @server, result.first.last[:id]), notice: "Message was queued successfully"
|
||||
else
|
||||
redirect_to_with_json [:queue, organization, @server], :notice => "Messages queued successfully "
|
||||
redirect_to_with_json [:queue, organization, @server], notice: "Messages queued successfully "
|
||||
end
|
||||
else
|
||||
respond_to do |wants|
|
||||
wants.html do
|
||||
flash.now[:alert] = "Your message could not be sent. Ensure that all fields are completed fully. #{result.errors.inspect}"
|
||||
render 'new'
|
||||
render "new"
|
||||
end
|
||||
wants.json do
|
||||
render :json => {:flash => {:alert => "Your message could not be sent. Please check all field are completed fully."}}
|
||||
render json: { flash: { alert: "Your message could not be sent. Please check all field are completed fully." } }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,58 +52,62 @@
|
||||
|
||||
def outgoing
|
||||
@searchable = true
|
||||
get_messages('outgoing')
|
||||
get_messages("outgoing")
|
||||
respond_to do |wants|
|
||||
wants.html
|
||||
wants.json { render :json => {
|
||||
:flash => flash.each_with_object({}) { |(type, message), hash| hash[type] = message},
|
||||
:region_html => render_to_string(:partial => 'index', :formats => [:html])
|
||||
}}
|
||||
wants.json do
|
||||
render json: {
|
||||
flash: flash.each_with_object({}) { |(type, message), hash| hash[type] = message },
|
||||
region_html: render_to_string(partial: "index", formats: [:html])
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def incoming
|
||||
@searchable = true
|
||||
get_messages('incoming')
|
||||
get_messages("incoming")
|
||||
respond_to do |wants|
|
||||
wants.html
|
||||
wants.json { render :json => {
|
||||
:flash => flash.each_with_object({}) { |(type, message), hash| hash[type] = message},
|
||||
:region_html => render_to_string(:partial => 'index', :formats => [:html])
|
||||
}}
|
||||
wants.json do
|
||||
render json: {
|
||||
flash: flash.each_with_object({}) { |(type, message), hash| hash[type] = message },
|
||||
region_html: render_to_string(partial: "index", formats: [:html])
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def held
|
||||
get_messages('held')
|
||||
get_messages("held")
|
||||
end
|
||||
|
||||
def deliveries
|
||||
render :json => {:html => render_to_string(:partial => 'deliveries', :locals => {:message => @message})}
|
||||
render json: { html: render_to_string(partial: "deliveries", locals: { message: @message }) }
|
||||
end
|
||||
|
||||
def html_raw
|
||||
render :html => @message.html_body_without_tracking_image.html_safe
|
||||
render html: @message.html_body_without_tracking_image.html_safe
|
||||
end
|
||||
|
||||
def spam_checks
|
||||
@spam_checks = @message.spam_checks.sort_by { |s| s['score']}.reverse
|
||||
@spam_checks = @message.spam_checks.sort_by { |s| s["score"] }.reverse
|
||||
end
|
||||
|
||||
def attachment
|
||||
if @message.attachments.size > params[:attachment].to_i
|
||||
attachment = @message.attachments[params[:attachment].to_i]
|
||||
send_data attachment.body, :content_type => attachment.mime_type, :disposition => 'download', :filename => attachment.filename
|
||||
send_data attachment.body, content_type: attachment.mime_type, disposition: "download", filename: attachment.filename
|
||||
else
|
||||
redirect_to attachments_organization_server_message_path(organization, @server, @message.id), :alert => "Attachment not found. Choose an attachment from the list below."
|
||||
redirect_to attachments_organization_server_message_path(organization, @server, @message.id), alert: "Attachment not found. Choose an attachment from the list below."
|
||||
end
|
||||
end
|
||||
|
||||
def download
|
||||
if @message.raw_message
|
||||
send_data @message.raw_message, :filename => "Message-#{organization.permalink}-#{@server.permalink}-#{@message.id}.eml", :content_type => "text/plain"
|
||||
send_data @message.raw_message, filename: "Message-#{organization.permalink}-#{@server.permalink}-#{@message.id}.eml", content_type: "text/plain"
|
||||
else
|
||||
redirect_to organization_server_message_path(organization, @server, @message.id), :alert => "We no longer have the raw message stored for this message."
|
||||
redirect_to organization_server_message_path(organization, @server, @message.id), alert: "We no longer have the raw message stored for this message."
|
||||
end
|
||||
end
|
||||
|
||||
@@ -113,10 +117,10 @@
|
||||
@message.queued_message.queue!
|
||||
flash[:notice] = "This message will be retried shortly."
|
||||
elsif @message.held?
|
||||
@message.add_to_message_queue(:manual => true)
|
||||
@message.add_to_message_queue(manual: true)
|
||||
flash[:notice] = "This message has been released. Delivery will be attempted shortly."
|
||||
else
|
||||
@message.add_to_message_queue(:manual => true)
|
||||
@message.add_to_message_queue(manual: true)
|
||||
flash[:notice] = "This message will be redelivered shortly."
|
||||
end
|
||||
else
|
||||
@@ -148,10 +152,10 @@
|
||||
private
|
||||
|
||||
def get_messages(scope)
|
||||
if scope == 'held'
|
||||
options = {:where => {:held => 1}}
|
||||
if scope == "held"
|
||||
options = { where: { held: 1 } }
|
||||
else
|
||||
options = {:where => {:scope => scope, :spam => false}, :order => :timestamp, :direction => 'desc'}
|
||||
options = { where: { scope: scope, spam: false }, order: :timestamp, direction: "desc" }
|
||||
|
||||
if @query = (params[:query] || session["msg_query_#{@server.id}_#{scope}"]).presence
|
||||
session["msg_query_#{@server.id}_#{scope}"] = @query
|
||||
@@ -160,8 +164,8 @@
|
||||
flash.now[:alert] = "It doesn't appear you entered anything to filter on. Please double check your query."
|
||||
else
|
||||
@queried = true
|
||||
if qs[:order] == 'oldest-first'
|
||||
options[:direction] = 'asc'
|
||||
if qs[:order] == "oldest-first"
|
||||
options[:direction] = "asc"
|
||||
end
|
||||
|
||||
options[:where][:rcpt_to] = qs[:to] if qs[:to]
|
||||
@@ -176,7 +180,7 @@
|
||||
end
|
||||
options[:where][:tag] = qs[:tag] if qs[:tag]
|
||||
options[:where][:id] = qs[:id] if qs[:id]
|
||||
options[:where][:spam] = true if qs[:spam] == 'yes' || qs[:spam] == 'y'
|
||||
options[:where][:spam] = true if qs[:spam] == "yes" || qs[:spam] == "y"
|
||||
if qs[:before] || qs[:after]
|
||||
options[:where][:timestamp] = {}
|
||||
if qs[:before]
|
||||
@@ -208,21 +212,19 @@
|
||||
|
||||
def get_time_from_string(string)
|
||||
begin
|
||||
if string =~ /\A(\d{2,4})\-(\d{2})\-(\d{2}) (\d{2})\:(\d{2})\z/
|
||||
time = Time.new($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i)
|
||||
elsif string =~ /\A(\d{2,4})\-(\d{2})\-(\d{2})\z/
|
||||
time = Time.new($1.to_i, $2.to_i, $3.to_i, 0)
|
||||
if string =~ /\A(\d{2,4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\z/
|
||||
time = Time.new(::Regexp.last_match(1).to_i, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i, ::Regexp.last_match(4).to_i, ::Regexp.last_match(5).to_i)
|
||||
elsif string =~ /\A(\d{2,4})-(\d{2})-(\d{2})\z/
|
||||
time = Time.new(::Regexp.last_match(1).to_i, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i, 0)
|
||||
else
|
||||
time = Chronic.parse(string, :context => :past)
|
||||
time = Chronic.parse(string, context: :past)
|
||||
end
|
||||
rescue
|
||||
rescue StandardError
|
||||
end
|
||||
|
||||
if time.nil?
|
||||
raise TimeUndetermined, "Couldn't determine a suitable time from '#{string}'"
|
||||
else
|
||||
time
|
||||
end
|
||||
raise TimeUndetermined, "Couldn't determine a suitable time from '#{string}'" if time.nil?
|
||||
|
||||
time
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class OrganizationIPPoolsController < ApplicationController
|
||||
|
||||
include WithinOrganization
|
||||
before_action :admin_required, :only => [:assignments]
|
||||
before_action :admin_required, only: [:assignments]
|
||||
|
||||
def index
|
||||
@ip_pools = organization.ip_pools.order(:name)
|
||||
@@ -10,7 +10,7 @@ class OrganizationIPPoolsController < ApplicationController
|
||||
def assignments
|
||||
organization.ip_pool_ids = params[:ip_pools]
|
||||
organization.save!
|
||||
redirect_to [organization, :ip_pools], :notice => "Organization IP pools have been updated successfully"
|
||||
redirect_to [organization, :ip_pools], notice: "Organization IP pools have been updated successfully"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class OrganizationsController < ApplicationController
|
||||
|
||||
before_action :admin_required, :only => [:new, :create, :delete, :destroy]
|
||||
before_action :admin_required, only: [:new, :create, :delete, :destroy]
|
||||
|
||||
def index
|
||||
if current_user.admin?
|
||||
@@ -17,48 +17,48 @@ class OrganizationsController < ApplicationController
|
||||
@organization = Organization.new
|
||||
end
|
||||
|
||||
def edit
|
||||
@organization_obj = current_user.organizations_scope.find(organization.id)
|
||||
end
|
||||
|
||||
def create
|
||||
@organization = Organization.new(params.require(:organization).permit(:name, :permalink))
|
||||
@organization.owner = current_user
|
||||
if @organization.save
|
||||
redirect_to_with_json organization_root_path(@organization)
|
||||
else
|
||||
render_form_errors 'new', @organization
|
||||
render_form_errors "new", @organization
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@organization_obj = current_user.organizations_scope.find(organization.id)
|
||||
end
|
||||
|
||||
def update
|
||||
@organization_obj = current_user.organizations_scope.find(organization.id)
|
||||
if @organization_obj.update(params.require(:organization).permit(:name, :time_zone))
|
||||
redirect_to_with_json organization_settings_path(@organization_obj), :notice => "Settings for #{@organization_obj.name} have been saved successfully."
|
||||
redirect_to_with_json organization_settings_path(@organization_obj), notice: "Settings for #{@organization_obj.name} have been saved successfully."
|
||||
else
|
||||
render_form_errors 'edit', @organization_obj
|
||||
render_form_errors "edit", @organization_obj
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
unless current_user.authenticate(params[:password])
|
||||
respond_to do |wants|
|
||||
wants.html { redirect_to organization_delete_path(@organization), :alert => "The password you entered was not valid. Please check and try again." }
|
||||
wants.json { render :json => {:alert => "The password you entered was invalid. Please check and try again."} }
|
||||
wants.html { redirect_to organization_delete_path(@organization), alert: "The password you entered was not valid. Please check and try again." }
|
||||
wants.json { render json: { alert: "The password you entered was invalid. Please check and try again." } }
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
organization.soft_destroy
|
||||
redirect_to_with_json root_path(:nrd => 1), :notice => "#{@organization.name} has been removed successfully."
|
||||
redirect_to_with_json root_path(nrd: 1), notice: "#{@organization.name} has been removed successfully."
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def organization
|
||||
if [:edit, :update, :delete, :destroy].include?(action_name.to_sym)
|
||||
@organization ||= params[:org_permalink] ? current_user.organizations_scope.find_by_permalink!(params[:org_permalink]) : nil
|
||||
end
|
||||
return unless [:edit, :update, :delete, :destroy].include?(action_name.to_sym)
|
||||
|
||||
@organization ||= params[:org_permalink] ? current_user.organizations_scope.find_by_permalink!(params[:org_permalink]) : nil
|
||||
end
|
||||
helper_method :organization
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class RoutesController < ApplicationController
|
||||
if @route.save
|
||||
redirect_to_with_json [organization, @server, :routes]
|
||||
else
|
||||
render_form_errors 'new', @route
|
||||
render_form_errors "new", @route
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ class RoutesController < ApplicationController
|
||||
if @route.update(safe_params)
|
||||
redirect_to_with_json [organization, @server, :routes]
|
||||
else
|
||||
render_form_errors 'edit', @route
|
||||
render_form_errors "edit", @route
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,7 +38,7 @@ class RoutesController < ApplicationController
|
||||
private
|
||||
|
||||
def safe_params
|
||||
params.require(:route).permit(:name, :domain_id, :spam_mode, :_endpoint, :additional_route_endpoints_array => [])
|
||||
params.require(:route).permit(:name, :domain_id, :spam_mode, :_endpoint, additional_route_endpoints_array: [])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ class ServersController < ApplicationController
|
||||
|
||||
include WithinOrganization
|
||||
|
||||
before_action :admin_required, :only => [:advanced, :suspend, :unsuspend]
|
||||
before_action :admin_required, only: [:advanced, :suspend, :unsuspend]
|
||||
before_action { params[:id] && @server = organization.servers.present.find_by_permalink!(params[:id]) }
|
||||
|
||||
def index
|
||||
@@ -23,7 +23,7 @@ class ServersController < ApplicationController
|
||||
@first_date = graph_data.first.first
|
||||
@last_date = graph_data.last.first
|
||||
@graph_data = graph_data.map(&:last)
|
||||
@messages = @server.message_db.messages(:order => 'id', :direction => 'desc', :limit => 6)
|
||||
@messages = @server.message_db.messages(order: "id", direction: "desc", limit: 6)
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -35,7 +35,7 @@ class ServersController < ApplicationController
|
||||
if @server.save
|
||||
redirect_to_with_json organization_server_path(organization, @server)
|
||||
else
|
||||
render_form_errors 'new', @server
|
||||
render_form_errors "new", @server
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,9 +43,9 @@ class ServersController < ApplicationController
|
||||
extra_params = [:spam_threshold, :spam_failure_threshold, :postmaster_address]
|
||||
extra_params += [:send_limit, :allow_sender, :log_smtp_data, :outbound_spam_threshold, :message_retention_days, :raw_message_retention_days, :raw_message_retention_size] if current_user.admin?
|
||||
if @server.update(safe_params(*extra_params))
|
||||
redirect_to_with_json organization_server_path(organization, @server), :notice => "Server settings have been updated"
|
||||
redirect_to_with_json organization_server_path(organization, @server), notice: "Server settings have been updated"
|
||||
else
|
||||
render_form_errors 'edit', @server
|
||||
render_form_errors "edit", @server
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,31 +53,31 @@ class ServersController < ApplicationController
|
||||
unless current_user.authenticate(params[:password])
|
||||
respond_to do |wants|
|
||||
wants.html do
|
||||
redirect_to [:delete, organization, @server], :alert => "The password you entered was not valid. Please check and try again."
|
||||
redirect_to [:delete, organization, @server], alert: "The password you entered was not valid. Please check and try again."
|
||||
end
|
||||
wants.json do
|
||||
render :json => {:alert => "The password you entere was invalid. Please check and try again"}
|
||||
render json: { alert: "The password you entere was invalid. Please check and try again" }
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
@server.soft_destroy
|
||||
redirect_to_with_json organization_root_path(organization), :notice => "#{@server.name} has been deleted successfully"
|
||||
redirect_to_with_json organization_root_path(organization), notice: "#{@server.name} has been deleted successfully"
|
||||
end
|
||||
|
||||
def queue
|
||||
@messages = @server.queued_messages.order(:id => :desc).page(params[:page])
|
||||
@messages = @server.queued_messages.order(id: :desc).page(params[:page])
|
||||
@messages_with_message = @messages.include_message
|
||||
end
|
||||
|
||||
def suspend
|
||||
@server.suspend(params[:reason])
|
||||
redirect_to_with_json [organization, @server], :notice => "Server has been suspended"
|
||||
redirect_to_with_json [organization, @server], notice: "Server has been suspended"
|
||||
end
|
||||
|
||||
def unsuspend
|
||||
@server.unsuspend
|
||||
redirect_to_with_json [organization, @server], :notice => "Server has been unsuspended"
|
||||
redirect_to_with_json [organization, @server], notice: "Server has been unsuspended"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class SessionsController < ApplicationController
|
||||
|
||||
layout 'sub'
|
||||
layout "sub"
|
||||
|
||||
skip_before_action :login_required, :only => [:new, :create, :create_with_token, :begin_password_reset, :finish_password_reset, :ip, :raise_error]
|
||||
skip_before_action :login_required, only: [:new, :create, :create_with_token, :begin_password_reset, :finish_password_reset, :ip, :raise_error]
|
||||
|
||||
def create
|
||||
login(User.authenticate(params[:email_address], params[:password]))
|
||||
@@ -10,13 +10,13 @@ class SessionsController < ApplicationController
|
||||
redirect_to_with_return_to root_path
|
||||
rescue Postal::Errors::AuthenticationError => e
|
||||
flash.now[:alert] = "The credentials you've provided are incorrect. Please check and try again."
|
||||
render 'new'
|
||||
render "new"
|
||||
end
|
||||
|
||||
def create_with_token
|
||||
result = JWT.decode(params[:token], Postal.signing_key.to_s, 'HS256')[0]
|
||||
if result['timestamp'] > 1.minute.ago.to_f
|
||||
login(User.find(result['user'].to_i))
|
||||
result = JWT.decode(params[:token], Postal.signing_key.to_s, "HS256")[0]
|
||||
if result["timestamp"] > 1.minute.ago.to_f
|
||||
login(User.find(result["user"].to_i))
|
||||
redirect_to root_path
|
||||
else
|
||||
destroy
|
||||
@@ -33,42 +33,42 @@ class SessionsController < ApplicationController
|
||||
|
||||
def persist
|
||||
auth_session.persist! if logged_in?
|
||||
render :plain => "OK"
|
||||
render plain: "OK"
|
||||
end
|
||||
|
||||
def begin_password_reset
|
||||
if request.post?
|
||||
if user = User.where(:email_address => params[:email_address]).first
|
||||
user.begin_password_reset(params[:return_to])
|
||||
redirect_to login_path(:return_to => params[:return_to]), :notice => "Please check your e-mail and click the link in the e-mail we've sent you."
|
||||
else
|
||||
redirect_to login_reset_path(:return_to => params[:return_to]), :alert => "No user exists with that e-mail address. Please check and try again."
|
||||
end
|
||||
return unless request.post?
|
||||
|
||||
if user = User.where(email_address: params[:email_address]).first
|
||||
user.begin_password_reset(params[:return_to])
|
||||
redirect_to login_path(return_to: params[:return_to]), notice: "Please check your e-mail and click the link in the e-mail we've sent you."
|
||||
else
|
||||
redirect_to login_reset_path(return_to: params[:return_to]), alert: "No user exists with that e-mail address. Please check and try again."
|
||||
end
|
||||
end
|
||||
|
||||
def finish_password_reset
|
||||
@user = User.where(:password_reset_token => params[:token]).where("password_reset_token_valid_until > ?", Time.now).first
|
||||
@user = User.where(password_reset_token: params[:token]).where("password_reset_token_valid_until > ?", Time.now).first
|
||||
if @user.nil?
|
||||
redirect_to login_path(:return_to => params[:return_to]), :alert => "This link has expired or never existed. Please choose reset password to try again."
|
||||
redirect_to login_path(return_to: params[:return_to]), alert: "This link has expired or never existed. Please choose reset password to try again."
|
||||
end
|
||||
|
||||
if request.post?
|
||||
if params[:password].blank?
|
||||
flash.now[:alert] = "You must enter a new password"
|
||||
return
|
||||
end
|
||||
@user.password = params[:password]
|
||||
@user.password_confirmation = params[:password_confirmation]
|
||||
if @user.save
|
||||
login(@user)
|
||||
redirect_to_with_return_to root_path, :notice => "Your new password has been set and you've been logged in."
|
||||
end
|
||||
return unless request.post?
|
||||
|
||||
if params[:password].blank?
|
||||
flash.now[:alert] = "You must enter a new password"
|
||||
return
|
||||
end
|
||||
@user.password = params[:password]
|
||||
@user.password_confirmation = params[:password_confirmation]
|
||||
return unless @user.save
|
||||
|
||||
login(@user)
|
||||
redirect_to_with_return_to root_path, notice: "Your new password has been set and you've been logged in."
|
||||
end
|
||||
|
||||
def ip
|
||||
render :plain => "ip: #{request.ip} remote ip: #{request.remote_ip}"
|
||||
render plain: "ip: #{request.ip} remote ip: #{request.remote_ip}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class SMTPEndpointsController < ApplicationController
|
||||
|
||||
include WithinOrganization
|
||||
before_action { @server = organization.servers.present.find_by_permalink!(params[:server_id]) }
|
||||
before_action { params[:id] && @smtp_endpoint = @server.smtp_endpoints.find_by_uuid!(params[:id]) }
|
||||
@@ -17,7 +18,7 @@ class SMTPEndpointsController < ApplicationController
|
||||
flash[:notice] = params[:return_notice] if params[:return_notice].present?
|
||||
redirect_to_with_json [:return_to, [organization, @server, :smtp_endpoints]]
|
||||
else
|
||||
render_form_errors 'new', @smtp_endpoint
|
||||
render_form_errors "new", @smtp_endpoint
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +26,7 @@ class SMTPEndpointsController < ApplicationController
|
||||
if @smtp_endpoint.update(safe_params)
|
||||
redirect_to_with_json [organization, @server, :smtp_endpoints]
|
||||
else
|
||||
render_form_errors 'edit', @smtp_endpoint
|
||||
render_form_errors "edit", @smtp_endpoint
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class TrackDomainsController < ApplicationController
|
||||
|
||||
include WithinOrganization
|
||||
before_action { @server = organization.servers.present.find_by_permalink!(params[:server_id]) }
|
||||
before_action { params[:id] && @track_domain = @server.track_domains.find_by_uuid!(params[:id]) }
|
||||
@@ -16,7 +17,7 @@ class TrackDomainsController < ApplicationController
|
||||
if @track_domain.save
|
||||
redirect_to_with_json [:return_to, [organization, @server, :track_domains]]
|
||||
else
|
||||
render_form_errors 'new', @track_domain
|
||||
render_form_errors "new", @track_domain
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +25,7 @@ class TrackDomainsController < ApplicationController
|
||||
if @track_domain.update(params.require(:track_domain).permit(:track_loads, :track_clicks, :excluded_click_domains, :ssl_enabled))
|
||||
redirect_to_with_json [organization, @server, :track_domains]
|
||||
else
|
||||
render_form_errors 'edit', @track_domain
|
||||
render_form_errors "edit", @track_domain
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,15 +36,15 @@ class TrackDomainsController < ApplicationController
|
||||
|
||||
def check
|
||||
if @track_domain.check_dns
|
||||
redirect_to_with_json [organization, @server, :track_domains], :notice => "Your CNAME for #{@track_domain.full_name} looks good!"
|
||||
redirect_to_with_json [organization, @server, :track_domains], notice: "Your CNAME for #{@track_domain.full_name} looks good!"
|
||||
else
|
||||
redirect_to_with_json [organization, @server, :track_domains], :alert => "There seems to be something wrong with your DNS record. Check documentation for information."
|
||||
redirect_to_with_json [organization, @server, :track_domains], alert: "There seems to be something wrong with your DNS record. Check documentation for information."
|
||||
end
|
||||
end
|
||||
|
||||
def toggle_ssl
|
||||
@track_domain.update(:ssl_enabled => !@track_domain.ssl_enabled)
|
||||
redirect_to_with_json [organization, @server, :track_domains], :notice => "SSL settings for #{@track_domain.full_name} updated successfully."
|
||||
@track_domain.update(ssl_enabled: !@track_domain.ssl_enabled)
|
||||
redirect_to_with_json [organization, @server, :track_domains], notice: "SSL settings for #{@track_domain.full_name} updated successfully."
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
class UserController < ApplicationController
|
||||
|
||||
skip_before_action :login_required, :only => [:new, :create, :join]
|
||||
skip_before_action :login_required, only: [:new, :create, :join]
|
||||
|
||||
def new
|
||||
@user_invite = UserInvite.active.find_by!(:uuid => params[:invite_token])
|
||||
@user_invite = UserInvite.active.find_by!(uuid: params[:invite_token])
|
||||
@user = User.new
|
||||
@user.email_address = @user_invite.email_address
|
||||
render :layout => 'sub'
|
||||
render layout: "sub"
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.find(current_user.id)
|
||||
end
|
||||
|
||||
def create
|
||||
@user_invite = UserInvite.active.find_by!(:uuid => params[:invite_token])
|
||||
@user_invite = UserInvite.active.find_by!(uuid: params[:invite_token])
|
||||
@user = User.new(params.require(:user).permit(:first_name, :last_name, :email_address, :password, :password_confirmation))
|
||||
@user.email_verified_at = Time.now
|
||||
if @user.save
|
||||
@@ -18,19 +22,19 @@ class UserController < ApplicationController
|
||||
self.current_user = @user
|
||||
redirect_to root_path
|
||||
else
|
||||
render 'new', :layout => 'sub'
|
||||
render "new", layout: "sub"
|
||||
end
|
||||
end
|
||||
|
||||
def join
|
||||
if @invite = UserInvite.where(:uuid => params[:token]).where("expires_at > ?", Time.now).first
|
||||
if @invite = UserInvite.where(uuid: params[:token]).where("expires_at > ?", Time.now).first
|
||||
if logged_in?
|
||||
if request.post?
|
||||
@invite.accept(current_user)
|
||||
redirect_to_with_json root_path(:nrd => 1), :notice => "Invitation has been accepted successfully. You now have access to this organization."
|
||||
redirect_to_with_json root_path(nrd: 1), notice: "Invitation has been accepted successfully. You now have access to this organization."
|
||||
elsif request.delete?
|
||||
@invite.reject
|
||||
redirect_to_with_json root_path(:nrd => 1), :notice => "Invitation has been rejected successfully."
|
||||
redirect_to_with_json root_path(nrd: 1), notice: "Invitation has been rejected successfully."
|
||||
else
|
||||
@organizations = @invite.organizations.order(:name).to_a
|
||||
end
|
||||
@@ -38,14 +42,10 @@ class UserController < ApplicationController
|
||||
redirect_to new_signup_path(params[:token])
|
||||
end
|
||||
else
|
||||
redirect_to_with_json root_path(:nrd => 1), :alert => "The invite URL you have has expired. Please ask the person who invited you to re-send your invitation."
|
||||
redirect_to_with_json root_path(nrd: 1), alert: "The invite URL you have has expired. Please ask the person who invited you to re-send your invitation."
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.find(current_user.id)
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find(current_user.id)
|
||||
@user.attributes = params.require(:user).permit(:first_name, :last_name, :time_zone, :email_address, :password, :password_confirmation)
|
||||
@@ -56,10 +56,10 @@ class UserController < ApplicationController
|
||||
respond_to do |wants|
|
||||
wants.html do
|
||||
flash.now[:alert] = "The current password you have entered is incorrect. Please check and try again."
|
||||
render 'edit'
|
||||
render "edit"
|
||||
end
|
||||
wants.json do
|
||||
render :json => {:alert => "The current password you've entered is incorrect. Please check and try again"}
|
||||
render json: { alert: "The current password you've entered is incorrect. Please check and try again" }
|
||||
end
|
||||
end
|
||||
return
|
||||
@@ -69,23 +69,23 @@ class UserController < ApplicationController
|
||||
|
||||
if @user.save
|
||||
if email_changed
|
||||
redirect_to_with_json verify_path(:return_to => settings_path), :notice => "Your settings have been updated successfully. As you've changed, your e-mail address you'll need to verify it before you can continue."
|
||||
redirect_to_with_json verify_path(return_to: settings_path), notice: "Your settings have been updated successfully. As you've changed, your e-mail address you'll need to verify it before you can continue."
|
||||
else
|
||||
redirect_to_with_json settings_path, :notice => "Your settings have been updated successfully."
|
||||
redirect_to_with_json settings_path, notice: "Your settings have been updated successfully."
|
||||
end
|
||||
else
|
||||
render_form_errors 'edit', @user
|
||||
render_form_errors "edit", @user
|
||||
end
|
||||
end
|
||||
|
||||
def verify
|
||||
if request.post?
|
||||
if params[:code].to_s.strip == current_user.email_verification_token.to_s || (Rails.env.development? && params[:code].to_s.strip == "123456")
|
||||
current_user.verify!
|
||||
redirect_to_with_json [:return_to, root_path], :notice => "Thanks - your e-mail address has been verified successfully."
|
||||
else
|
||||
flash_now :alert, "The code you've entered isn't correct. Please check and try again."
|
||||
end
|
||||
return unless request.post?
|
||||
|
||||
if params[:code].to_s.strip == current_user.email_verification_token.to_s || (Rails.env.development? && params[:code].to_s.strip == "123456")
|
||||
current_user.verify!
|
||||
redirect_to_with_json [:return_to, root_path], notice: "Thanks - your e-mail address has been verified successfully."
|
||||
else
|
||||
flash_now :alert, "The code you've entered isn't correct. Please check and try again."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -11,45 +11,44 @@ class UsersController < ApplicationController
|
||||
@user = User.new(admin: true)
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(params.require(:user).permit(:email_address, :first_name, :last_name, :password, :password_confirmation, :admin, organization_ids: []))
|
||||
if @user.save
|
||||
redirect_to_with_json :users, :notice => "#{@user.name} has been created successfully."
|
||||
redirect_to_with_json :users, notice: "#{@user.name} has been created successfully."
|
||||
else
|
||||
render_form_errors 'new', @user
|
||||
render_form_errors "new", @user
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@user.attributes = params.require(:user).permit(:email_address, :first_name, :last_name, :admin, organization_ids: [])
|
||||
|
||||
if @user == current_user && !@user.admin?
|
||||
respond_to do |wants|
|
||||
wants.html { redirect_to users_path, alert: "You cannot change your own admin status" }
|
||||
wants.json { render :json => {:form_errors => ["You cannot change your own admin status"]}, :status => 422 }
|
||||
wants.json { render json: { form_errors: ["You cannot change your own admin status"] }, status: :unprocessable_entity }
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if @user.save
|
||||
redirect_to_with_json :users, :notice => "Permissions for #{@user.name} have been updated successfully."
|
||||
redirect_to_with_json :users, notice: "Permissions for #{@user.name} have been updated successfully."
|
||||
else
|
||||
render_form_errors 'edit', @user
|
||||
render_form_errors "edit", @user
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @user == current_user
|
||||
redirect_to_with_json :users, :alert => "You cannot delete your own user."
|
||||
redirect_to_with_json :users, alert: "You cannot delete your own user."
|
||||
return
|
||||
end
|
||||
|
||||
@user.destroy!
|
||||
redirect_to_with_json :users, :notice => "#{@user.name} has been removed"
|
||||
redirect_to_with_json :users, notice: "#{@user.name} has been removed"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class WebhooksController < ApplicationController
|
||||
|
||||
include WithinOrganization
|
||||
before_action { @server = organization.servers.present.find_by_permalink!(params[:server_id]) }
|
||||
before_action { params[:id] && @webhook = @server.webhooks.find_by_uuid!(params[:id]) }
|
||||
@@ -8,7 +9,7 @@ class WebhooksController < ApplicationController
|
||||
end
|
||||
|
||||
def new
|
||||
@webhook = @server.webhooks.build(:all_events => true)
|
||||
@webhook = @server.webhooks.build(all_events: true)
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -16,7 +17,7 @@ class WebhooksController < ApplicationController
|
||||
if @webhook.save
|
||||
redirect_to_with_json [organization, @server, :webhooks]
|
||||
else
|
||||
render_form_errors 'new', @webhook
|
||||
render_form_errors "new", @webhook
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +25,7 @@ class WebhooksController < ApplicationController
|
||||
if @webhook.update(safe_params)
|
||||
redirect_to_with_json [organization, @server, :webhooks]
|
||||
else
|
||||
render_form_errors 'edit', @webhook
|
||||
render_form_errors "edit", @webhook
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,7 +46,7 @@ class WebhooksController < ApplicationController
|
||||
private
|
||||
|
||||
def safe_params
|
||||
params.require(:webhook).permit(:name, :url, :all_events, :enabled, :events => [])
|
||||
params.require(:webhook).permit(:name, :url, :all_events, :enabled, events: [])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم