mobile_workflow 0.5.3 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfdd780bae1700eef4c227697f5d75b953bfb70c4a553f2ac9dc3fa6b1a92d28
4
- data.tar.gz: ad16f3eb17f23f6e92fea8c56d50d5deb06c2faa9b1ee62d5774ddb26f38c62f
3
+ metadata.gz: 713ccaaf463cd2815599e145de07b2b2cc5f838242f49e8e97a9eafebb691d10
4
+ data.tar.gz: f95cdbe9e1474adc2813c2c14edc113bd56b13bbb0661de16b2abe27368d1c30
5
5
  SHA512:
6
- metadata.gz: d826dd850a09030b3f54666ffa37abb05fcdf39b0bc45e348d7988aebe03244a7bbddb38eea54a8ee482e4442256548d5fbd85d6c74d95dd365f2215b9930e0a
7
- data.tar.gz: a8e597024e8ffa0eca83ec1958d6d90f02ff2e68722fd498bb8e96dcde216e46420f7f822e229507920f3d65ed291e7023c22dcefb484466309981a8de86d91a
6
+ metadata.gz: 936c2c40cf080691b9c867214d09dea90dd4a16f2370e6f2b7b0d307a965e78863dfb3a761839f8fc46463727e96a7d0e7f37e4767aade6132b202715faa6917
7
+ data.tar.gz: 126597e1a681f59d770b40c8c2c830398932b2d69c8b8d81c5e3a5fbd52e9e3f858d15e857b10ecede4c1caf2600090406cf2d0ea2212122c0fd705e19a6e7dd
@@ -1,5 +1,5 @@
1
1
  module MobileWorkflow
2
- class SnsNotificationsController < ApiController
2
+ class SnsNotificationsController < ActionController::API
3
3
  if Object.const_defined?("Aws::S3") && Object.const_defined?("Aws::SNS")
4
4
  before_action :verify_request_authenticity
5
5
 
@@ -8,7 +8,7 @@ module MobileWorkflow
8
8
 
9
9
  def mw_list_item(id: self.id, text:, detail_text: nil, sf_symbol_name: nil, image_attachment: nil)
10
10
  mw_list_item = {id: id, text: text, detailText: detail_text, sfSymbolName: sf_symbol_name}
11
- mw_list_item[:imageURL] = preview_url(image_attachment, height: 100, width: 100) if image_attachment
11
+ mw_list_item[:imageURL] = preview_url(image_attachment, options: { resize_to_fill: [100, 100] }) if image_attachment
12
12
  mw_list_item.compact
13
13
  end
14
14
 
@@ -16,8 +16,8 @@ module MobileWorkflow
16
16
  {type: :text, label: label, text: text.to_s}.compact
17
17
  end
18
18
 
19
- def mw_display_image(attachment)
20
- {type: :image, previewURL: preview_url(attachment, height: 600, width: 1200), url: attachment_url(attachment)}
19
+ def mw_display_image(attachment, options: { resize_to_fill: [600, 1200] })
20
+ {type: :image, previewURL: preview_url(attachment, options: options), url: attachment_url(attachment)}
21
21
  end
22
22
 
23
23
  def mw_display_unsplash_image(image_url)
@@ -29,8 +29,8 @@ module MobileWorkflow
29
29
  {type: :image, previewURL: image_url, url: image_url}
30
30
  end
31
31
 
32
- def mw_display_video(attachment)
33
- {type: :video, previewURL: preview_url(attachment, height: 600, width: 1200), url: attachment_url(attachment)}
32
+ def mw_display_video(attachment, preview_options: { resize_to_fill: [600, 1200] })
33
+ {type: :video, previewURL: preview_url(attachment, options: preview_options), url: attachment_url(attachment)}
34
34
  end
35
35
 
36
36
  def mw_display_button(label:, style: :primary, on_success: :forward)
@@ -69,12 +69,12 @@ module MobileWorkflow
69
69
  def validate_button_style!(style)
70
70
  raise 'Unknown style' unless BUTTON_STYLES.include?(style)
71
71
  end
72
-
73
- def preview_url(attachment, height:, width:, options: { resize_to_fill: [height, width]} )
72
+
73
+ def preview_url(attachment, options:)
74
74
  return nil unless attachment.attached?
75
75
 
76
76
  if attachment.image?
77
- Rails.application.routes.url_helpers.rails_representation_url(attachment.variant(combine_options: options), host: attachment_host)
77
+ Rails.application.routes.url_helpers.rails_representation_url(attachment.variant(options), host: attachment_host)
78
78
  elsif attachment.previewable?
79
79
  Rails.application.routes.url_helpers.rails_representation_url(attachment.preview(options), host: attachment_host)
80
80
  else
@@ -8,13 +8,18 @@ module MobileWorkflow
8
8
 
9
9
  class_option :attributes, type: :array, default: [], banner: "field:type field:type"
10
10
  class_option :actions, type: :array, default: [], banner: "index create update destroy"
11
+ class_option :doorkeeper_oauth, type: :boolean, default: false
11
12
 
12
13
  def copy_controller_and_spec_files
13
14
  template "controller.rb.erb", File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
