workado 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0aadfc8aaf8a875ff285016ecf78b5e4db9bc0fc8bcea05ec020e77cc2f96bb6
4
+ data.tar.gz: 884f7e754314c81618b3e0faf1ed6f75b87c4cd7a06ece07eee10e2ea9a28405
5
+ SHA512:
6
+ metadata.gz: 337d3a5004cf25ce0200b26cff3c01cd5d907c5a8bba13bc7eabcc6da092f2e908d39b63c80db17bf8723961d080061250ca9ffadb09d51d63b0a493d48019be
7
+ data.tar.gz: f2f0dcfab3e45aecb77061945d89d2b921ca656d0621281975af6923ec0a32e10d84823075a949f2f355641ddac2ca21237268d29490747472ce34808f21c6dc
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Workado
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/workado`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'workado'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install workado
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/workado. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Workado project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/workado/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ module Workado
2
+ class BaseController < ::ApplicationController
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module Workado
2
+ class InvitationsController < BaseController
3
+ def accept
4
+ workspace_user = WorkspaceUser.find_by(acceptable_token: params[:token])
5
+ workspace_user.accept!
6
+ redirect_to(Workado.after_accept_path.call)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Workado
2
+ class InviteMailer < ::ApplicationMailer
3
+ def invite(workspace_user)
4
+ @workspace_user = workspace_user
5
+ @user = workspace_user.user
6
+ @workspace = workspace_user.workspace
7
+ mail(to: @user.email, subject: "You have been invited to #{@workspace.name}")
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,5 @@
1
+ module Workado
2
+ class ApplicationRecord < ::ApplicationRecord
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module Workado
2
+ class Workspace < ApplicationRecord
3
+ self.table_name = "workado_workspaces"
4
+ has_many :workspace_users, dependent: :destroy
5
+ validates :name, presence: true
6
+
7
+ def invite_user(email:, **params, &block)
8
+ user = Workado.user_model.find_by(email: email)
9
+ if user.blank?
10
+ user = Workado.user_model.new(email: email)
11
+ yield(user) if block_given?
12
+ user.save!
13
+ end
14
+ self.workspace_users.create!(user: user, **params)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ module Workado
2
+ class WorkspaceUser < ApplicationRecord
3
+ extend Enumerize
4
+ self.table_name = "workado_workspace_users"
5
+ has_secure_token :acceptable_token
6
+
7
+ belongs_to :workspace
8
+ belongs_to :user, polymorphic: true
9
+
10
+ enumerize :role, in: Workado.roles, default: Workado.default_role, scope: true, predicates: true
11
+
12
+ validates :role, presence: true
13
+
14
+ after_create :send_invitation_mailer, if: ->{ accepted_at.blank? }
15
+
16
+ def self.accept!(token)
17
+ record = find_by(acceptable_token: token)
18
+ record.accept!
19
+ record
20
+ end
21
+
22
+ def accepted?
23
+ accepted_at.present?
24
+ end
25
+
26
+ def accept!
27
+ update!(accepted_at: Time.current)
28
+ end
29
+
30
+ def accept
31
+ update(accepted_at: Time.current)
32
+ end
33
+
34
+ def send_invitation_mailer
35
+ InviteMailer.invite(self).deliver_now
36
+ end
37
+ end
38
+ end
@@ -0,0 +1 @@
1
+ <%= Workado::Engine.routes.url_helpers.accept_invitation_url(@workspace_user.acceptable_token, Workado.default_url_options) %>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Workado::Engine.routes.draw do
2
+ get "invitations/:token", to: "workado/invitations#accept", as: :accept_invitation
3
+ end
@@ -0,0 +1,21 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ require "rails/generators/active_record"
5
+
6
+ module Workado
7
+ module Generators
8
+ class InstallGenerator < Rails::Generators::Base
9
+ include ActiveRecord::Generators::Migration
10
+ source_root File.join(__dir__, "templates")
11
+
12
+ def copy_migration
13
+ migration_template "migration.rb", "db/migrate/install_workado.rb", migration_version: migration_version
14
+ end
15
+
16
+ def migration_version
17
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :workado_workspaces do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+
8
+ create_table :workado_workspace_users do |t|
9
+ t.references :workspace, foreign_key: { to_table: :workado_workspaces }
10
+ t.references :user, polymorphic: true
11
+ t.string :role
12
+ t.datetime :accepted_at
13
+ t.string :acceptable_token
14
+ t.timestamps
15
+ end
16
+ end
17
+ end
data/lib/workado.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "workado/engine"
2
+ require "workado/version"
3
+
4
+ module Workado
5
+ class Error < StandardError; end
6
+
7
+ mattr_accessor :user_class
8
+ @@user_class = nil
9
+
10
+ mattr_accessor :roles
11
+ @@roles = []
12
+
13
+ mattr_accessor :default_role
14
+ @@default_role = nil
15
+
16
+ mattr_accessor :after_accept_path
17
+ @@after_accept_path = ->{ "/" }
18
+
19
+
20
+ def self.setup
21
+ yield self
22
+ end
23
+
24
+ def self.user_model
25
+ @@user_model ||= user_class.constantize
26
+ end
27
+
28
+ def self.default_url_options
29
+ Rails.application.routes.default_url_options.merge(Rails.application.config.action_mailer.default_url_options)
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Workado
2
+ class Engine < ::Rails::Engine
3
+ engine_name "workado"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Workado
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workado
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Uysim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: enumerize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Manage user in workspace
84
+ email:
85
+ - uysimty@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - Rakefile
92
+ - app/controllers/workado/base_controller.rb
93
+ - app/controllers/workado/invitations_controller.rb
94
+ - app/mailers/workado/invite_mailer.rb
95
+ - app/models/workado/application_record.rb
96
+ - app/models/workado/workspace.rb
97
+ - app/models/workado/workspace_user.rb
98
+ - app/views/workado/invite_mailer/invite.html.erb
99
+ - config/routes.rb
100
+ - lib/generators/workado/install_generator.rb
101
+ - lib/generators/workado/templates/migration.rb.tt
102
+ - lib/workado.rb
103
+ - lib/workado/engine.rb
104
+ - lib/workado/version.rb
105
+ homepage: https://github.com/Uysim/workado
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.0.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: workspace managment
128
+ test_files: []