-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial admin/avo setup * Initial admin resources
- Loading branch information
Showing
25 changed files
with
370 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ group :test do | |
gem "capybara" | ||
gem "selenium-webdriver" | ||
end | ||
gem "avo", ">= 3.2" |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Avo::Resources::Article < Avo::BaseResource | ||
self.find_record_method = -> { | ||
# When using friendly_id, we need to check if the id is a slug or an id. | ||
# If it's a slug, we need to use the find_by_slug method. | ||
# If it's an id, we need to use the find method. | ||
# If the id is an array, we need to use the where method in order to return a collection. | ||
if id.is_a?(Array) | ||
id.first.to_i == 0 ? query.where(slug: id) : query.where(id: id) | ||
else | ||
id.to_i == 0 ? query.find_by_slug(id) : query.find(id) | ||
end | ||
} | ||
|
||
self.includes = [] | ||
# self.search = { | ||
# query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) } | ||
# } | ||
|
||
def fields | ||
field :id, as: :id | ||
field :title, as: :text | ||
field :slug, as: :text | ||
field :content, as: :trix | ||
field :publish_at, as: :date_time | ||
field :author_name, as: :text | ||
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,32 @@ | ||
class Avo::Resources::Term < Avo::BaseResource | ||
self.find_record_method = -> { | ||
# When using friendly_id, we need to check if the id is a slug or an id. | ||
# If it's a slug, we need to use the find_by_slug method. | ||
# If it's an id, we need to use the find method. | ||
# If the id is an array, we need to use the where method in order to return a collection. | ||
if id.is_a?(Array) | ||
id.first.to_i == 0 ? query.where(slug: id) : query.where(id: id) | ||
else | ||
id.to_i == 0 ? query.find_by_slug(id) : query.find(id) | ||
end | ||
} | ||
|
||
self.includes = [] | ||
# self.search = { | ||
# query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) } | ||
# } | ||
|
||
def fields | ||
field :id, as: :id | ||
field :name, as: :text | ||
field :title, as: :text | ||
field :content, as: :trix | ||
field :slug, as: :text | ||
field :video_id, as: :text | ||
field :video_title, as: :text | ||
field :video_description, as: :textarea | ||
field :video_thumbnail_url, as: :text | ||
field :video_upload_date, as: :date | ||
field :video_duration, as: :text | ||
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 Avo::Resources::User < Avo::BaseResource | ||
self.includes = [] | ||
# self.search = { | ||
# query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) } | ||
# } | ||
|
||
def fields | ||
field :id, as: :id | ||
field :username, as: :text | ||
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 |
---|---|---|
@@ -1,4 +1,30 @@ | ||
class ApplicationController < ActionController::Base | ||
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. | ||
# allow_browser versions: :modern | ||
|
||
helper_method :current_user | ||
helper_method :user_signed_in? | ||
|
||
private | ||
|
||
def authenticate | ||
@current_user = nil | ||
authenticate_with_http_digest(ENV["AUTH_SECRET"]) do |username| | ||
@current_user = User.find_by(username: username) | ||
@current_user&.password_digest || false | ||
end | ||
!@current_user.nil? | ||
end | ||
|
||
def authenticate! | ||
authenticate || request_http_digest_authentication(ENV["AUTH_SECRET"]) | ||
end | ||
|
||
def current_user | ||
Current.user ||= @current_user | ||
end | ||
|
||
def user_signed_in? | ||
Current.user.present? | ||
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,4 @@ | ||
# This controller has been generated to enable Rails' resource routes. | ||
# More information on https://docs.avohq.io/3.0/controllers.html | ||
class Avo::ArticlesController < Avo::ResourcesController | ||
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,4 @@ | ||
# This controller has been generated to enable Rails' resource routes. | ||
# More information on https://docs.avohq.io/3.0/controllers.html | ||
class Avo::TermsController < Avo::ResourcesController | ||
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,4 @@ | ||
# This controller has been generated to enable Rails' resource routes. | ||
# More information on https://docs.avohq.io/3.0/controllers.html | ||
class Avo::UsersController < Avo::ResourcesController | ||
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Current < ActiveSupport::CurrentAttributes | ||
attribute :user | ||
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 User < ApplicationRecord | ||
end |
Empty file.
Oops, something went wrong.