myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3477] trunk: Removed key_type from oauth


From: noreply
Subject: [myexperiment-hackers] [3477] trunk: Removed key_type from oauth
Date: Fri, 8 Mar 2013 12:36:39 +0000 (UTC)

Revision
3477
Author
fbacall
Date
2013-03-08 12:36:39 +0000 (Fri, 08 Mar 2013)

Log Message

Removed key_type from oauth

Modified Paths

Diff

Modified: trunk/app/controllers/oauth_controller.rb (3476 => 3477)


--- trunk/app/controllers/oauth_controller.rb	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/app/controllers/oauth_controller.rb	2013-03-08 12:36:39 UTC (rev 3477)
@@ -41,38 +41,30 @@
     end
     @address@hidden
     redirect_url=params[:oauth_callback]||@token.client_application.callback_url
-    if (@token.client_application.key_type == 'System') || @client_applications.include?(@token.client_application)
-      unless @token.invalidated?
-        if request.post?
-          if params[:authorize]=='1'
-            @token.authorize!(current_user)
-            if redirect_url
-              redirect_to redirect_url+"address@hidden"
-            else
-              render :action=""
-            end
-          elsif params[:commit]=="Save Changes"
-            @token.invalidate!
-            if redirect_url
-              redirect_to redirect_url+"?oauth_failure=1"
-            else
-              render :action=""
-            end
+    unless @token.invalidated?
+      if request.post?
+        if params[:authorize]=='1'
+          @token.authorize!(current_user)
+          if redirect_url
+            redirect_to redirect_url+"address@hidden"
+          else
+            render :action=""
           end
+        elsif params[:commit]=="Save Changes"
+          @token.invalidate!
+          if redirect_url
+            redirect_to redirect_url+"?oauth_failure=1"
+          else
+            render :action=""
+          end
         end
-      else
-       if redirect_url
-         redirect_to redirect_url+"?oauth_failure=1"
-       else
-         render :action=""
-       end
       end
     else
-       if redirect_url
-         redirect_to redirect_url+"?oauth_failure=1"
-       else
-         render :action=""
-       end
+     if redirect_url
+       redirect_to redirect_url+"?oauth_failure=1"
+     else
+       render :action=""
+     end
     end
   end
 
@@ -87,7 +79,6 @@
 
   def index
     @client_applications=current_user.client_applications
-    @admin_client_applications=ClientApplication.find(:all, :conditions => ["user_id != ? and creator_id = ?", current_user.id, current_user.id])
     @tokens=current_user.tokens.find :all, :conditions=>'oauth_tokens.invalidated_at is null and oauth_tokens.authorized_at is not null'
   end
 
@@ -118,18 +109,12 @@
   end
 
   def show
-    if (!(@client_application.user_id == current_user.id or @client_application.creator_id == current_user.id))
-      @client_application = nil
-    end
     @address@hidden
   end
 
   def edit
     @permissions = TABLES['REST'][:data]
     @address@hidden
-    if (!(@client_application.user_id == current_user.id or @client_application.creator_id == current_user.id))
-        @client_application = nil
-    end
     @address@hidden
     unless @client_application.nil?
       @address@hidden
@@ -137,13 +122,11 @@
   end
 
   def update
-    if (current_user.admin? or @client_application.key_type=="User")
-      @client_application.permissions.delete_all
-      if params[:key_permissions] 
-        for key_permission in params[:key_permissions] do
-          @key_permission = KeyPermission.new(:client_application_id => @client_application.id, :for ="" key_permission[0])
-           @key_permission.save
-        end
+    @client_application.permissions.delete_all
+    if params[:key_permissions]
+      for key_permission in params[:key_permissions] do
+        @key_permission = KeyPermission.new(:client_application_id => @client_application.id, :for ="" key_permission[0])
+         @key_permission.save
       end
     end
     if @client_application.update_attributes(params[:client_application])
@@ -171,7 +154,8 @@
       "index"         => "view",
       "request_token" => "view",
       "test_request"  => "view",
-      "show"          => "view"
+      "show"          => "view",
+      "update"        => "edit"
     }
 
     if action_name == 'update'
@@ -184,10 +168,10 @@
       if Authorization.check(action_permissions[action_name] || action_name, client_app, current_user)
         @client_application = client_app
       else
-        error("Client Application not found (id not authorized)", "is invalid (not authorized)")
+        render_401
       end
     rescue ActiveRecord::RecordNotFound
-      error("Client Application not found", "is invalid")
+      render_404("Client Application not found")
     end
   end
 

Modified: trunk/app/models/client_application.rb (3476 => 3477)


--- trunk/app/models/client_application.rb	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/app/models/client_application.rb	2013-03-08 12:36:39 UTC (rev 3477)
@@ -6,9 +6,6 @@
            :class_name => "KeyPermission",
            :order => "key_permissions.for",
            :dependent => :destroy
