Commit 39b33a9fce5ae445a0b3fc67f77f683100860c37

Thomas de Grivel 2021-11-22T18:00:54

deploy only. remove IO.inspect

diff --git a/lib/kmxgit/repository_manager.ex b/lib/kmxgit/repository_manager.ex
index 936ba10..acb4547 100644
--- a/lib/kmxgit/repository_manager.ex
+++ b/lib/kmxgit/repository_manager.ex
@@ -76,7 +76,6 @@ defmodule Kmxgit.RepositoryManager do
     user = UserManager.get_user_by_slug(login)
     if user do
       members = [user | repo.members]
-      IO.inspect(members)
       repo
       |> Repository.changeset(%{})
       |> Ecto.Changeset.put_assoc(:members, members)
diff --git a/lib/kmxgit/user_manager/user.ex b/lib/kmxgit/user_manager/user.ex
index 7a8a725..3aeb0a7 100644
--- a/lib/kmxgit/user_manager/user.ex
+++ b/lib/kmxgit/user_manager/user.ex
@@ -8,6 +8,7 @@ defmodule Kmxgit.UserManager.User do
   alias BCrypt
 
   schema "users" do
+    field :deploy_only, :boolean, null: false, default: false
     field :description, :string, null: true
     field :email, :string, unique: true
     field :encrypted_password, :string
@@ -28,7 +29,7 @@ defmodule Kmxgit.UserManager.User do
     |> check_password_confirmation()
     |> put_password_hash()
     |> cast_assoc(:slug)
-    |> validate_required([:email, :slug, :encrypted_password])
+    |> validate_required([:deploy_only, :email, :encrypted_password, :is_admin, :slug])
     |> validate_format(:email, ~r/^[-_+.0-9A-Za-z]+@([-_0-9A-Za-z]+[.])+[A-Za-z]+$/)
     |> unique_constraint(:_lower_email)
     |> Markdown.validate_markdown(:description)
@@ -36,13 +37,13 @@ defmodule Kmxgit.UserManager.User do
 
   def changeset(user, attrs \\ %{}) do
     user
-    |> cast(attrs, [:description, :email, :name, :password, :password_confirmation, :ssh_keys])
+    |> cast(attrs, [:deploy_only, :description, :email, :name, :password, :password_confirmation, :ssh_keys])
     |> common_changeset()
   end
 
   def admin_changeset(user, attrs \\ %{}) do
     user
-    |> cast(attrs, [:description, :email, :is_admin, :name, :password, :password_confirmation, :ssh_keys])
+    |> cast(attrs, [:deploy_only, :description, :email, :is_admin, :name, :password, :password_confirmation, :ssh_keys])
     |> common_changeset()
   end
 
diff --git a/lib/kmxgit_web/controllers/admin/organisation_controller.ex b/lib/kmxgit_web/controllers/admin/organisation_controller.ex
index 55f6928..2616b2c 100644
--- a/lib/kmxgit_web/controllers/admin/organisation_controller.ex
+++ b/lib/kmxgit_web/controllers/admin/organisation_controller.ex
@@ -86,7 +86,6 @@ defmodule KmxgitWeb.Admin.OrganisationController do
           conn
           |> redirect(to: Routes.admin_organisation_path(conn, :show, org))
         {:error, changeset} ->
-          IO.inspect(changeset)
           conn
           |> assign(:action, Routes.admin_organisation_path(conn, :update, organisation))
           |> assign(:changeset, changeset)
diff --git a/lib/kmxgit_web/controllers/admin/repository_controller.ex b/lib/kmxgit_web/controllers/admin/repository_controller.ex
index 95cc903..d621455 100644
--- a/lib/kmxgit_web/controllers/admin/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/admin/repository_controller.ex
@@ -57,7 +57,6 @@ defmodule KmxgitWeb.Admin.RepositoryController do
         conn
         |> redirect(to: Routes.admin_repository_path(conn, :show, repo))
       {:error, changeset} ->
-        IO.inspect(changeset)
         conn
         |> assign(:action, Routes.admin_repository_path(conn, :create))
         |> assign(:changeset, changeset)
@@ -98,7 +97,6 @@ defmodule KmxgitWeb.Admin.RepositoryController do
         conn
         |> redirect(to: Routes.admin_repository_path(conn, :show, repo))
       {:error, changeset} ->
-        IO.inspect(changeset)
         conn
         |> assign(:action, Routes.admin_repository__path(conn, :update, repo))
         |> assign(:changeset, changeset)
diff --git a/lib/kmxgit_web/controllers/organisation_controller.ex b/lib/kmxgit_web/controllers/organisation_controller.ex
index 494cbd3..373fc9c 100644
--- a/lib/kmxgit_web/controllers/organisation_controller.ex
+++ b/lib/kmxgit_web/controllers/organisation_controller.ex
@@ -19,7 +19,6 @@ defmodule KmxgitWeb.OrganisationController do
         conn
         |> redirect(to: Routes.slug_path(conn, :show, organisation.slug.slug))
       {:error, changeset} ->
-        IO.inspect(changeset)
         conn
         |> assign(:action, Routes.organisation_path(conn, :create))
         |> assign(:changeset, changeset)
@@ -68,7 +67,6 @@ defmodule KmxgitWeb.OrganisationController do
           conn
           |> redirect(to: Routes.slug_path(conn, :show, org.slug.slug))
         {:error, changeset} ->
-          IO.inspect(changeset)
           conn
           |> render("edit.html", changeset: changeset,
                     action: Routes.organisation_path(conn, :update, organisation.slug.slug))