14
15
  template "controller_spec.rb.erb", File.join("spec/controllers", controller_class_path, "#{controller_file_name}_controller_spec.rb")
15
16
  end
16
17
 
17
- private
18
+ private
19
+ def doorkeeper_oauth?
20
+ options[:doorkeeper_oauth]
21
+ end
22
+
18
23
  def attributes_names
19
24
  options[:attributes].map{ |attribute| attribute.split(":").first }
20
25
  end
@@ -32,6 +32,11 @@ module MobileWorkflow
32
32
  template("user.rb.erb", "app/models/user.rb")
33
33
  template("sessions_controller.rb.erb", "app/controllers/sessions_controller.rb")
34
34
  route "resources :sessions, only: [:new, :create]"
35
+
36
+ # View related for login screen
37
+ copy_file("views/layout/application.html.erb")
38
+ copy_file("views/sessions/new.html.erb")
39
+ copy_file("helpers/application_helper.rb")
35
40
  end
36
41
 
37
42
  def generate_models
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
- ruby '2.6.6'
4
+ ruby '2.7.2'
5
5
 
6
6
  # Core Gems
7
7
  gem 'rails', '~> 6.1.0'
@@ -11,12 +11,13 @@ gem 'turbolinks', '~> 5'
11
11
 
12
12
  # Mobile Workflow
13
13
  #gem 'mobile_workflow', path: '../mobile_workflow'
14
- gem 'mobile_workflow', github: 'FutureWorkshops/mobile_workflow'
14
+ #gem 'mobile_workflow', github: 'FutureWorkshops/mobile_workflow'
15
+ gem 'mobile_workflow'
15
16
 
16
17
  # Authorisation / Authentication
17
18
  <%- if options[:doorkeeper_oauth] %>
18
19
  gem 'doorkeeper'
19
- gem 'bcrypt-ruby'
20
+ gem 'bcrypt'
20
21
  <%- end %>
21
22
  gem 'cancancan', '~> 3.1'
22
23
 
@@ -8,7 +8,7 @@ class ApiController < ActionController::API
8
8
  before_action :doorkeeper_authorize!, unless: :anonymous_action?
9
9
 
10
10
  def current_resource_owner
11
- User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token&.accessible?
11
+ @current_resource_owner ||= User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token&.accessible?
12
12
  end
13
13
  alias_method :current_user, :current_resource_owner
14
14
 
@@ -0,0 +1,13 @@
1
+ module ApplicationHelper
2
+
3
+ def bootstrap_class_for(flash_type)
4
+ { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }.stringify_keys[flash_type.to_s] || flash_type.to_s
5
+ end
6
+
7
+ def flash_messages
8
+ flash.each do |flash_type, message|
9
+ concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(flash_type)}", role: 'alert'))
10
+ end
11
+ nil
12
+ end
13
+ end
@@ -3,7 +3,7 @@ class SessionsController < ApplicationController
3
3
  end
4
4
 
5
5
  def create
6
- @user = User.find_by(email: params[:email])
6
+ @user = User.find_by("LOWER(email)= ?", params[:email].downcase)
7
7
  if @user && @user.authenticate(params[:password])
8
8
  session[:user_id] = @user.id
9
9
  redirect_to params[:return_to] || root_url, notice: "Logged in!"
@@ -1,4 +1,4 @@
1
1
  class User < ApplicationRecord
2
2
  has_secure_password
3
- validates :email, presence: true
3
+ validates :email, presence: true, uniqueness: true
4
4
  end
@@ -0,0 +1,18 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <!-- Required meta tags -->
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7
+
8
+ <!-- Bootstrap CSS -->
9
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
10
+
11
+ <title>MW Project</title>
12
+ </head>
13
+ <body>
14
+ <div class="container">
15
+ <%= yield %>
16
+ </div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,20 @@
1
+ <h1>Sign In</h1>
2
+
3
+ <%= flash_messages %>
4
+
5
+ <%= form_tag sessions_path, method: :post do %>
6
+ <%= hidden_field_tag :return_to, params[:return_to] %>
7
+
8
+ <div class="form-group">
9
+ <%= label_tag :email %>
10
+ <%= email_field_tag :email, nil, class: "form-control" %>
11
+ </div>
12
+
13
+ <div class="form-group">
14
+ <%= label_tag :password %>
15
+ <%= password_field_tag :password, nil, class: "form-control" %>
16
+ </div>
17
+
18
+ <%= submit_tag 'Sign In', class: "btn btn-primary" %>
19
+ <% end %>
20
+
@@ -6,10 +6,19 @@ require 'json'
6
6
  RSpec.describe <%= controller_class_name %>Controller do
7
7
  let(:params) { {} }
8
8
  let(:json_response) { JSON.parse(response.body, symbolize_names: true) }
9
+ <% if doorkeeper_oauth? -%>
10
+ let(:user) { create(:user) }
11
+ let(:token) { instance_double('Doorkeeper::AccessToken', :accessible? => true, :acceptable? => true, resource_owner_id: user.id) }
12
+ <% end -%>
9
13
 
10
14
  describe 'GET #index' do
