Skip to content

Commit eeed942

Browse files
committed
Use 'public_visibility' & add unique member organization constraint
Misc change - Also use different annotate gem https://github.com/drwl/annotaterb as it has compatibility with Rails 8 and it overcomes the issues mentioned here: ctran/annotate_models#1032
1 parent f620fce commit eeed942

26 files changed

+278
-267
lines changed

.annotaterb.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
:position: before
3+
:position_in_additional_file_patterns: before
4+
:position_in_class: before
5+
:position_in_factory: before
6+
:position_in_fixture: before
7+
:position_in_routes: before
8+
:position_in_serializer: before
9+
:position_in_test: before
10+
:classified_sort: true
11+
:exclude_controllers: true
12+
:exclude_factories: false
13+
:exclude_fixtures: false
14+
:exclude_helpers: true
15+
:exclude_scaffolds: true
16+
:exclude_serializers: false
17+
:exclude_sti_subclasses: false
18+
:exclude_tests: false
19+
:force: false
20+
:format_markdown: false
21+
:format_rdoc: false
22+
:format_yard: false
23+
:frozen: false
24+
:ignore_model_sub_dir: false
25+
:ignore_unknown_models: false
26+
:include_version: false
27+
:show_check_constraints: false
28+
:show_complete_foreign_keys: false
29+
:show_foreign_keys: true
30+
:show_indexes: true
31+
:simple_indexes: false
32+
:sort: false
33+
:timestamp: false
34+
:trace: false
35+
:with_comment: true
36+
:with_column_comments: true
37+
:with_table_comments: true
38+
:active_admin: false
39+
:command:
40+
:debug: false
41+
:hide_default_column_types: ''
42+
:hide_limit_column_types: ''
43+
:ignore_columns:
44+
:ignore_routes:
45+
:models: true
46+
:routes: false
47+
:skip_on_db_migrate: false
48+
:target_action: :do_annotations
49+
:wrapper:
50+
:wrapper_close:
51+
:wrapper_open:
52+
:classes_default_to_s: []
53+
:additional_file_patterns: []
54+
:model_dir:
55+
- app/models
56+
:require: []
57+
:root_dir:
58+
- ''

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ group :development do
8585

8686
gem 'flog', require: false # Flog reports the most tortured code in an easy to read pain report
8787

88-
gem 'annotate' # Annotate Rails classes with schema and routes info
88+
gem 'annotaterb' # Annotate Rails classes with schema and routes info
8989

9090
gem 'i18n-debug' # Get more clarity on which Internationalisation related translations are looked up
9191
end

Gemfile.lock

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ GEM
7474
uri (>= 0.13.1)
7575
addressable (2.8.7)
7676
public_suffix (>= 2.0.2, < 7.0)
77-
annotate (2.6.5)
78-
activerecord (>= 2.3.0)
79-
rake (>= 0.8.7)
77+
annotaterb (4.13.0)
8078
ast (2.4.2)
8179
base64 (0.2.0)
8280
bcrypt (3.1.20)
@@ -376,7 +374,7 @@ PLATFORMS
376374
x86_64-linux
377375

378376
DEPENDENCIES
379-
annotate
377+
annotaterb
380378
bcrypt (~> 3.1.7)
381379
bootsnap
382380
brakeman

app/controllers/learnings_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ def destroy
8888
private
8989

9090
def learnings_params
91-
params.require(:learning).permit(:lesson, :description, :public, :organization_id, learning_category_ids: [])
91+
params.require(:learning).permit(:lesson, :description, :public_visibility, :organization_id, learning_category_ids: [])
9292
end
9393
end

app/models/learning.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# description(Learning lesson in more detail) :text
1010
# learning_category_ids(Collection of different learning categories a Learning belongs to) :integer default([]), is an Array
1111
# lesson(Learning lesson learnt) :string not null
12-
# public(Determines organizational visibility of the learning) :boolean default(FALSE), not null
12+
# public_visibility(Determines organizational visibility of the learning) :boolean default(FALSE), not null
1313
# created_at :datetime not null
1414
# updated_at :datetime not null
1515
# creator_id(User who created the learning) :bigint not null

