add authorized_keys views and editable fields
authorTom Clegg <tom@clinicalfuture.com>
Thu, 6 Jun 2013 22:19:52 +0000 (18:19 -0400)
committerTom Clegg <tom@clinicalfuture.com>
Thu, 6 Jun 2013 22:19:52 +0000 (18:19 -0400)
13 files changed:
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/models/arvados_base.rb
apps/workbench/app/models/authorized_key.rb
apps/workbench/app/models/collection.rb
apps/workbench/app/models/job.rb
apps/workbench/app/models/pipeline_instance.rb
apps/workbench/app/views/application/_arvados_object.html.erb
apps/workbench/app/views/application/_arvados_object_attr.html.erb
apps/workbench/app/views/authorized_keys/_form.html.erb [new file with mode: 0644]
apps/workbench/app/views/authorized_keys/edit.html.erb [new file with mode: 0644]
apps/workbench/app/views/authorized_keys/index.html.erb
apps/workbench/app/views/authorized_keys/new.html.erb [new file with mode: 0644]
apps/workbench/app/views/authorized_keys/show.html.erb [new file with mode: 0644]

index 619c4b52a754b53d1b26578050ff81caeff37454..f66f968d65e83ce2e590c125546c7d9ca5ad1fa0 100644 (file)
@@ -65,6 +65,24 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  def new
+    @object = model_class.new
+  end
+
+  def update
+    if @object.update_attributes params[@object.class.to_s.underscore.singularize.to_sym]
+      show
+    else
+      self.render_error status: 422
+    end
+  end
+
+  def create
+    @object = model_class.new params[model_class.to_s.singularize.to_sym]
+    @object.save!
+    redirect_to @object
+  end
+
   def current_user
     if Thread.current[:arvados_api_token]
       @current_user ||= User.current
@@ -121,6 +139,8 @@ class ApplicationController < ActionController::Base
         rescue ArvadosApiClient::NotLoggedInException
           try_redirect_to_login = true
         end
+      else
+        logger.debug "session is #{session.inspect}"
       end
       if try_redirect_to_login
         respond_to do |f|
index e6d10f0eeb7cba2fe03cfa980684bcb11872aa35..268b7b9a8c570ba6c47350d3c645c20c0988b03f 100644 (file)
@@ -187,6 +187,22 @@ class ArvadosBase < ActiveRecord::Base
     }
   end
 
+  def editable?
+    (current_user and
+     (current_user.is_admin or
+      current_user.uuid == self.owner))
+  end
+
+  def attribute_editable?(attr)
+    if "created_at modified_at modified_by_user modified_by_client updated_at".index(attr.to_s)
+      false
+    elsif "uuid owner".index(attr.to_s)
+      current_user and current_user.is_admin
+    else
+      true
+    end
+  end
+
   def self.resource_class_for_uuid(uuid, opts={})
     if uuid.is_a? ArvadosBase
       return uuid.class
@@ -223,4 +239,8 @@ class ArvadosBase < ActiveRecord::Base
     @etag = nil
     self
   end
+
+  def current_user
+    Thread.current[:user]
+  end
 end
index a56021682cbc953ff145d23acbbef664cf59060c..62ee83238dae697bfaa72b71d3994d3077b86fde 100644 (file)
@@ -1,2 +1,9 @@
 class AuthorizedKey < ArvadosBase
+  def attribute_editable?(attr)
+    if attr.to_s == 'authorized_user'
+      current_user and current_user.is_admin
+    else
+      super(attr)
+    end
+  end
 end
index d96146143df0c1eaf7eb8ba01178dd1e8bb458fc..cfbb6405041a41f5efb0de50f11ab6dbbf179835 100644 (file)
@@ -8,4 +8,8 @@ class Collection < ArvadosBase
       tot
     end
   end
+
+  def attribute_editable?(attr)
+    false
+  end
 end
index e716df75f9105bcecfeb61618465343e33d73019..f88834e0c3f102ca1219fd68e6d655bd0352faa7 100644 (file)
@@ -1,2 +1,5 @@
 class Job < ArvadosBase
+  def attribute_editable?(attr)
+    false
+  end
 end