11
15
  let!(:<%= controller_class_name.singularize.underscore %>) { create(:<%= controller_class_name.singularize.underscore %>) }
12
- before(:each) { get :index, params: params }
16
+ before(:each) do
17
+ <% if doorkeeper_oauth? -%>
18
+ allow(subject).to receive(:doorkeeper_token) { token }
19
+ <% end -%>
20
+ get :index, params: params
21
+ end
13
22
 
14
23
  context 'ok' do
15
24
  it { expect(json_response[0][:id]).to eq <%= controller_class_name.singularize.underscore %>.id }
@@ -20,7 +29,12 @@ RSpec.describe <%= controller_class_name %>Controller do
20
29
  describe 'GET #show' do
21
30
  let(:<%= controller_class_name.singularize.underscore %>) { create(:<%= controller_class_name.singularize.underscore %>) }
22
31
  let(:params) { { id: <%= controller_class_name.singularize.underscore %>.id } }
23
- before(:each) { get :show, params: params }
32
+ before(:each) do
33
+ <% if doorkeeper_oauth? -%>
34
+ allow(subject).to receive(:doorkeeper_token) { token }
35
+ <% end -%>
36
+ get :show, params: params
37
+ end
24
38
 
25
39
  context 'ok' do
26
40
  it { expect(response.status).to eq 200 }
@@ -30,7 +44,12 @@ RSpec.describe <%= controller_class_name %>Controller do
30
44
  describe 'POST #create' do
31
45
  let(:payload_params) { {text: 'OK'} }
32
46
  let(:params) { { payload: payload_params, binaries: [{identifier: 'record', mimetype: 'video/mp4'}] } }
33
- before(:each) { post :create, params: params }
47
+ before(:each) do
48
+ <% if doorkeeper_oauth? -%>
49
+ allow(subject).to receive(:doorkeeper_token) { token }
50
+ <% end -%>
51
+ post :create, params: params
52
+ end
34
53
 
35
54
  context 'ok' do
36
55
  it { expect(<%= controller_class_name.singularize %>.count).to eq 1 }
@@ -18,9 +18,8 @@ module MobileWorkflow::Cli
18
18
  end
19
19
 
20
20
  def administrate_generator
21
- Bundler.with_clean_env { generate 'administrate:install' }
21
+ Bundler.with_unbundled_env { generate 'administrate:install' }
22
22
 
23
- #rails_command 'generate administrate:install'
24
23
  file 'app/assets/config/manifest.js', <<-CODE
25
24
  //= link administrate/application.css
26
25
  //= link administrate/application.js
@@ -34,7 +33,7 @@ module Admin
34
33
  end
35
34
  CODE
36
35
 
37
- Bundler.with_clean_env { generate 'administrate:routes' }
36
+ Bundler.with_unbundled_env { generate 'administrate:routes' }
38
37
  end
39
38
 
40
39
  def ability_generator
@@ -51,16 +51,18 @@ module MobileWorkflow::Cli
51
51
  protected
52
52
 
53
53
  def get_builder_class
54
- MobileWorkflow::Cli::AppBuilder
54
+ ::MobileWorkflow::Cli::AppBuilder
55
55
  end
56
56
 
57
57
  # Todo: MBS - move these methods to the builder class
58
58
  # Ideally override RailsBuilder methods
59
59
  private
60
60
  def setup_db
61
- rails_command "db:drop"
62
- rails_command "db:create"
63
- rails_command "db:migrate"
61
+ Bundler.with_unbundled_env do
62
+ rails_command("db:drop")
63
+ rails_command("db:create")
64
+ rails_command("db:migrate")
65
+ end
64
66
  end
65
67
 
66
68
  def initial_git_commit
@@ -1,5 +1,5 @@
1
1
  module MobileWorkflow
2
- VERSION = '0.5.3'
2
+ VERSION = '0.5.8'
3
3
  RUBY_VERSION = '2.5.5'
4
4
  RAILS_VERSION = '6.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile_workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brooke-Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2021-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -112,10 +112,13 @@ files:
112
112
  - lib/generators/mobile_workflow/install/templates/README.md.erb
113
113
  - lib/generators/mobile_workflow/install/templates/ability.rb
114
114
  - lib/generators/mobile_workflow/install/templates/api_controller.rb.erb
115
+ - lib/generators/mobile_workflow/install/templates/helpers/application_helper.rb
115
116
  - lib/generators/mobile_workflow/install/templates/seeds.rb.erb
116
117
  - lib/generators/mobile_workflow/install/templates/sessions_controller.rb.erb
117
118
  - lib/generators/mobile_workflow/install/templates/storage.s3.yml
118
119
  - lib/generators/mobile_workflow/install/templates/user.rb.erb
120
+ - lib/generators/mobile_workflow/install/templates/views/layouts/application.html.erb
121
+ - lib/generators/mobile_workflow/install/templates/views/sessions/new.html.erb
119
122
  - lib/generators/mobile_workflow/templates/controller.rb.erb
120
123
  - lib/generators/mobile_workflow/templates/controller_spec.rb.erb
121
124
  - lib/mobile_workflow.rb