From 51a176bd698da9f6733dab082ad57c6d4070b6e0 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Mon, 6 Sep 2021 09:54:43 +0200
Subject: [PATCH] websites with repo and token

---
 .../admin/communication/websites_controller.rb      |  2 +-
 .../admin/research/journal/volumes_controller.rb    |  3 ++-
 app/models/communication/website.rb                 |  2 ++
 app/models/research/journal/volume.rb               |  3 +++
 .../admin/communication/websites/_form.html.erb     |  8 ++++++--
 .../admin/research/journal/volumes/_form.html.erb   | 13 ++++++++++---
 .../admin/research/journal/volumes/jekyll.html.erb  |  2 +-
 db/migrate/20210906072443_add_repo_to_websites.rb   |  6 ++++++
 ...2_add_description_to_research_journal_volumes.rb |  5 +++++
 db/schema.rb                                        |  5 ++++-
 test/fixtures/research/journal/volumes.yml          |  1 +
 test/models/research/journal/volume_test.rb         |  1 +
 12 files changed, 42 insertions(+), 9 deletions(-)
 create mode 100644 db/migrate/20210906072443_add_repo_to_websites.rb
 create mode 100644 db/migrate/20210906074132_add_description_to_research_journal_volumes.rb

diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb
index f8e4754c3..2f40b095a 100644
--- a/app/controllers/admin/communication/websites_controller.rb
+++ b/app/controllers/admin/communication/websites_controller.rb
@@ -51,6 +51,6 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati
   end
 
   def website_params
-    params.require(:communication_website).permit(:name, :domain)
+    params.require(:communication_website).permit(:name, :domain, :repository, :access_token)
   end
 end
diff --git a/app/controllers/admin/research/journal/volumes_controller.rb b/app/controllers/admin/research/journal/volumes_controller.rb
index 0e7911460..3ed534842 100644
--- a/app/controllers/admin/research/journal/volumes_controller.rb
+++ b/app/controllers/admin/research/journal/volumes_controller.rb
@@ -2,6 +2,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap
   load_and_authorize_resource class: Research::Journal::Volume
 
   def index
+    @volumes = @volumes.ordered
     breadcrumb
   end
 
@@ -54,6 +55,6 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap
   end
 
   def volume_params
-    params.require(:research_journal_volume).permit(:title, :number, :published_at)
+    params.require(:research_journal_volume).permit(:title, :number, :published_at, :description)
   end
 end
diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb
index 18f308ca1..c5ac8d1d5 100644
--- a/app/models/communication/website.rb
+++ b/app/models/communication/website.rb
@@ -3,8 +3,10 @@
 # Table name: communication_websites
 #
 #  id            :uuid             not null, primary key
+#  access_token  :string
 #  domain        :string
 #  name          :string
+#  repository    :string
 #  created_at    :datetime         not null
 #  updated_at    :datetime         not null
 #  university_id :uuid             not null
diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb
index 39fc7f41a..ed0e9f297 100644
--- a/app/models/research/journal/volume.rb
+++ b/app/models/research/journal/volume.rb
@@ -3,6 +3,7 @@
 # Table name: research_journal_volumes
 #
 #  id                  :uuid             not null, primary key
+#  description         :text
 #  number              :integer
 #  published_at        :datetime
 #  title               :string
@@ -28,6 +29,8 @@ class Research::Journal::Volume < ApplicationRecord
 
   after_save :publish_to_github
 
+  scope :ordered, -> { order(number: :desc, published_at: :desc) }
+
   def to_s
     "##{ number } #{ title }"
   end
diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb
index 85bfdf3ac..a4161a45d 100644
--- a/app/views/admin/communication/websites/_form.html.erb
+++ b/app/views/admin/communication/websites/_form.html.erb
@@ -1,10 +1,14 @@
 <%= simple_form_for [:admin, website] do |f| %>
   <div class="row">
-    <div class="col-md-6">
+    <div class="col-md-4">
       <%= f.input :name %>
     </div>
-    <div class="col-md-6">
+    <div class="col-md-4">
       <%= f.input :domain %>
+      <%= f.input :repository %>
+      <%= f.input :access_token %>
+    </div>
+    <div class="col-md-4">
     </div>
   </div>
   <% content_for :buttons do %>
diff --git a/app/views/admin/research/journal/volumes/_form.html.erb b/app/views/admin/research/journal/volumes/_form.html.erb
index 04fb38734..0ab792a10 100644
--- a/app/views/admin/research/journal/volumes/_form.html.erb
+++ b/app/views/admin/research/journal/volumes/_form.html.erb
@@ -1,7 +1,14 @@
 <%= simple_form_for [:admin, volume] do |f| %>