-  belongs_to :creator,
-             :class_name => "User",
-	     :foreign_key => "creator_id"
   validates_presence_of :name,:url,:key,:secret
   validates_uniqueness_of :key
   before_validation_on_create :generate_keys

Modified: trunk/app/views/oauth/_form.rhtml (3476 => 3477)


--- trunk/app/views/oauth/_form.rhtml	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/app/views/oauth/_form.rhtml	2013-03-08 12:36:39 UTC (rev 3477)
@@ -1,54 +1,17 @@
 <div class="field">
-	<label for=""
-	<%=f.text_field :name %>
+  <label for=""
+  <%=f.text_field :name %>
 </div>
 <div class="field">
-        <% if current_user.admin? %>
-          <label for=""
-	  <% unless @client_application.id %>  
-	    <%= select_tag "client_application[key_type]", options_for_select([ "User", "System"], "User") %>
-	  <% else %>
-	    <%= select_tag "client_application[key_type]", options_for_select([ "User", "System"], @client_application.key_type) %>
-	  <% end %>
+  <label for="" Application URL*</label><br/>
+  <%=f.text_field :url%>
 </div>
 <div class="field">
-	  <label for="" User*</label><br/>
-          <% unless @client_application.id %>
-            <select id="client_application[user_id]" name="client_application[user_id]" %>
-              <% all_users().each do |u| %>
-	        <option <%= 'selected="selected"' if u.id==current_user.id %> value="<%= u.id %>"><%= h(u.name) %></option><% end %>
-            </select>
-          <% else %>
-            <select id="client_application[user_id]" name="client_application[user_id]">
-              <% all_users().each do |u| %>
-	         <option <%= 'selected="selected"' if address@hidden %> value="<%= u.id %>"><%= h(u.name) %></option><% end %>
-            </select>
-	  <% end %>
-	<% else %>
-          <%= f.hidden_field :user_id, :value => current_user.id %>
-	  <% unless @client_application.id %>
-	    <%= f.hidden_field :key_type, :value => "User" %>
-	  <% else %>
-	     <%= f.hidden_field :key_type, :value => @client_application.key_type %>
-	  <% end %>
-	<% end %>
-	<% unless @client_application.id %>
-	  <%= f.hidden_field :creator_id, :value => current_user.id %>
-	<% else %>
-	  <%= f.hidden_field :creator_id, :value => @client_application.creator_id %>
-	<% end %>
-
+  <label for="" URL*</label><br/>
+  <%=f.text_field :callback_url%>
 </div>
 <div class="field">
-	<label for="" Application URL*</label><br/>
-	<%=f.text_field :url%>
+  <label for="" URL</label><br/>
+  <%=f.text_field :support_url%>
 </div>
-<div class="field">
-	<label for="" URL*</label><br/>
-	<%=f.text_field :callback_url%>
-</div>
-<div class="field">
-	<label for="" URL</label><br/>
-	<%=f.text_field :support_url%>
-</div>
 

Modified: trunk/app/views/oauth/_permissions.rhtml (3476 => 3477)


--- trunk/app/views/oauth/_permissions.rhtml	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/app/views/oauth/_permissions.rhtml	2013-03-08 12:36:39 UTC (rev 3477)
@@ -1,5 +1,4 @@
 <h2>Permissions</h2>
-<% checkboxes=[] %>
 <% permissions_categorised=permissions_categorised(@permissions) %>
 <% for category,permissions in permissions_categorised %>
   <h3><%= category.capitalize %></h3>
@@ -8,34 +7,16 @@
     <% for type,data in permission -%>
       <% key=data['URI'] -%>
       <% key_type = "#{type} #{key}" -%>
-      <% if (@permissions_for.include?(key_type)) %>
-        <%=check_box_tag "key_permissions[#{type} #{key}]", 1,  true %> <%= type %> <%= key %>
-      <% else %>
-        <%=check_box_tag "key_permissions[#{type} #{key}]" %> <%= type %> <%= key %>
-      <% end -%>
-      <% checkboxes.push("key_permissions[#{type} #{key}]"); %>
-      &nbsp;&nbsp;&nbsp;&nbsp;
+      <% checked = @permissions_for.include?(key_type) %>
+      <%= check_box_tag "key_permissions[#{type} #{key}]", 1,  checked, :class => "permission" %> <%= type %> <%= key %>
     <% end %>
   <% end -%>
   </p>
 <% end %>
 <br/>
 <p style="text-align:center;" >
-  <input type="button" name="check_all" value="Check All"  checkboxes = new Array();
-  <% i = 0 -%> 
-  <% for c in checkboxes %>
-      <%= "checkboxes[#{i}]='#{c}';" -%>
-      <% i=i+1 -%>
-  <% end -%>
-  checkAll(checkboxes);" />
-  &nbsp;&nbsp;&nbsp;&nbsp;
-  <input type="button" name="uncheck_all" value="Uncheck All"  checkboxes = new Array();
-  <% i = 0 -%>
-  <% for c in checkboxes %>
-      <%= "checkboxes[#{i}]='#{c}';" -%>
-      <% i=i+1 -%>
-  <% end -%>
-  uncheckAll(checkboxes);" />
+  <input type="button" name="check_all" value="Check All"  (e) { e.checked = true });"/>
+  <input type="button" name="uncheck_all" value="Uncheck All"  (e) { e.checked = false });"/>
 </p>
 
 