app/models/learning_category.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
2-
32
# == Schema Information
43
#
54
# Table name: learning_categories
@@ -25,6 +24,7 @@
2524
# fk_rails_... (creator_id => users.id)
2625
# fk_rails_... (last_modifier_id => users.id)
2726
#
27+
2828
class LearningCategory < ApplicationRecord
2929
acts_as_paranoid
3030

app/models/membership.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
2-
32
# == Schema Information
43
#
54
# Table name: memberships
@@ -12,14 +11,16 @@
1211
#
1312
# Indexes
1413
#
15-
# index_memberships_on_member_id (member_id)
16-
# index_memberships_on_organization_id (organization_id)
14+
# index_memberships_on_member_id (member_id)
15+
# index_memberships_on_member_id_and_organization_id (member_id,organization_id) UNIQUE
16+
# index_memberships_on_organization_id (organization_id)
1717
#
1818
# Foreign Keys
1919
#
2020
# fk_rails_... (member_id => users.id)
2121
# fk_rails_... (organization_id => organizations.id)
2222
#
23+
2324
class Membership < ApplicationRecord
2425
belongs_to :member, class_name: 'User'
2526
belongs_to :organization

app/models/organization.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# frozen_string_literal: true
2-
32
# == Schema Information
43
#
54
# Table name: organizations
65
#
76
# id :bigint not null, primary key
8-
# name :string not null
97
# created_at :datetime not null
108
# updated_at :datetime not null
9+
# name :string not null
1110
#
1211
# Indexes
1312
#
1413
# index_organizations_on_name (name) UNIQUE
1514
#
15+
1616
class Organization < ApplicationRecord
1717
has_many :memberships, dependent: :destroy
1818
has_many :members, through: :memberships

app/views/learnings/edit.html.erb

+68-74
Original file line numberDiff line numberDiff line change
@@ -3,106 +3,100 @@
33
<div class="columns is-centered">
44
<div class="column is-8-desktop is-11-tablet is-12-mobile">
55
<div class="box p-5">
6-
<h1 class="title has-text-centered mb-5"><%= t(".title") %></h1>
6+
<h1 class="title has-text-centered mb-5">
7+
<%= t(".title") %>
8+
</h1>
79
<%= form_with(model: @learning, local: true) do |f| %>
810
<% if @learning.errors.any? %>
911
<div class="notification is-danger is-light">
1012
<h2 class="subtitle">
11-
<%= pluralize(@learning.errors.count, "error") %> prohibited this learning from being saved:
13+
<%= pluralize(@learning.errors.count, "error" ) %> prohibited this learning from being saved:
1214
</h2>
1315
<ul class="ml-4">
1416
<% @learning.errors.full_messages.each do |msg| %>
15-
<li><%= msg %></li>
16-
<% end %>
17+
<li>
18+
<%= msg %>
19+
</li>
20+
<% end %>
1721
</ul>
1822
</div>
19-
<% end %>
23+
<% end %>
2024

21-
<div class="field mb-4">
22-
<%= f.label :lesson, class: "label" %>
23-
<div class="control">
24-
<%= f.text_field :lesson,
25-
class: "input",
26-
placeholder: "Enter learning name" %>
27-
</div>
28-
</div>
25+
<div class="field mb-4">
26+
<%= f.label :lesson, class: "label" %>
27+
<div class="control">
28+
<%= f.text_field :lesson, class: "input" , placeholder: "Enter learning name" %>
29+
</div>
30+
</div>
2931

30-
<div class="field mb-4">
31-
<%= f.label :description, class: "label" %>
32-
<div class="control">
33-
<%= f.text_area :description,
34-
class: "textarea",
35-
placeholder: "Enter learning description",
36-
rows: 5 %>
37-
</div>
38-
</div>
32+
<div class="field mb-4">
33+
<%= f.label :description, class: "label" %>
34+
<div class="control">
35+
<%= f.text_area :description, class: "textarea" , placeholder: "Enter learning description" ,
36+
rows: 5 %>
37+
</div>
38+
</div>
3939