-  <%= f.input :title %>
-  <%= f.input :number %>
-  <%= f.input :published_at, html5: true %>
+  <div class="row">
+    <div class="col-md-4">
+      <%= f.input :title %>
+      <%= f.input :number %>
+      <%= f.input :published_at, html5: true %>
+    </div>
+    <div class="col-md-8">
+      <%= f.input :description, input_html: { rows: 5 } %>
+    </div>
+  </div>
   <% content_for :buttons do %>
     <%= submit f %>
   <% end %>
diff --git a/app/views/admin/research/journal/volumes/jekyll.html.erb b/app/views/admin/research/journal/volumes/jekyll.html.erb
index f02574e99..c55119b9b 100644
--- a/app/views/admin/research/journal/volumes/jekyll.html.erb
+++ b/app/views/admin/research/journal/volumes/jekyll.html.erb
@@ -21,4 +21,4 @@ articles:
   - <%= article.id %>
 <% end %>
 ---
-The internal dynamics of political parties were a central concern for the founders of both organization theory and political sociology, yet contemporary research tends to neglect the importance and value of studying these electoral machines from a truly organizational point of view. The present issue seeks to remedy this shortcoming by allowing curious and creative scholars to reimagine what it might mean for organization scholars and activists alike to engage actively with political parties. While some contributions reflect on the idiosyncrasies of political parties in general, most articles and notes cultivate a so-called immersive approach to the study of party organization, in which the researcher ventures beyond the glossy surface of party propaganda in order to experience and analyze party organizing in practice rather than on paper. These ambitions yield fascinating accounts of parties such as Podemos, En Marche, DiEM25, Movimento 5 Stelle, the British Labour Party, as well as the German and Icelandic Pirate Party.
+<%= @volume.description %>
diff --git a/db/migrate/20210906072443_add_repo_to_websites.rb b/db/migrate/20210906072443_add_repo_to_websites.rb
new file mode 100644
index 000000000..109bb847c
--- /dev/null
+++ b/db/migrate/20210906072443_add_repo_to_websites.rb
@@ -0,0 +1,6 @@
+class AddRepoToWebsites < ActiveRecord::Migration[6.1]
+  def change
+    add_column :communication_websites, :access_token, :string
+    add_column :communication_websites, :repository, :string
+  end
+end
diff --git a/db/migrate/20210906074132_add_description_to_research_journal_volumes.rb b/db/migrate/20210906074132_add_description_to_research_journal_volumes.rb
new file mode 100644
index 000000000..d695cad93
--- /dev/null
+++ b/db/migrate/20210906074132_add_description_to_research_journal_volumes.rb
@@ -0,0 +1,5 @@
+class AddDescriptionToResearchJournalVolumes < ActiveRecord::Migration[6.1]
+  def change
+    add_column :research_journal_volumes, :description, :text
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 44e5ac9a5..9066a2fdc 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.define(version: 2021_08_31_122745) do
+ActiveRecord::Schema.define(version: 2021_09_06_074132) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -64,6 +64,8 @@ ActiveRecord::Schema.define(version: 2021_08_31_122745) do
     t.string "domain"
     t.datetime "created_at", precision: 6, null: false
     t.datetime "updated_at", precision: 6, null: false
+    t.string "access_token"
+    t.string "repository"
     t.index ["university_id"], name: "index_communication_websites_on_university_id"
   end
 
@@ -110,6 +112,7 @@ ActiveRecord::Schema.define(version: 2021_08_31_122745) do
     t.datetime "published_at"
     t.datetime "created_at", precision: 6, null: false
     t.datetime "updated_at", precision: 6, null: false
+    t.text "description"
     t.index ["research_journal_id"], name: "index_research_journal_volumes_on_research_journal_id"
     t.index ["university_id"], name: "index_research_journal_volumes_on_university_id"
   end
diff --git a/test/fixtures/research/journal/volumes.yml b/test/fixtures/research/journal/volumes.yml
index b5dfce353..1ffa4e70c 100644
--- a/test/fixtures/research/journal/volumes.yml
+++ b/test/fixtures/research/journal/volumes.yml
@@ -3,6 +3,7 @@
 # Table name: research_journal_volumes
 #
 #  id                  :uuid             not null, primary key
+#  description         :text
 #  number              :integer
 #  published_at        :datetime
 #  title               :string
diff --git a/test/models/research/journal/volume_test.rb b/test/models/research/journal/volume_test.rb
index 3d62a1aaa..a8ffee5ad 100644
--- a/test/models/research/journal/volume_test.rb
+++ b/test/models/research/journal/volume_test.rb
@@ -3,6 +3,7 @@
 # Table name: research_journal_volumes
 #
 #  id                  :uuid             not null, primary key
+#  description         :text
 #  number              :integer
 #  published_at        :datetime
 #  title               :string
-- 
GitLab