@@ -100,7 +98,7 @@ defmodule KmxgitWeb.OrganisationController do
         {:ok, org} ->
           conn
           |> redirect(to: Routes.slug_path(conn, :show, org.slug.slug))
-        {:error, _} ->
+        {:error, e} ->
           conn
           |> assign(:action, Routes.organisation_path(conn, :add_user_post, params["slug"]))
           |> assign(:current_organisation, org)
diff --git a/lib/kmxgit_web/controllers/page_controller.ex b/lib/kmxgit_web/controllers/page_controller.ex
index 123c3b8..18e791f 100644
--- a/lib/kmxgit_web/controllers/page_controller.ex
+++ b/lib/kmxgit_web/controllers/page_controller.ex
@@ -36,7 +36,6 @@ defmodule KmxgitWeb.PageController do
             |> Guardian.Plug.sign_in(user)
             |> redirect(to: "/")
           {:error, changeset} ->
-            IO.inspect(changeset)
             conn
             |> assign(:no_navbar_links, true)
             |> assign(:changeset, changeset)
diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index b8789ec..5bf4e60 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -76,7 +76,6 @@ defmodule KmxgitWeb.RepositoryController do
         conn
         |> redirect(to: Routes.repository_path(conn, :show, owner.slug.slug, Repository.splat(repo)))
       {:error, changeset} ->
-        IO.inspect(changeset)
         conn
         |> assign(:action, Routes.repository_path(conn, :create, owner.slug.slug))
         |> assign(:changeset, changeset)
@@ -145,7 +144,6 @@ defmodule KmxgitWeb.RepositoryController do
             conn
             |> redirect(to: Routes.repository_path(conn, :show, params["owner"], Repository.splat(repo)))
           {:error, changeset} ->
-            IO.inspect(changeset)
             conn
             |> assign(:action, Routes.repository_path(conn, :update, params["owner"], Repository.splat(repo)))
             |> assign(:changeset, changeset)
diff --git a/lib/kmxgit_web/templates/admin/user/form.html.heex b/lib/kmxgit_web/templates/admin/user/form.html.heex
index a8b2175..eec8af5 100644
--- a/lib/kmxgit_web/templates/admin/user/form.html.heex
+++ b/lib/kmxgit_web/templates/admin/user/form.html.heex
@@ -38,6 +38,12 @@
     <%= error_tag f, :is_admin %>
   </div>
 
+  <div class="mb-3 form-check">
+    <%= checkbox f, :deploy_only, class: "form-check-input" %>
+    <%= label f, :deploy_only, class: "form-check-label" %>
+    <%= error_tag f, :deploy_only %>
+  </div>
+
   <div class="form-group">
     <%= if @conn.assigns[:user] do %>
       <%= link gettext("Cancel"),
diff --git a/lib/kmxgit_web/templates/admin/user/show.html.heex b/lib/kmxgit_web/templates/admin/user/show.html.heex
index dcc1371..f056547 100644
--- a/lib/kmxgit_web/templates/admin/user/show.html.heex
+++ b/lib/kmxgit_web/templates/admin/user/show.html.heex
@@ -40,6 +40,10 @@
       <th><%= gettext "Admin" %></th>
       <td><%= @user.is_admin %></td>
     </tr>
+    <tr>
+      <th><%= gettext "Deploy only" %></th>
+      <td><%= @user.deploy_only %></td>
+    </tr>
   </table>
 
   <%= link gettext("Delete user"),
diff --git a/lib/kmxgit_web/templates/user/edit.html.heex b/lib/kmxgit_web/templates/user/edit.html.heex
index 1d82b1b..59b3966 100644
--- a/lib/kmxgit_web/templates/user/edit.html.heex
+++ b/lib/kmxgit_web/templates/user/edit.html.heex
@@ -39,6 +39,12 @@
       <%= password_input f, :password_confirmation, class: "form-control" %>
     </div>
 
+    <div class="mb-3 form-check">
+      <%= checkbox f, :deploy_only, class: "form-check-input" %>
+      <%= label f, :deploy_only, class: "form-check-label" %>
+      <%= error_tag f, :deploy_only %>
+    </div>
+
     <div class="mb-3">
       <%= link gettext("Cancel"),
                to: Routes.slug_path(@conn, :show, @current_user.slug.slug),
diff --git a/lib/kmxgit_web/templates/user/show.html.heex b/lib/kmxgit_web/templates/user/show.html.heex
index 7d955ed..0f92445 100644
--- a/lib/kmxgit_web/templates/user/show.html.heex
+++ b/lib/kmxgit_web/templates/user/show.html.heex
@@ -46,6 +46,10 @@
           </td>
         </tr>
         <tr>
+          <th><%= gettext "Deploy only" %></th>
+          <td><%= @user.deploy_only %></td>
+        </tr>
+        <tr>
           <th>
             <%= gettext "Organisations" %>
           </th>
diff --git a/priv/repo/migrations/20211122130426_add_deploy_only_to_users.exs b/priv/repo/migrations/20211122130426_add_deploy_only_to_users.exs
new file mode 100644
index 0000000..b0c2ae7
--- /dev/null
+++ b/priv/repo/migrations/20211122130426_add_deploy_only_to_users.exs
@@ -0,0 +1,9 @@
+defmodule Kmxgit.Repo.Migrations.AddDeployOnlyToUsers do
+  use Ecto.Migration
+
+  def change do
+    alter table(:users) do
+      add :deploy_only, :boolean, null: false, default: false
+    end
+  end
+end