Commit b633c096 authored by Rafael Ravedutti's avatar Rafael Ravedutti

Merge branch 'develop' into 'password_reset_email_change'

# Conflicts:
#   docker-compose.yml
parents 5140a717 5c42ebd5
Pipeline #17143 passed with stages
in 3 minutes
......@@ -2,3 +2,5 @@ AGENDADOR_SECRET_KEY_BASE=6e58e1f0e806642a44a504672e22665606100838a0c80c8b3b6766
AGENDADOR_API_DB_USER=agendador
AGENDADOR_API_DB_PASSWORD=123mudar
AGENDADOR_REDIS_PASSWORD=123mudar
MAIL_USERNAME: agendador
MAIL_PASSWORD: 123mudar
\ No newline at end of file
This diff is collapsed.
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
......
module Api::V1
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class Accounts::PasswordsController < DeviseTokenAuth::PasswordsController
# this action is responsible for generating password reset tokens and
......@@ -11,20 +26,20 @@ module Api::V1
# fall back to default value if provided
@redirect_url ||= DeviseTokenAuth.default_password_reset_url
unless @redirect_url
return render_create_error_missing_redirect_url
end
@resource = Account.find_by(uid: params[:cpf])
if @resource.citizen.email.nil? or @resource.citizen.email.empty?
@resource = Account.find_by(uid: params[:cpf])
if @resource.nil? or @resource.citizen.email.nil? or @resource.citizen.email.empty?
render json: {
errors: ["User #{params[:cpf]} does not have an email registered."]
}, status: 422
return
end
@resource.email = @resource.citizen.email
@resource.email = @resource.citizen.email
@resource.save
@email = @resource.email
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class Accounts::RegistrationsController < DeviseTokenAuth::RegistrationsController
require "#{Rails.root}/lib/image_parser.rb"
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class Accounts::SessionsController < DeviseTokenAuth::SessionsController
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class AccountsController < ApplicationController
include Authenticable
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class CepController < ApplicationController
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class CitizenUploadsController < ApplicationController
include Authenticable
include HasPolicies
require 'csv'
before_action :set_citizen_upload, only: [:show, :destroy]
# GET /citizen_uploads
def index
# Current citizen id
citizen_id = current_user[0][:id]
# Permission
permission = Professional.get_permission(current_user[1])
@resource_booking = policy_scope(ResourceBooking.filter(
params[:q], params[:page], params[:permission]))
# Find uploads for current citizen
@uploads = policy_scope(CitizenUpload.filter(
params[:q], params[:page], permission))
# Check if uploads are not null for current citizen
if @uploads.nil?
render json: {
errors: ["You don't have the permission to view citizen uploads."]
}, status: 403
return
end
# Sort uploads by date in descending order
@uploads = @uploads.order("created_at DESC")
# Uploads with professional id
uploads_with_professional = @uploads.as_json
# Add professional id to uploads
uploads_with_professional.each do |upload|
upload_citizen = Citizen.find(upload['citizen_id'])
professional = Professional.where(account_id: upload_citizen.account_id).first
upload[:professional_id] = professional.id
end
# Create response object
response = Hash.new
response[:num_entries] = @uploads.total_count
response[:entries] = uploads_with_professional
# Render uploads in JSON format
render json: response.to_json
end
# GET /citizen_uploads/1
def show
if @upload_id.nil?
render json: {
errors: ["Upload task #{params[:upload_id]} does not exist."]
}, status: 404
else
begin
authorize @upload_id, :show?
rescue
render json: {
errors: ["You're not allowed to view this citizen upload log."]
}, status: 403
return
end
# Upload log path
path = @upload_id.log.path
# If log not found, displays not found message
if path.nil?
render json: {
errors: ["Log not found for current task."]
}, status: 404
# Otherwise, send file
else
send_file path,
type: @upload_id.log_content_type,
disposition: 'inline'
end
end
end
# POST /citizen_uploads
def create
# Current citizen id
citizen = current_user[0]
# Current citizen id
citizen_id = citizen[:id]
# Permission
permission = Professional.get_permission(current_user[1])
# City for current permission
city_id = citizen.professional.professionals_service_places.find(
current_user[1]).service_place.city_id
# Data must be defined in the parameters
if params.has_key?(:file) and params[:file].present?
# File content
content = params[:file].read
# Create upload object
upload_object = CitizenUpload.new({
citizen_id: citizen_id,
status: 0, # ready to start
amount: 0,
progress: 0.0
})
begin
authorize upload_object, :create?
rescue
render json: {
errors: ["You're not allowed to perform citizen uploads."]
}, status: 403
return
end
# Save upload object in the database
upload_object.save()
# Create sidekiq job for uploading the citizens
CitizenUploadWorker.perform_async(upload_object.id, content, permission, city_id)
render json: {
errors: ["Citizens scheduled to be imported!"]
}, status: 201
else
render json: {
errors: ["Undefined citizens to import."]
}, status: 404
end
end
# DELETE /citizen_uploads/1
def destroy
end
# GET /citizen_uploads/example_file_xls
def example_xls
filename = "#{Rails.root.to_s}/public/citizen_upload_example.xls"
content_type = "application/xls"
send_file filename, :type => content_type, :x_sendfile => true
end
# GET /citizen_uploads/example_file_ods
def example_ods
filename = "#{Rails.root.to_s}/public/citizen_upload_example.ods"
content_type = "application/vnd.oasis.opendocument.spreadsheet"
send_file filename, :type => content_type, :x_sendfile => true
end
private
# Use callbacks to share common setup or constraints between actions.
def set_citizen_upload
begin
@upload_id = CitizenUpload.find(params[:id])
rescue
@upload_id = nil
end
end
# Only allow a trusted parameter "white list" through.
def citizen_upload_params
params.permit(:file)
end
end
end
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class CitizensController < ApplicationController
include Authenticable
......@@ -164,94 +179,6 @@ module Api::V1
end
end
# GET /citizens/upload_log/1
def get_upload_log
# Find uploads for current citizen
@upload = CitizenUpload.find(params[:upload_id])
if @upload.nil?
render json: {
errors: ["Upload task #{params[:upload_id]} does not exist."]
}, status: 404
else
# Upload log path
path = @upload.log.path
# If log not found, displays not found message
if path.nil?
render json: {
errors: ["Log not found for current task."]
}, status: 404
# Otherwise, send file
else
send_file path,
type: @upload.log_content_type,
disposition: 'inline'
end
end
end
# GET /citizens/upload
def get_uploads
# Current citizen id
citizen_id = current_user[0][:id]
# Permission
permission = Professional.get_permission(current_user[1])
# Find uploads for current citizen
@uploads = CitizenUpload.where(citizen_id: citizen_id)
.order("created_at DESC")
.filter(params[:q], params[:page], permission)
# Create response object
response = Hash.new
response[:num_entries] = @uploads.total_count
response[:entries] = @uploads.as_json
# Render uploads in JSON format
render json: response.to_json
end
# POST /citizens/upload
def upload
# Current citizen id
citizen_id = current_user[0][:id]
# Data must be defined in the parameters
if params.has_key?(:data) and params[:data].present?
# Number of citizens to upload
upload_size = params[:data].size
# Create upload object
upload_object = CitizenUpload.new({
citizen_id: citizen_id,
status: 0, # ready to start
amount: upload_size,
progress: 0.0
})
# Save upload object in the database
upload_object.save()
# Create sidekiq job for uploading the citizens
CitizenUploadWorker.perform_async(
upload_object.id, upload_size, params[:data])
render json: {
errors: ["Citizens scheduled to be imported!"]
}, status: 201
else
render json: {
errors: ["Undefined citizens to import."]
}, status: 404
end
end
# PATCH/PUT /citizens/1
def update
if @citizen.nil?
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class CityHallsController < ApplicationController
include Authenticable
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class DependantsController < ApplicationController
include Authenticable
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class FormsController < ApplicationController
include Authenticable
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class NotificationsController < ApplicationController
include Authenticable
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class OccupationsController < ApplicationController
include Authenticable
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class ProfessionalsController < ApplicationController
include Authenticable
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador. If not, see <https://www.gnu.org/licenses/>.
module Api::V1
class ResourceBookingsController < ApplicationController
include Authenticable
......
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,