Skip to content

Commit

Permalink
add basic auth guide
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed May 27, 2024
1 parent 80648f2 commit ed68359
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
45 changes: 45 additions & 0 deletions docs/3.0/guides/basic-authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Add Avo behind Basic Authentication

Because in Rails we commonly do that using a static function on the controller we need to [safely extend the controller](https://avohq.io/blog/safely-extend-a-ruby-on-rails-controller) to contain that function.

In actuality we will end up with something that behaves like this:

```ruby{2}
class Avo::ApplicationController < ::ActionController::Base
http_basic_authenticate_with name: "adrian", password: "password"
# More methods here
end
```

## Safely add it to Avo

We described the process in depth in [this article](https://avohq.io/blog/safely-extend-a-ruby-on-rails-controller) so let's get down to business.

1. Add the `BasicAuth` concern
1. The concern will prepend the basic auth method
1. `include` that concern to Avo's `ApplicationController`

```ruby{8,20}
# app/controllers/concerns/basic_auth.rb
module BasicAuth
extend ActiveSupport::Concern
# Aiuthentication strategy came from this article
# https://dev.to/kevinluo201/setup-a-basic-authentication-in-rails-with-http-authentication-388e
included do
http_basic_authenticate_with name: "adrian", password: "password"
end
end
# config/initializers/avo.rb
Avo.configure do |config|
# Avo configuration
end
# Add this to include it to Avo's ApplicationController
Rails.configuration.to_prepare do
# Add basic authentication to Avo
Avo::ApplicationController.include BasicAuth
end
```
28 changes: 26 additions & 2 deletions docs/3.0/records-reordering.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,33 @@ end

## Display the buttons in the `Index` view or association view

A typical scenario is to order the records only in the scope of a parent record, like order the `MenuItems` for a `Menu` or `Slides` for a `Slider`. So you wouldn't need to have the order buttons on the `Index` view but only in the association section.
A typical scenario is to have the order buttons on the <Index /> view or a resource. That's the default value for the `visible_on` option.

To control that, you can use the `visible_on` option. The possible values are `:index`, `:association` or `[:index, :association]` for both views.
```ruby{3}
class Avo::Resources::CourseLink < Avo::BaseResource
self.ordering = {
visible_on: :index,
}
end
```

## Display the button on a `has_many` association

Another scenario is to order the records only in the scope of a parent record, like order the `MenuItems` for a `Menu`, or `Slides` for a `Slider`. So you wouldn't need to have the order buttons on the <Index /> view but only in the association section (in a has many association).

To control that, you can use the `visible_on` option and set it to `:association`.

```ruby{3}
class Avo::Resources::CourseLink < Avo::BaseResource
self.ordering = {
visible_on: :association,
}
end
```

### Possible values

The possible values for the `visible_on` option are `:index`, `:association` or `[:index, :association]` for both views.

## Change the scope on the `Index` view

Expand Down

0 comments on commit ed68359

Please sign in to comment.