index b8c74dfa57ce739cd9014eb57d139d0a4a1404d3..81cd42bf4693d29d78119a50007a884750d745fc 100644 (file)
@@ -16,4 +16,8 @@ class PipelineInstance < ArvadosBase
       end
     end
   end
+
+  def attribute_editable?(attr)
+    attr == 'name'
+  end
 end
index 77d236efb986d309757a15b15967c7ec8d70fc34..b170ba7fad2ef6b4b6ffb62ad3d10b21ee5022ac 100644 (file)
@@ -1,3 +1,4 @@
+<%= form_for @object do |f| %>
 <table class="table topalign">
   <thead>
   </thead>
@@ -7,6 +8,8 @@
     <% end %>
   </tbody>
 </table>
+<% end %>
+
 <pre>
 <%= JSON.pretty_generate(@object.attributes) rescue nil %>
 </pre>
index cb296c58de9b3a399f2f3ef9dbfafeeff8089933..7a5d60df6581a809344db897841474149b6449f9 100644 (file)
@@ -19,6 +19,8 @@
   <td><%= attr %></td>
   <% if attr == 'uuid' and (uuid = attrvalue.split('-')).size == 3 %>
   <td><%= uuid[0..-2].join('-') %>-<b><%= uuid[-1] %></b></td>
+  <% elsif @object.attribute_editable?(attr) %>
+  <td><%= link_to "#{attrvalue}", '#', { "data-type" => "text", "data-resource" => @object.class.to_s.singularize.underscore, "data-name" => attr, "data-url" => url_for(action: "update", id: @object.uuid), "data-original-title" => "Enter #{attr}", :class => "editable" } %></td>
   <% else %>
   <td><%= link_to_if_arvados_object attrvalue, {referring_attr: attr, referring_object: @object, with_prefixes: true, with_class_name: true} %></td>
   <% end %>
diff --git a/apps/workbench/app/views/authorized_keys/_form.html.erb b/apps/workbench/app/views/authorized_keys/_form.html.erb
new file mode 100644 (file)
index 0000000..5a7231d
--- /dev/null
@@ -0,0 +1,31 @@
+<%= form_for @object do |f| %>
+<table class="table">
+  <tr>
+    <td>
+      name
+    </td><td>
+      <%= f.text_field :name %>
+    </td>
+  </tr>
+  <tr>
+    <td>
+      authorized user
+    </td><td>
+      <%= f.text_field :authorized_user %>
+    </td>
+  </tr>
+  <tr>
+    <td>
+      public key
+    </td><td>
+      <%= f.text_area :public_key %>
+    </td>
+  </tr>
+  <tr>
+    <td></td>
+    <td>
+      <%= f.submit class: 'btn btn-primary' %>
+    </td>
+  </tr>
+</table>
+<% end %>
diff --git a/apps/workbench/app/views/authorized_keys/edit.html.erb b/apps/workbench/app/views/authorized_keys/edit.html.erb
new file mode 100644 (file)
index 0000000..23997ae
--- /dev/null
@@ -0,0 +1 @@
+<%= render partial: 'form' %>
index a02ebc3d1b86320a5f371e43ae0d3d5cb081dc89..4658af851ee989fb3e7bbbd204a0ddb4b2c13a94 100644 (file)
@@ -18,7 +18,7 @@
   </thead>
   <tbody>
 
-    <% @objects.sort_by { |ak| ak[:created_at] }.reverse.each do |g| %>
+    <% @objects.sort_by { |ak| ak[:created_at] }.reverse.each do |ak| %>
 
     <tr>
       <td>
diff --git a/apps/workbench/app/views/authorized_keys/new.html.erb b/apps/workbench/app/views/authorized_keys/new.html.erb
new file mode 100644 (file)
index 0000000..23997ae
--- /dev/null
@@ -0,0 +1 @@
+<%= render partial: 'form' %>
diff --git a/apps/workbench/app/views/authorized_keys/show.html.erb b/apps/workbench/app/views/authorized_keys/show.html.erb
new file mode 100644 (file)
index 0000000..9079085
--- /dev/null
@@ -0,0 +1 @@
+<%= render :partial => 'application/arvados_object' %>