Modified: trunk/app/views/oauth/edit.rhtml (3476 => 3477)


--- trunk/app/views/oauth/edit.rhtml	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/app/views/oauth/edit.rhtml	2013-03-08 12:36:39 UTC (rev 3477)
@@ -1,17 +1,13 @@
 <h1>Edit OAuth details for <address@hidden></h1>
 
-<% form_for :client_application, :url ="" { :action ="" :update } do |f| %>
-       <%= f.hidden_field :id %>
-       <%= render :partial => "form", :locals => { :f => f } %>
-       <% if (@client_application.nil? or current_user.admin?) %>
-         <%= render :partial => "permissions", :locals => { :f => f } %>
-       <% else %>
-         <% if (@client_application.key_type=="User") %>
-	   <%= render :partial => "permissions", :locals => { :f => f } %>
-         <% else %>
-	   <%= render :partial => "show_permissions"  %>
-         <% end %>
-       <% end %>
- <br/><br/>        
+<% form_for @client_application, :url ="" { :action ="" "update", :controller => "oauth" }, :method => :put do |f| %>
+
+  <%= f.hidden_field :id %>
+
+  <%= render :partial => "form", :locals => { :f => f } %>
+
+  <%= render :partial => "permissions", :locals => { :f => f } %>
+
+ <br/><br/>
  <p style="text-align: center; font-weight: bold;"><%= submit_tag "Update" %></p>
 <% end %>

Modified: trunk/app/views/oauth/index.rhtml (3476 => 3477)


--- trunk/app/views/oauth/index.rhtml	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/app/views/oauth/index.rhtml	2013-03-08 12:36:39 UTC (rev 3477)
@@ -31,16 +31,6 @@
 		<div><%=link_to client.name,:action=""
 	<%end%>
 <%end%>
-<% if current_user.admin? %>
-<h3>Client Applications You Have Created For Other Users</h3>
-<% if @admin_client_applications.empty? %>
-	<p>You do not currently have any client applications that you have created or other users.</p>
-<%else%>
-	<address@hidden do |client|%>
-                <div><%=link_to client.name,:action=""
-        <%end%>
-<% end %>
-<% end %>
 <ul class="sectionIcons">
 	<li><%= icon "register_application", {:controller =>'oauth',:action="" nil, nil, "Register Client Application" %></li>
 </ul>

Modified: trunk/app/views/oauth/show.rhtml (3476 => 3477)


--- trunk/app/views/oauth/show.rhtml	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/app/views/oauth/show.rhtml	2013-03-08 12:36:39 UTC (rev 3477)
@@ -6,9 +6,6 @@
 <p>
         <b>Main Application URL:</b> <address@hidden>
 </p>
-<p>
-	<b>Key Type:</b> <address@hidden>
-</p>
 <% if current_user.admin? %>
 <p>
 	<b>For User:</b> <a href="" user_path(@client_application.user.id) %>"><address@hidden></a>

Modified: trunk/config/routes.rb (3476 => 3477)


--- trunk/config/routes.rb	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/config/routes.rb	2013-03-08 12:36:39 UTC (rev 3477)
@@ -162,11 +162,11 @@
   map.resources :messages, :collection => { :sent => :get, :delete_all_selected => :delete }
 
   # all oauth
-  map.resources :oauth
   map.authorize '/oauth/authorize',:controller=>'oauth',:action=""
   map.request_token '/oauth/request_token',:controller=>'oauth',:action=""
   map.access_token '/oauth/access_token',:controller=>'oauth',:action=""
   map.test_request '/oauth/test_request',:controller=>'oauth',:action=""
+  map.resources :oauth
 
   # User timeline
   map.connect 'users/timeline', :controller => 'users', :action ="" 'timeline'

Modified: trunk/db/schema.rb (3476 => 3477)


--- trunk/db/schema.rb	2013-03-08 10:11:25 UTC (rev 3476)
+++ trunk/db/schema.rb	2013-03-08 12:36:39 UTC (rev 3477)
@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130304123620) do
+ActiveRecord::Schema.define(:version => 20130308085716) do
 
   create_table "activity_limits", :force => true do |t|
     t.string   "contributor_type", :null => false
@@ -108,10 +108,8 @@
     t.string   "key",          :limit => 50
     t.string   "secret",       :limit => 50
     t.integer  "user_id"
-    t.string   "key_type"
     t.datetime "created_at"
     t.datetime "updated_at"
-    t.integer  "creator_id"
   end
 
   add_index "client_applications", ["key"], :name => "index_client_applications_on_key", :unique => true

reply via email to

[Prev in Thread] Current Thread [Next in Thread]