forked from fs/task_tracker_itis_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
901555f
commit 71a3f05
Showing
13 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class ApplicationController < ActionController::Base | ||
include Authentication | ||
include Authorization | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Authorization | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
verify_authorized | ||
|
||
rescue_from ActionPolicy::Unauthorized, with: :deny_access! | ||
end | ||
|
||
private | ||
|
||
def deny_access!(error) | ||
redirect_to root_path, alert: error.message | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
class Project < ApplicationRecord | ||
has_many :tasks, dependent: :destroy | ||
has_many :project_memberships, dependent: :destroy | ||
has_many :users, through: :project_memberships | ||
|
||
validates :name, :description, presence: true | ||
validates :name, uniqueness: true | ||
has_many :tasks, dependent: :destroy | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class ProjectMembership < ApplicationRecord | ||
extend Enumerize | ||
|
||
ROLES = %i[owner member].freeze | ||
|
||
belongs_to :user | ||
belongs_to :project | ||
|
||
enumerize :role, in: ROLES, predicates: true, scope: :shallow, default: :member | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
class User < ApplicationRecord | ||
extend Enumerize | ||
|
||
has_secure_password | ||
ROLES = %i[member admin super_admin].freeze | ||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i.freeze | ||
|
||
has_many :project_memberships, dependent: :restrict_with_error | ||
has_many :projects, through: :project_memberships | ||
|
||
validates :password, length: { minimum: 6 } | ||
validates :email, presence: true, uniqueness: true, format: { with: VALID_EMAIL_REGEX } | ||
validates :first_name, :last_name, presence: true | ||
|
||
enumerize :role, in: ROLES, predicates: true, scope: :shallow, default: :member | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ApplicationPolicy < ActionPolicy::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class ProjectPolicy < ApplicationPolicy | ||
authorize :user, allow_nil: true | ||
|
||
def index? | ||
true | ||
end | ||
|
||
def new? | ||
true | ||
end | ||
|
||
def create? | ||
user.present? | ||
end | ||
|
||
def destroy? | ||
true | ||
end | ||
|
||
def edit? | ||
new? | ||
end | ||
|
||
def show? | ||
true | ||
end | ||
|
||
def update? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddRolesToUsers < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :users, :role, :string, default: "member", null: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateProjectMemberships < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :project_memberships do |t| | ||
t.references :project, null: false, foreign_key: true | ||
t.belongs_to :user, null: false, foreign_key: true | ||
t.string :role, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.