jinda 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b84fcc19349e4dc4ecaf04277c5de4b5e83a59c102c8f89de93cde6f563be5d
4
- data.tar.gz: aa08af1a7565d4b873ab2989365c2186298341d412da536919cecfad295187df
3
+ metadata.gz: a1d1eebb536ba8765d34f26028668acb9f824553c869b50a88d1f073763c4ed6
4
+ data.tar.gz: 216f6fd05bd095dd168d13019c9931cbe9d541a2893b13550820c282709037ae
5
5
  SHA512:
6
- metadata.gz: a5a7180d9bde1efc58adfa2d069f0640566c75b7d0d1162885ab57896361af6e1fc35bbaf19eb9ab52406ed9bb0bfb8fb053d718b5dfaba3f5d2a6f4956a884e
7
- data.tar.gz: c9c79c5b4a4e82aaa406b3ad4c42258217fed3dba81a05772063df643b30aaa4e3f4811c6320dd9d143d6b747d5f2d2641e88c13c09668e0071aef49f8c3f685
6
+ metadata.gz: eea8d30604497f1e4f85ff351a4dc4a210700c21a450d9dc59dff0fd327829a62e4b78f78648601cf164364f20d4ba6619a6cc3a5e2d95c637c0c7c54a900be7
7
+ data.tar.gz: 2a4d7a166ed604490eb8a9a1fc0ae0c13027ee3dca3fc3dee350f92a72427f963f0dfc2a33c0357ec734f16ddaee9bbdd21ccc1a5e425c115bf99f75afe7d5db
data/README.md CHANGED
@@ -36,7 +36,7 @@ app without ActiveRecord
36
36
 
37
37
  ## Add jinda to your Gemfile:
38
38
 
39
- gem 'jinda', '~> 0.2.0'
39
+ gem 'jinda', '~> 0.2.1'
40
40
 
41
41
  For Development (most updated)
42
42
 
@@ -11,7 +11,6 @@
11
11
  // GO AFTER THE REQUIRES BELOW.
12
12
  //
13
13
  //= require jquery
14
- //= require jquery.turbolinks
15
14
  //= require jquery_ujs
16
15
  //= require jqm/jquery.mobile.splitview
17
16
  //= require jqm/jquery.mobile-1.2.1
@@ -1,6 +1,6 @@
1
1
  class ArticlesController < ApplicationController
2
2
  before_action :load_article, only: [:show, :destroy]
3
- before_action :load_comments, only: :show
3
+ before_action :load_comments, only: [:show]
4
4
 
5
5
  def index
6
6
  @articles = Article.desc(:created_at).page(params[:page]).per(10)
@@ -15,11 +15,9 @@ class ArticlesController < ApplicationController
15
15
  def edit
16
16
  @article = Article.find(params[:id])
17
17
  @page_title = 'Member Login'
18
-
19
18
  end
20
19
 
21
20
  def create
22
-
23
21
  @article = Article.new(
24
22
  title: $xvars["form_article"]["title"],
25
23
  text: $xvars["form_article"]["text"],
@@ -27,15 +25,19 @@ class ArticlesController < ApplicationController
27
25
  body: $xvars["form_article"]["body"],
28
26
  user_id: $xvars["user_id"])
29
27
  @article.save!
30
- # if @article.save!
31
- # format.html { redirect_to @article, notice: 'Sample was successfully created.' }
32
- # format.json { render :show, status: :created, location: @article }
33
- # else
34
- # format.html { render :new }
35
- # format.json { render json: @article.errors, status: :unprocessable_entity }
36
- # end
37
- redirect_to @article
38
28
 
29
+ # comment out to use jinda_controller end_action
30
+ # redirect_to @article
31
+ # if @article.save!
32
+ # # format.html { redirect_to @article, notice: 'Sample was successfully created.' }
33
+ # format.html { redirect_to @article }
34
+ # format.json { render :show, status: :created, location: @article }
35
+ # end
36
+ # else
37
+ # format.html { render :new }
38
+ # format.json { render json: @article.errors, status: :unprocessable_entity }
39
+ # end
40
+
39
41
  end
40
42
 
41
43
  def my
@@ -47,19 +49,23 @@ class ArticlesController < ApplicationController
47
49
  # $xvars["select_article"] and $xvars["edit_article"]
48
50
  # These are variables.
49
51
  # They contain everything that we get their forms select_article and edit_article
50
- article_id = $xvars["select_article"] ? $xvars["select_article"]["title"] : $xvars["p"]["article_id"]
52
+
53
+ article_id = $xvars["select_article"] ? $xvars["select_article"]["title"] : $xvars["p"]["article_id"]
51
54
  @article = Article.find(article_id)