40-
<div class="field mb-4">
41-
<%= f.label :organization_id, "Organization", class: "label" %>
42-
<div class="control">
43-
<div class="select is-fullwidth">
44-
<%= f.collection_select :organization_id,
45-
current_user.organizations,
46-
:id,
47-
:name,
48-
{ prompt: "Select an organization" },
49-
{ class: "select" } %>
40+
<div class="field mb-4">
41+
<%= f.label :organization_id, "Organization" , class: "label" %>
42+
<div class="control">
43+
<div class="select is-fullwidth">
44+
<%= f.collection_select :organization_id, current_user.organizations, :id, :name, {
45+
prompt: "Select an organization" }, { class: "select" } %>
46+
</div>
47+
</div>
5048
</div>
51-
</div>
52-
</div>
5349

54-
<div class="field mb-5">
55-
<%= f.label "Learning Categories", class: "label mb-3" %>
56-
<div class="control">
57-
<div class="columns is-multiline is-mobile">
58-
<% LearningCategory.all.each do |category| %>
59-
<div class="column is-half-mobile is-one-third-tablet">
50+
<div class="field mb-5">
51+
<%= f.label "Learning Categories" , class: "label mb-3" %>
52+
<div class="control">
53+
<div class="columns is-multiline is-mobile">
54+
<% LearningCategory.all.each do |category| %>
55+
<div class="column is-half-mobile is-one-third-tablet">
56+
<label class="checkbox">
57+
<%= check_box_tag "learning[learning_category_ids][]" , category.id,
58+
@learning.learning_category_ids.include?(category),
59+
id: "learning_category_#{category.id}" %>
60+
<span class="ml-2">
61+
<%= category.name %>
62+
</span>
63+
</label>
64+
</div>
65+
<% end %>
66+
</div>
67+
</div>
68+
</div>
69+
70+
<div class="field mb-5">
71+
<%= f.label :public, class: "label" %>
72+
<div class="control">
6073
<label class="checkbox">
61-
<%= check_box_tag "learning[learning_category_ids][]",
62-
category.id,
63-
@learning.learning_category_ids.include?(category),
64-
id: "learning_category_#{category.id}" %>
65-
<span class="ml-2"><%= category.name %></span>
74+
<%= f.check_box :public_visibility %>
75+
<span class="ml-2">Make this learning public</span>
6676
</label>
77+
<p class="help">Public learnings can be viewed by all users</p>
6778
</div>
68-
<% end %>
6979
</div>
70-
</div>
71-
</div>
72-
73-
<div class="field mb-5">
74-
<%= f.label :public, class: "label" %>
75-
<div class="control">
76-
<label class="checkbox">
77-
<%= f.check_box :public %>
78-
<span class="ml-2">Make this learning public</span>
79-
</label>
80-
<p class="help">Public learnings can be viewed by all users</p>
81-
</div>
82-
</div>
8380

84-
<div class="field is-grouped is-grouped-centered mt-5">
85-
<div class="control">
86-
<%= f.submit "Update Learning",
87-
class: "button is-primary is-medium px-5" %>
88-
</div>
89-
<div class="control">
90-
<%= link_to "Cancel",
91-
learnings_path,
92-
class: "button is-light is-medium" %>
93-
</div>
94-
</div>
95-
<% end %>
81+
<div class="field is-grouped is-grouped-centered mt-5">
82+
<div class="control">
83+
<%= f.submit "Update Learning" , class: "button is-primary is-medium px-5" %>
84+
</div>
85+
<div class="control">
86+
<%= link_to "Cancel" , learnings_path, class: "button is-light is-medium" %>
87+
</div>
88+
</div>
89+
<% end %>
9690
</div>
9791

9892
<div class="has-text-centered mt-4 mb-4">
99-
<%= link_to learnings_path,
100-
class: "has-text-grey is-flex is-align-items-center is-justify-content-center" do %>
93+
<%= link_to learnings_path, class: "has-text-grey is-flex is-align-items-center is-justify-content-center" do
94+
%>
10195
<span class="icon">
10296
<i class="fas fa-arrow-left"></i>
10397
</span>
10498
<span>Back to Learnings</span>
105-
<% end %>
99+
<% end %>
106100
</div>
107101
</div>
108102
</div>

0 commit comments

Comments
 (0)