-
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.
Users and permissions for Api Auth
- Loading branch information
Showing
5 changed files
with
68 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ApiPermission < ApplicationRecord | ||
belongs_to :api_user | ||
|
||
validates :endpoint_name, presence: true | ||
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,7 @@ | ||
class ApiUser < ApplicationRecord | ||
has_secure_password | ||
|
||
has_many :api_permissions, dependent: :destroy | ||
|
||
validates :username, presence: true, uniqueness: true | ||
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,19 @@ | ||
class CreateApiUsers < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :api_users do |t| | ||
t.string :username, null: false, unique: true | ||
t.string :password_digest, null: false | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :api_users, :username, unique: true | ||
|
||
ApiUser.find_or_create_by(id: 1) do |api_user| | ||
api_user.username = 'madeline' | ||
api_user.password = 'k2j3j10pp' | ||
api_user.password_confirmation = 'k2j3j10pp' | ||
end | ||
|
||
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,18 @@ | ||
class CreateApiPermissions < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :api_permissions do |t| | ||
t.references :api_user, null: false, foreign_key: true | ||
t.string :endpoint_name, null: false | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :api_permissions, [:api_user_id, :endpoint_name], unique: true | ||
|
||
ApiPermission.find_or_create_by(id: 1) do |permission| | ||
permission.api_user_id = 1 | ||
permission.endpoint_name = 'addresses' | ||
end | ||
|
||
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