b4um_generators 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/README.de.md +338 -4
- data/README.md +330 -5
- data/lib/b4um_generators/version.rb +1 -1
- data/lib/generators/b4um/admin/admin_generator.rb +614 -0
- data/lib/generators/b4um/admin/templates/add_admin_fields_migration.rb.tt +10 -0
- data/lib/generators/b4um/admin/templates/admin_base_controller.rb.tt +5 -0
- data/lib/generators/b4um/admin/templates/admin_dashboard.html.erb.tt +19 -0
- data/lib/generators/b4um/admin/templates/admin_dashboard_controller.rb.tt +6 -0
- data/lib/generators/b4um/admin/templates/admin_users_controller.rb.tt +70 -0
- data/lib/generators/b4um/admin/templates/admin_users_index.html.erb.tt +110 -0
- data/lib/generators/b4um/admin/templates/b4um_admin.rake.tt +106 -0
- data/lib/generators/b4um/authentication/authentication_generator.rb +90 -1
- data/lib/generators/b4um/guest/guest_generator.rb +673 -0
- data/lib/generators/b4um/guest/templates/add_guest_fields_migration.rb.tt +12 -0
- data/lib/generators/b4um/guest/templates/b4um_guests.rake.tt +12 -0
- data/lib/generators/b4um/guest/templates/edit.html.erb.tt +156 -0
- data/lib/generators/b4um/guest/templates/guest_expiration_warning.html.erb.tt +12 -0
- data/lib/generators/b4um/guest/templates/guests_controller.rb.tt +88 -0
- data/lib/generators/b4um/guest/templates/new.html.erb.tt +136 -0
- data/lib/generators/b4um/help/help_generator.rb +162 -0
- data/lib/generators/b4um/scaffold/scaffold_generator.rb +50 -0
- data/lib/generators/b4um/scaffold/templates/_form.html.erb.tt +18 -14
- metadata +16 -1
data/README.md
CHANGED
|
@@ -6,8 +6,8 @@ b4um Generators is a collection of reusable Rails generators, templates, compone
|
|
|
6
6
|
Rails projects.
|
|
7
7
|
|
|
8
8
|
The gem provides a consistent starting point for Rails applications and includes generators for scaffolds, controllers,
|
|
9
|
-
Bento layouts, tables, pagination, infinite scrolling, search, comments, authentication,
|
|
10
|
-
editing.
|
|
9
|
+
Bento layouts, tables, pagination, infinite scrolling, search, sorting, comments, authentication, administrator
|
|
10
|
+
management, guest access, attachments and rich-text editing.
|
|
11
11
|
|
|
12
12
|
Generated components share the same b4um styling and are designed to work together.
|
|
13
13
|
|
|
@@ -23,7 +23,7 @@ b4um Generators is currently used as a local gem during development.
|
|
|
23
23
|
Add the gem to the Rails application's `Gemfile`:
|
|
24
24
|
|
|
25
25
|
```ruby
|
|
26
|
-
gem "b4um_generators", "~> 0.
|
|
26
|
+
gem "b4um_generators", "~> 0.4.0", path: "/path/to/b4um_generators"
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Then run:
|
|
@@ -79,9 +79,12 @@ b4um:controller
|
|
|
79
79
|
b4um:pagination
|
|
80
80
|
b4um:infinite_scroll
|
|
81
81
|
b4um:search
|
|
82
|
+
b4um:sortable
|
|
82
83
|
b4um:comments
|
|
83
84
|
b4um:in_place
|
|
84
85
|
b4um:authentication
|
|
86
|
+
b4um:admin
|
|
87
|
+
b4um:guest
|
|
85
88
|
b4um:trix
|
|
86
89
|
b4um:readable
|
|
87
90
|
b4um:help
|
|
@@ -95,7 +98,7 @@ bin/rails generate b4um:help
|
|
|
95
98
|
|
|
96
99
|
## Scaffold Generator
|
|
97
100
|
|
|
98
|
-
Generate a Rails resource
|
|
101
|
+
Generate a Rails resource with b4um views and components:
|
|
99
102
|
|
|
100
103
|
```bash
|
|
101
104
|
bin/rails generate b4um:scaffold MODEL ATTRIBUTES
|
|
@@ -113,6 +116,7 @@ The scaffold generator provides:
|
|
|
113
116
|
- Index, show, new and edit views
|
|
114
117
|
- Bento index layout by default
|
|
115
118
|
- Optional table index layout
|
|
119
|
+
- Required fields with `presence` validation
|
|
116
120
|
- Select fields with custom labels
|
|
117
121
|
- Radio fields with custom labels
|
|
118
122
|
- Automatic navigation entry
|
|
@@ -122,6 +126,32 @@ The scaffold generator provides:
|
|
|
122
126
|
- Password field support
|
|
123
127
|
- Optional readable URL parameters
|
|
124
128
|
|
|
129
|
+
### Required Fields
|
|
130
|
+
|
|
131
|
+
Use `--required` to select fields for which the scaffold generator adds a `presence` validation to the model.
|
|
132
|
+
|
|
133
|
+
Use:
|
|
134
|
+
|
|
135
|
+
```text
|
|
136
|
+
--required=FIELD,FIELD
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Example:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
bin/rails generate b4um:scaffold Customer first_name:string last_name:string company:string email:string --required=first_name,last_name,email
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
This adds the following validation to the generated model:
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
validates :first_name, :last_name, :email, presence: true
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Fields not listed in `--required` remain optional.
|
|
152
|
+
|
|
153
|
+
`--required` can be combined with other scaffold options such as `--select`, `--radio`, `--layout` and `--param`.
|
|
154
|
+
|
|
125
155
|
### Select and Radio Fields
|
|
126
156
|
|
|
127
157
|
The scaffold generator can render string attributes as select or radio fields with custom display labels.
|
|
@@ -538,6 +568,301 @@ setup is missing, the generator stops with a helpful error message and a suggest
|
|
|
538
568
|
|
|
539
569
|
Repeated generator runs do not duplicate authentication helpers, routes, navigation controls or controller protection.
|
|
540
570
|
|
|
571
|
+
## Admin
|
|
572
|
+
|
|
573
|
+
Add administrator user management to an existing b4um authentication model:
|
|
574
|
+
|
|
575
|
+
```bash
|
|
576
|
+
bin/rails generate b4um:admin MODEL
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
Example:
|
|
580
|
+
|
|
581
|
+
```bash
|
|
582
|
+
bin/rails generate b4um:admin User
|
|
583
|
+
bin/rails db:migrate
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
The Admin generator builds on the existing b4um authentication system. Authentication must therefore be installed for
|
|
587
|
+
the selected model before running the Admin generator.
|
|
588
|
+
|
|
589
|
+
A complete setup looks like this:
|
|
590
|
+
|
|
591
|
+
```bash
|
|
592
|
+
bin/rails generate b4um:scaffold User name:string email:string password_digest:string
|
|
593
|
+
bin/rails db:migrate
|
|
594
|
+
|
|
595
|
+
bin/rails generate b4um:authentication User
|
|
596
|
+
|
|
597
|
+
bin/rails generate b4um:admin User
|
|
598
|
+
bin/rails db:migrate
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
The Admin generator adds two boolean fields to the authentication model:
|
|
602
|
+
|
|
603
|
+
```text
|
|
604
|
+
admin
|
|
605
|
+
blocked
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
Both fields default to `false`.
|
|
609
|
+
|
|
610
|
+
The generator also adds:
|
|
611
|
+
|
|
612
|
+
- An Admin dashboard
|
|
613
|
+
- Admin-only controller protection
|
|
614
|
+
- User management
|
|
615
|
+
- Administrator routes
|
|
616
|
+
- Blocking and unblocking users
|
|
617
|
+
- Granting and revoking administrator rights
|
|
618
|
+
- Deleting users
|
|
619
|
+
- Protection against blocking your own account
|
|
620
|
+
- Protection against deleting your own account
|
|
621
|
+
- Protection against removing the last administrator
|
|
622
|
+
- Blocked login prevention
|
|
623
|
+
- Automatic invalidation of sessions belonging to blocked users
|
|
624
|
+
|
|
625
|
+
### Creating the First Administrator
|
|
626
|
+
|
|
627
|
+
Administrator privileges are not available through public registration.
|
|
628
|
+
|
|
629
|
+
After running the Admin generator and the database migration, create the first administrator from the command line:
|
|
630
|
+
|
|
631
|
+
```bash
|
|
632
|
+
bin/rails b4um:admin:create
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
Run the database migration before creating the first administrator:
|
|
636
|
+
|
|
637
|
+
```bash
|
|
638
|
+
bin/rails db:migrate
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
The task automatically detects additional fields from the authentication model.
|
|
642
|
+
|
|
643
|
+
Fields with an unconditional `presence` validation are marked with `*` and must be entered. Other detected fields are
|
|
644
|
+
optional and can be left empty.
|
|
645
|
+
|
|
646
|
+
Email, password and password confirmation are always required.
|
|
647
|
+
|
|
648
|
+
For example, an authentication model with required `first_name` and `last_name` fields and an optional `company` field
|
|
649
|
+
may result in:
|
|
650
|
+
|
|
651
|
+
```text
|
|
652
|
+
First name *: Alex
|
|
653
|
+
Last name *: Example
|
|
654
|
+
Company:
|
|
655
|
+
Email *: admin@example.com
|
|
656
|
+
Password *:
|
|
657
|
+
Confirm password *:
|
|
658
|
+
Administrator admin@example.com was created successfully.
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
The password is entered without being displayed in the terminal.
|
|
662
|
+
|
|
663
|
+
If the Admin migration has not been run yet, the task stops and asks you to run `bin/rails db:migrate`.
|
|
664
|
+
|
|
665
|
+
The task creates the account with:
|
|
666
|
+
|
|
667
|
+
```text
|
|
668
|
+
admin: true
|
|
669
|
+
blocked: false
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
If an account with the entered email address already exists, the task stops instead of granting administrator privileges
|
|
673
|
+
to that account.
|
|
674
|
+
|
|
675
|
+
Existing users can be promoted from the Admin user management interface after the first administrator has been created.
|
|
676
|
+
|
|
677
|
+
### Admin Area
|
|
678
|
+
|
|
679
|
+
The generated Admin area is available at:
|
|
680
|
+
|
|
681
|
+
```text
|
|
682
|
+
/admin
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
Only a logged-in account with administrator privileges can access it.
|
|
686
|
+
|
|
687
|
+
The Admin dashboard links to the generated user management interface.
|
|
688
|
+
|
|
689
|
+
From there, administrators can:
|
|
690
|
+
|
|
691
|
+
- Block users
|
|
692
|
+
- Unblock users
|
|
693
|
+
- Grant administrator rights
|
|
694
|
+
- Revoke administrator rights
|
|
695
|
+
- Delete users
|
|
696
|
+
|
|
697
|
+
The currently logged-in administrator cannot block or delete their own account through the generated interface.
|
|
698
|
+
|
|
699
|
+
The last remaining administrator cannot lose administrator rights. This prevents an application from accidentally being
|
|
700
|
+
left without an administrator.
|
|
701
|
+
|
|
702
|
+
### Blocking Users
|
|
703
|
+
|
|
704
|
+
Blocking a user sets the authentication model's `blocked` field to `true`.
|
|
705
|
+
|
|
706
|
+
A blocked user cannot log in, even with the correct password.
|
|
707
|
+
|
|
708
|
+
If a user is already logged in when the account becomes blocked, the existing session is invalidated when authentication
|
|
709
|
+
is checked again.
|
|
710
|
+
|
|
711
|
+
Unblocking the account allows the user to log in again.
|
|
712
|
+
|
|
713
|
+
### Administrator Rights
|
|
714
|
+
|
|
715
|
+
Administrator access is controlled by the authentication model's `admin` field.
|
|
716
|
+
|
|
717
|
+
A regular registered user starts with:
|
|
718
|
+
|
|
719
|
+
```text
|
|
720
|
+
admin: false
|
|
721
|
+
blocked: false
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
An administrator can grant administrator rights to an existing user from the Admin user management interface.
|
|
725
|
+
|
|
726
|
+
Administrator rights can also be revoked there, as long as this would not remove the last administrator.
|
|
727
|
+
|
|
728
|
+
The Admin generator uses the same authentication model and login system as `b4um:authentication`; it does not create a
|
|
729
|
+
separate administrator account system or a second login.
|
|
730
|
+
|
|
731
|
+
## Guest Access
|
|
732
|
+
|
|
733
|
+
Add temporary guest access to an existing b4um authentication model:
|
|
734
|
+
|
|
735
|
+
```bash
|
|
736
|
+
bin/rails generate b4um:guest MODEL --required=FIELDS
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
Example:
|
|
740
|
+
|
|
741
|
+
```bash
|
|
742
|
+
bin/rails generate b4um:guest User --required=first_name,email
|
|
743
|
+
bin/rails db:migrate
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
The Guest generator builds on the existing b4um authentication system. Authentication must therefore be installed for
|
|
747
|
+
the selected model before running the Guest generator.
|
|
748
|
+
|
|
749
|
+
At least one field must be supplied with `--required`.
|
|
750
|
+
|
|
751
|
+
A complete setup can look like this:
|
|
752
|
+
|
|
753
|
+
```bash
|
|
754
|
+
bin/rails generate b4um:scaffold User first_name:string last_name:string company:string email:string password_digest:string --required=first_name,last_name,email
|
|
755
|
+
bin/rails db:migrate
|
|
756
|
+
|
|
757
|
+
bin/rails generate b4um:authentication User
|
|
758
|
+
|
|
759
|
+
bin/rails generate b4um:guest User --required=first_name,email
|
|
760
|
+
bin/rails db:migrate
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
The Guest generator adds two fields to the authentication model:
|
|
764
|
+
|
|
765
|
+
```text
|
|
766
|
+
guest
|
|
767
|
+
guest_expires_at
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
Guest accounts use the same authentication model as regular registered accounts. The generator does not create a
|
|
771
|
+
separate Guest model.
|
|
772
|
+
|
|
773
|
+
### Guest Fields
|
|
774
|
+
|
|
775
|
+
Fields listed with `--required` are required when creating a guest account.
|
|
776
|
+
|
|
777
|
+
Example:
|
|
778
|
+
|
|
779
|
+
```bash
|
|
780
|
+
bin/rails generate b4um:guest User --required=first_name,email
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
In this example, `first_name` and `email` are required for guests.
|
|
784
|
+
|
|
785
|
+
Additional suitable fields from the authentication model are detected automatically and can be entered when creating the
|
|
786
|
+
guest account. Fields not listed with `--required` remain optional.
|
|
787
|
+
|
|
788
|
+
Technical and sensitive fields are not exposed as normal guest profile fields.
|
|
789
|
+
|
|
790
|
+
The Guest generator adapts normal account presence validations so that a guest can be created with the smaller set of
|
|
791
|
+
fields defined by `--required`. The normal account requirements still apply when the guest is converted into a regular
|
|
792
|
+
account.
|
|
793
|
+
|
|
794
|
+
### Guest Passwords
|
|
795
|
+
|
|
796
|
+
Guest accounts use the existing `has_secure_password` authentication system.
|
|
797
|
+
|
|
798
|
+
A secure internal password is generated automatically for a guest account. The guest does not need to choose or enter
|
|
799
|
+
this password when guest access is created.
|
|
800
|
+
|
|
801
|
+
When the guest later converts the account into a regular account, a normal password must be chosen.
|
|
802
|
+
|
|
803
|
+
### Expiration
|
|
804
|
+
|
|
805
|
+
Guest access expires automatically.
|
|
806
|
+
|
|
807
|
+
The default lifetime is 7 days.
|
|
808
|
+
|
|
809
|
+
A different lifetime can be configured with `--expires-in`:
|
|
810
|
+
|
|
811
|
+
```bash
|
|
812
|
+
bin/rails generate b4um:guest User --required=first_name,email --expires-in=14
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
This example gives newly created guest accounts 14 days of guest access.
|
|
816
|
+
|
|
817
|
+
The expiration time is stored in:
|
|
818
|
+
|
|
819
|
+
```text
|
|
820
|
+
guest_expires_at
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
Guests approaching expiration receive a warning before the account expires.
|
|
824
|
+
|
|
825
|
+
### Converting a Guest Account
|
|
826
|
+
|
|
827
|
+
A guest account can be converted into a regular registered account.
|
|
828
|
+
|
|
829
|
+
Conversion keeps the existing authentication model record instead of creating a second user. Data already associated
|
|
830
|
+
with the guest therefore remains associated with the converted account.
|
|
831
|
+
|
|
832
|
+
During conversion, the generated form asks for the fields that are required for a normal account as well as a password
|
|
833
|
+
and password confirmation.
|
|
834
|
+
|
|
835
|
+
After successful conversion:
|
|
836
|
+
|
|
837
|
+
```text
|
|
838
|
+
guest: false
|
|
839
|
+
guest_expires_at: nil
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
The account then behaves like a regular authenticated account.
|
|
843
|
+
|
|
844
|
+
### Deleting a Guest Account
|
|
845
|
+
|
|
846
|
+
A guest can delete the temporary account instead of converting it.
|
|
847
|
+
|
|
848
|
+
Expired guest accounts can also be removed with the generated cleanup task:
|
|
849
|
+
|
|
850
|
+
```bash
|
|
851
|
+
bin/rails b4um:guests:cleanup
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
Run this task regularly in production so expired guest accounts do not remain stored indefinitely.
|
|
855
|
+
|
|
856
|
+
The scheduling mechanism is intentionally left to the application and its deployment environment.
|
|
857
|
+
|
|
858
|
+
### Guest and Admin
|
|
859
|
+
|
|
860
|
+
Guest access and Admin management use the same authentication model.
|
|
861
|
+
|
|
862
|
+
The Guest generator can therefore be used together with `b4um:admin`. Guest-specific validation handling preserves
|
|
863
|
+
normal account requirements so administrator creation and regular account registration continue to require the
|
|
864
|
+
appropriate fields.
|
|
865
|
+
|
|
541
866
|
## Active Storage and Images
|
|
542
867
|
|
|
543
868
|
Image attachments use Rails Active Storage.
|
|
@@ -1199,7 +1524,7 @@ The gem can be tested locally by referencing the repository with `path:` from a
|
|
|
1199
1524
|
|
|
1200
1525
|
## Version
|
|
1201
1526
|
|
|
1202
|
-
Current version: `0.
|
|
1527
|
+
Current version: `0.4.0`
|
|
1203
1528
|
|
|
1204
1529
|
## Author
|
|
1205
1530
|
|