Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ orbs:

defaults: &defaults
docker:
- image: cimg/ruby:2.7.3
- image: cimg/ruby:3.1.7
working_directory: ~/api.goodcity

jobs:
Expand All @@ -40,7 +40,7 @@ jobs:
<<: *defaults
steps:
- run: mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
- run: gem install bundler:2.2.27
- run: gem install bundler:2.3.27
- restore_cache:
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache: *restore-bundler-cache
Expand All @@ -50,7 +50,7 @@ jobs:
test:
<<: *defaults
docker:
- image: cimg/ruby:2.7.3-browsers
- image: cimg/ruby:3.1.7-browsers
- image: cimg/redis:6.0
- image: cimg/postgres:9.6
environment:
Expand All @@ -66,16 +66,14 @@ jobs:
- run:
name: Install PostgreSQL Client (required to run migrations)
command: |
sudo sh -c 'echo "deb https://apt-archive.postgresql.org/pub/repos/apt `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo apt-get install postgresql-client-9.6
sudo apt-get install -y postgresql-client
- attach_workspace:
at: ~/api.goodcity/tmp
- restore_cache:
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache: *restore-bundler-cache
- run: gem install bundler:2.2.27 && bundle config set --local deployment 'true' && (bundle check || bundle install --jobs=2 --retry=3)
- run: gem install bundler:2.3.27 && bundle config set --local deployment 'true' && (bundle check || bundle install --jobs=2 --retry=3)
- run:
name: Wait for DB and Redis containers to start
command: dockerize -wait tcp://localhost:5432 -wait tcp://localhost:6379 -timeout 1m
Expand Down Expand Up @@ -108,7 +106,7 @@ jobs:
- restore_cache:
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache: *restore-bundler-cache
- run: gem install bundler:2.2.27 && bundle config set --local deployment 'true' && (bundle check || bundle install --jobs=2 --retry=3)
- run: gem install bundler:2.3.27 && bundle config set --local deployment 'true' && (bundle check || bundle install --jobs=2 --retry=3)
- run: |
STAGE=$(if [ "$CIRCLE_BRANCH" == "live" ]; then echo production; else echo staging; fi)
bundle exec cap ${STAGE} deploy
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.7.3
ruby-3.1.7
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:2.7.3-alpine
FROM ruby:3.1.7-alpine

ARG GITHUB_TOKEN

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'
ruby '2.7.3'
ruby '3.1.7'

gem 'pg'
gem 'rails', '~> 6.1.4'
Expand Down Expand Up @@ -47,7 +47,7 @@ gem 'rotp'
gem 'rubyXL'
gem 'sidekiq', '<8'
gem 'sidekiq-scheduler'
gem 'state_machine'
gem 'state_machines-activerecord', '~> 0.9.0'
gem 'traco'
gem 'twilio-ruby'
gem 'whenever', require: false
Expand Down
14 changes: 10 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,13 @@ GEM
net-sftp (>= 2.1.2)
net-ssh (>= 2.8.0)
ostruct
state_machine (1.2.0)
state_machines (0.20.0)
state_machines-activemodel (0.9.0)
activemodel (>= 6.0)
state_machines (>= 0.6.0)
state_machines-activerecord (0.9.0)
activerecord (>= 6.0)
state_machines-activemodel (>= 0.9.0)
sys-uname (1.3.1)
ffi (~> 1.1)
thor (1.3.2)
Expand Down Expand Up @@ -645,7 +651,7 @@ DEPENDENCIES
simplecov
spring
spring-commands-rspec
state_machine
state_machines-activerecord (~> 0.9.0)
timecop
traco
twilio-ruby
Expand All @@ -654,7 +660,7 @@ DEPENDENCIES
with_advisory_lock

RUBY VERSION
ruby 2.7.3p183
ruby 3.1.7p261

BUNDLED WITH
2.4.19
2.3.27
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#api: bundle exec puma -C config/puma.rb
api: bundle exec rails server --binding=0.0.0.0
api: bundle exec rails server --binding=0.0.0.0 --port ${PORT:-3000}
sidekiq: bundle exec sidekiq
socketio: (cd ../socket.io-webservice/ && PORT=1337 npm start)
3 changes: 2 additions & 1 deletion app/controllers/api/v2/shareables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def destroy
* 401 - unauthorized
EOS
def index
records = paginate(@shareables)
# Ensure stable pagination order
records = paginate(@shareables.order(id: :asc))
records = records.of_type(params[:resource_type]) if params[:resource_type].present?
records = records.where(resource_id: params[:resource_id].split(',')) if params[:resource_id].present?

Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/operations/stock_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def register_quantity_change(package, quantity:, location:, action:, description
}

