diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/debt-manager.iml b/.idea/debt-manager.iml
new file mode 100644
index 0000000..c467147
--- /dev/null
+++ b/.idea/debt-manager.iml
@@ -0,0 +1,293 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ file://$MODULE_DIR$/app
+
+
+ file://$MODULE_DIR$/app/assets
+
+
+ file://$MODULE_DIR$/app/channels
+
+
+ file://$MODULE_DIR$/app/controllers
+
+
+ file://$MODULE_DIR$/app/helpers
+
+
+ file://$MODULE_DIR$/app/mailers
+
+
+ file://$MODULE_DIR$/app/models
+
+
+ file://$MODULE_DIR$/app/views
+
+
+ file://$MODULE_DIR$/config
+
+
+ file://$MODULE_DIR$/config/cable.yml
+
+
+ file://$MODULE_DIR$/config/database.yml
+
+
+ file://$MODULE_DIR$/config/environment.rb
+
+
+ file://$MODULE_DIR$/config/environments
+
+
+ file://$MODULE_DIR$/config/initializers
+
+
+ file://$MODULE_DIR$/config/locales
+
+
+ file://$MODULE_DIR$/config/routes
+
+
+ file://$MODULE_DIR$/config/routes.rb
+
+
+ file://$MODULE_DIR$/config
+
+
+ file://$MODULE_DIR$/db
+
+
+ file://$MODULE_DIR$/db/migrate
+
+
+ file://$MODULE_DIR$/db/seeds.rb
+
+
+ file://$MODULE_DIR$/lib
+
+
+ file://$MODULE_DIR$/lib/assets
+
+
+ file://$MODULE_DIR$/lib/tasks
+
+
+ file://$MODULE_DIR$/lib/templates
+
+
+ file://$MODULE_DIR$/log/development.log
+
+
+ file://$MODULE_DIR$/public
+
+
+ file://$MODULE_DIR$/public/javascripts
+
+
+ file://$MODULE_DIR$/public/stylesheets
+
+
+ file://$MODULE_DIR$/tmp
+
+
+ file://$MODULE_DIR$/vendor
+
+
+ file://$MODULE_DIR$/vendor/assets
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..adee33d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..e411da0
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/controllers/bubbles_controller.rb b/app/controllers/bubbles_controller.rb
index 7695138..f65d925 100644
--- a/app/controllers/bubbles_controller.rb
+++ b/app/controllers/bubbles_controller.rb
@@ -46,7 +46,7 @@ class BubblesController < ApplicationController
private
def allowed_params
- params.require(:bubble).permit(:name, :description, :color)
+ params.require(:bubble).permit(:name, :description, :color, :owner_id)
end
end
\ No newline at end of file
diff --git a/app/models/bubble.rb b/app/models/bubble.rb
index 1108d25..36c360d 100644
--- a/app/models/bubble.rb
+++ b/app/models/bubble.rb
@@ -8,7 +8,17 @@
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
+# owner_id :uuid not null
+#
+# Indexes
+#
+# index_bubbles_on_owner_id (owner_id)
+#
+# Foreign Keys
+#
+# fk_rails_... (owner_id => users.id)
#
class Bubble < ApplicationRecord
validates :name, presence: true, allow_blank: false
+ belongs_to :owner, class_name: "User"
end
diff --git a/app/models/user.rb b/app/models/user.rb
index fedf1d8..9aac96e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -21,4 +21,6 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
+
+ has_many :bubbles, foreign_key: :owner_id
end
diff --git a/app/views/bubbles/shared/_form.html.erb b/app/views/bubbles/shared/_form.html.erb
index c3b016a..d7c1572 100644
--- a/app/views/bubbles/shared/_form.html.erb
+++ b/app/views/bubbles/shared/_form.html.erb
@@ -1,21 +1,25 @@
<%= form_for bubble, url: bubble.persisted? ? bubble_path(bubble) : bubbles_path do |f| %>
-
+
<%= f.label :name, "Nom" %>
<%= f.text_field :name, required: true %>
-
+
-
+
<%= f.label :description, "Description" %>
<%= f.text_area :description %>
-
+
-
+
<%= f.label :color, "Couleur" %>
<%= f.color_field :color %>
-
+
+
+ <%= f.label :owner_id, "Administrateur" %>
+ <%= f.select :owner_id, User.all.collect {|u| [ u.email, u.id ] }, selected: bubble.owner_id || current_user.id %>
+
-<%= f.submit "Sauvegarder" %>
+ <%= f.submit "Sauvegarder" %>
<% end %>
\ No newline at end of file
diff --git a/db/migrate/20231210091848_add_owner_to_bubbles.rb b/db/migrate/20231210091848_add_owner_to_bubbles.rb
new file mode 100644
index 0000000..07f5fa5
--- /dev/null
+++ b/db/migrate/20231210091848_add_owner_to_bubbles.rb
@@ -0,0 +1,5 @@
+class AddOwnerToBubbles < ActiveRecord::Migration[7.0]
+ def change
+ add_reference(:bubbles, :owner, type: :uuid, foreign_key: { to_table: :users }, null: false)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index d9962ab..90d32be 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2023_11_01_172623) do
+ActiveRecord::Schema[7.0].define(version: 2023_12_10_091848) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@@ -21,6 +21,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_01_172623) do
t.string "color", default: "#0000ff", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.uuid "owner_id", null: false
+ t.index ["owner_id"], name: "index_bubbles_on_owner_id"
end
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@@ -35,4 +37,5 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_01_172623) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
+ add_foreign_key "bubbles", "users", column: "owner_id"
end