userswitch 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: bec449f560253bfeb5acbda00ba6fb3ba351cf85
4
- data.tar.gz: 939242e09521784854f835a858ee0ff2fe222527
3
+ metadata.gz: 39e9a40282495b54731301303b01a3c39d42c61b
4
+ data.tar.gz: f1afb090748812c3d48cc8b6c4a0077c3e738387
5
5
  SHA512:
6
- metadata.gz: c5f77f9d9df73af080706911c6afd87dac67adf0a5132787d36cdc3b473c386ba4b119922d05f6a49a0abef84ae13207829ff14a86a455f72694fdb931638360
7
- data.tar.gz: fe50c37355e92f6170edbfe8a646a42fa51f91a84324c19352ca2ff5ca8c79fa1dfa801a4566ccc13fdd6ad748371d354207c3d063a6cfdf4f94742a897daa8a
6
+ metadata.gz: 0567ea51abdc2de2f66d18ccdb63bf44041fc3904009026eaf2b0813463d4942947852d96590aaffb313d1140acbfda7b84f7cafa4bb9ea96c1db3d268fffb4b
7
+ data.tar.gz: 79c8fcb4dd303fc9e763c2c01ceddce8564bc924effc908aa06eef60f1cde73205a9e3e457dd9b17d6b1908cfb6b48e98327de8c5f321f93e96c2f94dfc827e9
data/README.md CHANGED
@@ -1,11 +1,79 @@
1
1
  # Userswitch
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/userswitch.svg)](https://badge.fury.io/rb/userswitch)
4
+
3
5
  Userswitch is a Rails plugin for switching between commonly used roles and users. It's particularly useful for development and staging environments when you often need to switch between various accounts. It saves you from the hassle of logging in or out.
4
6
 
5
- Calling users with (Showing only users with negative id):
7
+ ## Example
8
+
9
+ By default, the gem will output a chain of buttons as follows
10
+
11
+ ![pic1](https://raw.githubusercontent.com/kodius/userswitch/master/us1.png)
12
+
13
+ By clicking on a button, your Rails app will switch to a different user, that is, your session will change to that of a different account and save you the time you might otherwise spend clicking on logout links and filling in forms to log as a different user.
14
+
15
+ ![pic2](https://raw.githubusercontent.com/kodius/userswitch/master/us2.png)
16
+
17
+ Different roles can have different colors so as to be more noticeable.
18
+
19
+ ![pic3](https://raw.githubusercontent.com/kodius/userswitch/master/us3.png)
20
+
21
+ ## How to install
22
+
23
+ Add it to your app's Gemfile and run bundle
24
+ ```ruby
25
+ gem "userswitch"
26
+ ```
27
+ or install it manually
28
+ ```ruby
29
+ gem install userswitch
30
+ ```
31
+
32
+ ## How to use
33
+
34
+ Create file.yml inside you config folder.
35
+
36
+ Your file.yml should look like
37
+
38
+ ```yml
39
+ ## available colors: [red, dark-blue, light-blue, green, yellow, gray, white]
40
+ # name of role: color_name(need to be spelled right)
41
+ # 12 roles max
42
+ Roles:
43
+ admin: red
44
+ user: dark-blue
45
+ dog: green
46
+ cat: yellow
47
+ # 12 SwitchUsers max
48
+ SwitchUsers:
49
+ User1:
50
+ id: -1
51
+ name: Marko
52
+ role: user
53
+ #
54
+ User2:
55
+ id: -2
56
+ name: Kolinda
57
+ role: admin
58
+ #
59
+ User3:
60
+ id: -3
61
+ name: Mirko
62
+ role: dog
63
+ #
64
+ User4:
65
+ id: -4
66
+ name: Dean
67
+ role: cat
68
+
69
+ ```
70
+
71
+ then setup user ids you want to switch to order you wrote in the yours file.yml.
72
+ For example if you want button named Kolinda to be you AdminUser with id = 234 for example,
73
+ change your id to -2 because its ordered second and so on.
74
+
75
+ Inside of your template/view, you can call users with (showing only users from yours file.yml):
6
76
 
7
- ``` Userswitch.users.html_safe ```
77
+ ``` Userswitch.users.html_safe ```
8
78
 
9
- ![pic1](us1.png)
10
- ![pic2](us2.png)
11
- ![pic3](us3.png)
79
+ The above command will generate the required HTML output to make the switching work.
data/example_file.yml ADDED
@@ -0,0 +1,29 @@
1
+ ## available colors: [red, dark-blue, light-blue, green, yellow, gray, white]
2
+ # name of role: color_name(need to be spelled right)
3
+ # 12 roles max
4
+ Roles:
5
+ admin: red
6
+ user: dark-blue
7
+ dog: green
8
+ cat: yellow
9
+ # 12 SwitchUsers max
10
+ SwitchUsers:
11
+ User1:
12
+ id: -1
13
+ name: Marko
14
+ role: user
15
+ #
16
+ User2:
17
+ id: -2
18
+ name: Kolinda
19
+ role: admin
20
+ #
21
+ User3:
22
+ id: -3
23
+ name: Mirko
24
+ role: dog
25
+ #
26
+ User4:
27
+ id: -4
28
+ name: Dean
29
+ role: cat
@@ -1,3 +1,3 @@
1
1
  module Userswitch
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/userswitch.rb CHANGED
@@ -3,24 +3,50 @@ require 'userswitch/engine'
3
3
 
4
4
  module Userswitch
5
5
  def initialize_switch_users
6
- # AdminUser.where('id < 0')
7
- # TODO ovo ce ucitat iz file-a ili seedova sere, Adminusere itd.
8
- # nece bit where
9
- User.where('id < 0')
6
+ YAML.load_file('config/file.yml')
10
7
  end
11
8
 
12
9
  def create_button_from_user
13
10
  ceo_html = ''
14
- initialize_switch_users.each do |user|
15
- # pogleda koja je rola, ovisno o roli dodjelimo clase iz html-a css-a
16
- ceo_html += "<a href=\"/change-user/#{user.id}\" class=\"btn #{user.id} btn-outline btn-info btn-sm\">#{user.email}</a> \n"
11
+ switch_users_yml = initialize_switch_users
12
+ roles = switch_users_yml['Roles']
13
+ users = switch_users_yml['SwitchUsers']
14
+ # TODO provjeru da ih je 12
15
+ users.each do |user|
16
+ id = user.last['id']
17
+ color = btn_color(roles[user.last['role']])
18
+ ceo_html += "<a href=\"/change-user/#{id}\" class=\"btn #{id} #{color} btn-sm\">#{user.last["name"]}</a> \n"
17
19
  end
18
20
  ceo_html.html_safe
19
21
  end
20
22
 
23
+ def btn_color(color)
24
+ case color
25
+ when 'red'
26
+ 'btn-danger'
27
+ when 'dark-blue'
28
+ 'btn-primary'
29
+ when 'light-blue'
30
+ 'btn-info'
31
+ when 'green'
32
+ 'btn-success'
33
+ when 'yellow'
34
+ 'btn-warning'
35
+ when 'gray'
36
+ 'btn-basic'
37
+ when 'white'
38
+ 'btn-default'
39
+ else
40
+ 'btn-primary'
41
+ end
42
+ end
43
+
21
44
  def users
22
45
  create_button_from_user
23
46
  end
24
47
 
25
- module_function :users, :create_button_from_user, :initialize_switch_users
48
+ module_function :users,
49
+ :create_button_from_user,
50
+ :initialize_switch_users,
51
+ :btn_color
26
52
  end
Binary file
data/userswitch.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["matija"]
10
10
  spec.email = ["mmunjako@gmail.com"]
11
11
 
12
- spec.summary = "Switch between various user roles on your Rails app."
12
+ spec.summary = "Userswitch is a Rails plugin for switching between commonly used roles and users. It's particularly useful for development and staging environments when you often need to switch between various accounts. It saves you from the hassle of logging in or out."
13
13
  spec.homepage = "https://github.com/kodius/userswitch"
14
14
  spec.license = "MIT"
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: userswitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - matija
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,12 +71,14 @@ files:
71
71
  - bin/console
72
72
  - bin/setup
73
73
  - config/routes.rb
74
+ - example_file.yml
74
75
  - lib/userswitch.rb
75
76
  - lib/userswitch/engine.rb
76
77
  - lib/userswitch/version.rb
77
78
  - us1.png
78
79
  - us2.png
79
80
  - us3.png
81
+ - userswitch-0.1.2.gem
80
82
  - userswitch.gemspec
81
83
  homepage: https://github.com/kodius/userswitch
82
84
  licenses:
@@ -102,5 +104,8 @@ rubyforge_project:
102
104
  rubygems_version: 2.4.5.2
103
105
  signing_key:
104
106
  specification_version: 4
105
- summary: Switch between various user roles on your Rails app.
107
+ summary: Userswitch is a Rails plugin for switching between commonly used roles and
108
+ users. It's particularly useful for development and staging environments when you
109
+ often need to switch between various accounts. It saves you from the hassle of logging
110
+ in or out.
106
111
  test_files: []