52
-
53
- @article.update(title: $xvars["edit_article"]["article"]["title"],
54
- text: $xvars["edit_article"]["article"]["text"],
55
- keywords: $xvars["edit_article"]["article"]["keywords"],
56
- body: $xvars["edit_article"]["article"]["body"])
57
- redirect_to @article
58
-
59
-
55
+ @article.update(title: $xvars["edit_article"]["title"],
56
+ text: $xvars["edit_article"]["text"],
57
+ keywords: $xvars["edit_article"]["keywords"],
58
+ body: $xvars["edit_article"]["body"]
59
+ )
60
+ # redirect_to @article
61
+ # comment out to use jinda_controller end_action
60
62
  end
61
63
 
62
64
  def destroy
65
+ # duplicated from jinda_controller
66
+ # Expected to use in jinda)controller
67
+ #
68
+ current_ma_user = Jinda::User.where(:auth_token => cookies[:auth_token]).first if cookies[:auth_token]
63
69
  if Rails.env.test? #Temp solution until fix test of current_ma_user
64
70
  current_ma_user = $xvars["current_ma_user"]
65
71
  #current_ma_user = @article.user
@@ -67,13 +73,14 @@ class ArticlesController < ApplicationController
67
73
  if current_ma_user.role.upcase.split(',').include?("A") || current_ma_user == @article.user
68
74
  @article.destroy
69
75
  end
70
- redirect_to :action=>'index'
76
+ #redirect_to :action=>'index'
77
+ redirect_to :action=>'my'
71
78
  end
72
79
 
73
80
  private
74
81
 
75
82
  def load_article
76
- @article = Article.find(params[:id])
83
+ @article = Article.find(params.require(:article_id))
77
84
  end
78
85
 
79
86
  def load_comments
@@ -247,19 +247,25 @@ class JindaController < ApplicationController
247
247
  def end_form
248
248
  init_vars(params[:xmain_id])
249
249
  eval "@xvars[@runseq.code] = {} unless @xvars[@runseq.code]"
250
+ # Search for uploaded file name if exist
250
251
  params.each { |k,v|
251
252
  if params[k].respond_to? :original_filename
252
253
  get_image(k, params[k])
253
- elsif params[k]['filename'].respond_to? :original_filename
254
- eval "@xvars[@runseq.code][k] = v"
254
+ # check if params of array in form eg: edit_article
255
+ elsif params[k].is_a?(ActionController::Parameters)
255
256
  params[k].each { |k1,v1|
256
- next unless v1.respond_to?(:original_filename)
257
+ # eval "@xvars[@runseq.code][k1] = params.require(k1).permit(k1)"
258
+ eval "@xvars[@runseq.code][k1] = v1"
259
+ next unless v1.respond_to?(:original_filename)
257
260
  get_image1(k, k1, params[k][k1])
258
261
  }
259
-
260
262
  else
261
263
  # bug in to_unsalfe_h rails 5.1.6 https://github.com/getsentry/raven-ruby/issues/799
262
- # v = v.to_unsafe_h unless v.class == String
264
+ # Solution:
265
+ # https://stackoverflow.com/questions/34949505/rails-5-unable-to-retrieve-hash-values-from-parameter
266
+ # v = v.to_unsafe_h unless v.class == String
267
+ # v = params.require[k] unless v.class == String
268
+ v = v.to_s unless v.class == String
263
269
  eval "@xvars[@runseq.code][k] = v"
264
270
  end
265
271
  }
@@ -9,7 +9,7 @@ class SessionsController < ApplicationController
9
9
  # see app/views/sessions/new.html.erb for sample
10
10
  def create
11
11
  auth = request.env["omniauth.auth"]
12
- user = User.from_omniauth(auth)
12
+ user = Jinda::User.from_omniauth(auth)
13
13
  session[:user_id] = user.id
14
14
  if params.permit[:remember_me]
15
15
  cookies.permanent[:auth_token] = user.auth_token
@@ -153,7 +153,7 @@
153
153
  <node CREATED="1493418879485" ID="ID_1995497233" MODIFIED="1493718770637" TEXT="article">
154
154
  <node CREATED="1493418891110" ID="ID_364756011" MODIFIED="1493418905253" TEXT="title"/>
155
155
  <node CREATED="1493418906868" ID="ID_1676483995" MODIFIED="1493418911919" TEXT="text"/>
156
- <node CREATED="1493487131376" ID="ID_1334057464" MODIFIED="1493487186856" TEXT="belongs_to :user">
156
+ <node CREATED="1493487131376" ID="ID_1334057464" MODIFIED="1538239863609" TEXT="belongs_to :user, class_name =&gt; &quot;Jinda::User&quot;">
157
157
  <icon BUILTIN="edit"/>
158
158
  </node>
159
159
  <node CREATED="1493705838166" ID="ID_408271104" MODIFIED="1493705877062" TEXT="has_many :comments">