if PackagesInventory::QUANTITY_LOSS_ACTIONS.include?(action)
register_loss(package, params)
register_loss(package, **params)
elsif PackagesInventory::QUANTITY_GAIN_ACTIONS.include?(action)
register_gain(package, params)
register_gain(package, **params)
else
raise Goodcity::ActionNotAllowedError.new
end
Expand Down
12 changes: 7 additions & 5 deletions app/models/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def initialize(options = {})
# as part of the authentication/authorization process
# Additional options can be encoded inside the token
# params = { "mobile" => "+85212345678" }
def generate(params, metadata: {}, validity: nil, type: DEFAULT_TYPE)
def generate(params = {}, metadata: {}, validity: nil, type: DEFAULT_TYPE, **extra_params)
now = Time.current.to_i
validity ||= default_validity(type)

params = (params || {}).merge(extra_params)

payload = params.merge({
"iat": now,
"iss": issuer,
Expand All @@ -52,12 +54,12 @@ def generate(params, metadata: {}, validity: nil, type: DEFAULT_TYPE)
JWT.encode(payload.stringify_keys, secret_key, hmac_sha_algo)
end

def generate_api_token(params, metadata: {}, validity: nil)
generate(params, metadata: metadata, validity: validity, type: Types::API)
def generate_api_token(params = {}, metadata: {}, validity: nil, **extra_params)
generate(params, metadata: metadata, validity: validity, type: Types::API, **extra_params)
end

def generate_otp_token(params, metadata: {}, validity: nil)
generate(params, metadata: metadata, validity: validity, type: Types::OTP)
def generate_otp_token(params = {}, metadata: {}, validity: nil, **extra_params)
generate(params, metadata: metadata, validity: validity, type: Types::OTP, **extra_params)
end

# Allow access to the data stored inside the token e.g. mobile number
Expand Down
12 changes: 8 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class User < ApplicationRecord
scope :exclude_system_users, -> { where.not(id: [User.system_user.try(:id), User.stockit_user.try(:id)].compact) }
scope :active, -> { where(disabled: false) }
scope :exclude_user, ->(id) { where.not(id: id) }
scope :with_roles, ->(role_names) { where(roles: { name: role_names }).joins(:active_roles) }
scope :with_roles, ->(role_names) { joins(:active_roles).where(active_roles: { name: role_names }) }
scope :with_organisation_status, ->(status_list) { joins(:organisations_users).where(organisations_users: { status: status_list }) }
scope :with_eager_loading, -> { includes([:image, address: [:district]]) }
scope :with_permissions, ->(perm) {
Expand Down Expand Up @@ -171,9 +171,13 @@ def self.recent_orders_created_for(user_id)
end

def self.filter_users(opts)
res = search(opts['searchText']) if opts['searchText'].present?
res = res.with_organisation_status(opts['organisation_status'].split(',')) if opts['organisation_status'].present?
res = res.with_roles(opts['role_name']) if opts['role_name'].present?
search_text = opts[:searchText] || opts['searchText']
organisation_status = opts[:organisation_status] || opts['organisation_status']
role_name = opts[:role_name] || opts['role_name']

res = search_text.present? ? search(search_text) : all
res = res.with_organisation_status(organisation_status.split(',')) if organisation_status.present?
res = res.with_roles(role_name) if role_name.present?
res
end

Expand Down
6 changes: 3 additions & 3 deletions app/services/twilio_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def send_unread_message_reminder(url)

# options[:to] = "+85261111111"
# options[:body] = "SMS body"
def send_sms(options)
options = { to: mobile }.merge(options)
TwilioJob.perform_later(options)
def send_sms(options = nil, **kwargs)
options = { to: mobile }.merge(options || {}).merge(kwargs)
TwilioJob.perform_later(**options)
end

private
Expand Down
2 changes: 1 addition & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
set :linked_files, %w{ config/database.yml .env }
set :linked_dirs, %w{log tmp/pids tmp/cache}
set :bundle_binstubs, nil
set :rvm_ruby_version, '2.7.3'
set :rvm_ruby_version, '3.1.7'
set :newrelic_user, Proc.new { ENV['CIRCLE_USERNAME'] || ENV['USER'] }

after "deploy:updated", "newrelic:notice_deployment"
Expand Down
18 changes: 0 additions & 18 deletions config/initializers/state_machine_patch.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/systemd/sidekiq-production.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ After=syslog.target network.target
Type=simple
WorkingDirectory=/opt/rails/goodcity_server/current
Environment=NODE_VERSION=lts/gallium MALLOC_ARENA_MAX=2
ExecStart=/home/deployer/.nvm/nvm-exec /home/deployer/.rvm/bin/rvm 2.7.3 do bundle exec sidekiq -e production -C config/sidekiq.yml
ExecStart=/home/deployer/.nvm/nvm-exec /home/deployer/.rvm/bin/rvm 3.1.7 do bundle exec sidekiq -e production -C config/sidekiq.yml
User=deployer
Group=deployer
UMask=0002
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AddIndexToMessagesOnMessageableAndCreatedAt < ActiveRecord::Migration[6.1]
disable_ddl_transaction!

def change
unless index_exists?(:messages, name: 'index_messages_on_messageable_and_created_at')
unless index_exists?(:messages, nil, name: 'index_messages_on_messageable_and_created_at')
add_index :messages,
[:messageable_type, :messageable_id, :created_at],
name: 'index_messages_on_messageable_and_created_at',
Expand Down
Loading