@@ -5,7 +5,7 @@ class Article
5
5
  include Mongoid::Timestamps
6
6
  field :title, :type => String
7
7
  field :text, :type => String
8
- belongs_to :user
8
+ belongs_to :user, :class_name => "Jinda::User"
9
9
  has_many :comments
10
10
  validates :title, :text, :user_id, presence: true
11
11
  field :body, :type => String
@@ -10,7 +10,7 @@ class Jinda::Xmain
10
10
  field :name, :type => String
11
11
  field :ip, :type => String
12
12
  field :status, :type => String
13
- belongs_to :user
13
+ belongs_to :user, :class_name => "Jinda::User"
14
14
  field :xvars, :type => Hash
15
15
  field :current_runseq, :type => String
16
16
  # Jinda end
@@ -233,7 +233,8 @@ module Jinda
233
233
  # return nil
234
234
  # end
235
235
  #@user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
236
- @user ||= User.where(:auth_token => cookies[:auth_token]).first if cookies[:auth_token]
236
+ @user ||= Jinda::User.where(:auth_token => cookies[:auth_token]).first if cookies[:auth_token]
237
+ return @user
237
238
  end
238
239
 
239
240
  def ui_action?(s)
@@ -1,3 +1,3 @@
1
1
  module Jinda
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -19,7 +19,7 @@ namespace :jinda do
19
19
  unless Identity.where(code:"admin").exists?
20
20
  identity= Identity.create :code => "admin", :email => "admin@test.com", :password => "secret",
21
21
  :password_confirmation => "secret", :image => "https://user-images.githubusercontent.com/3953832/42472827-50ed8cbc-8388-11e8-8982-fa523c25288f.png"
22
- User.create :provider => "identity", :uid => identity.id.to_s, :code => identity.code,
22
+ Jinda::User.create :provider => "identity", :uid => identity.id.to_s, :code => identity.code,
23
23
  :email => identity.email, :role => "M,A,D", :auth_token => "71JxMH5fxi23zinBoq1uKA", :image => identity.image
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jinda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prateep Kul
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-09-02 00:00:00.000000000 Z
12
+ date: 2018-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -341,7 +341,6 @@ files:
341
341
  - lib/generators/jinda/templates/app/models/jinda/xmain.rb
342
342
  - lib/generators/jinda/templates/app/models/param.rb
343
343
  - lib/generators/jinda/templates/app/models/person.rb
344
- - lib/generators/jinda/templates/app/models/user.rb
345
344
  - lib/generators/jinda/templates/app/views/adminbsbs/content.haml
346
345
  - lib/generators/jinda/templates/app/views/admins/edit_role/edit_role.html.erb
347
346
  - lib/generators/jinda/templates/app/views/admins/edit_role/select_user.html.erb
@@ -1,63 +0,0 @@
1
- class User
2
- include Mongoid::Document
3
- before_create {generate_token(:auth_token)}
4
- field :provider, :type => String
5
- field :uid, :type => String
6
- field :code, :type => String
7
- field :email, :type => String
8
- field :role, :type => String
9
- field :user, :type => String
10
- field :auth_token, :type => String
11
- field :password_reset_token, :type => String
12
- field :password_reset_sent_at,:type => DateTime
13
- field :image, :type => String
14
-
15
-
16
- belongs_to :identity, :polymorphic => true, :optional => true
17
- has_many :xmains, :class_name => "Jinda::Xmain"
18
-
19
- ## Add to create forgot password
20
- def generate_token(column)
21
- begin
22
- self[column] = SecureRandom.urlsafe_base64
23
- end
24
- #end while User.exists?(column => self[column])
25
- end
26
-
27
- def has_role(role1)
28
- return role.upcase.split(',').include?(role1.upcase)
29
- end
30
-
31
- def self.from_omniauth(auth)
32
- # Rails now no longer support slice
33
- # where(auth.slice(:uid, :provider, :email)).first_or_create do |user|
34
- where(uid: auth.uid, provider: auth.provider, email: auth.info.email).first_or_create do |user|
35
- case auth.provider
36
- when 'identity'
37
- identity = Identity.find auth.uid
38
- user.code = identity.code
39
- user.email = identity.email
40
- else
41
- user.email = auth.info.email
42
- user.uid = auth.uid
43
- user.provider = auth.provider
44
- user.code = auth.info.name
45
- user.role = "M"
46
- user.image = auth.info.image
47
- end
48
- end
49
- end
50
-
51
- def ma_secured?
52
- role.upcase.split(',').include?(ma_secured_ROLE)
53
- end
54
-
55
- def send_password_reset
56
- generate_token(:password_reset_token)
57
- self.password_reset_sent_at = Time.zone.now
58
- save!
59
- UserMailer.password_reset(self).deliver
60
- end
61
-
62
-
63
- end