myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2097] trunk: removed network relationships


From: noreply
Subject: [myexperiment-hackers] [2097] trunk: removed network relationships
Date: Thu, 12 Feb 2009 16:30:38 -0500 (EST)

Revision
2097
Author
dgc
Date
2009-02-12 16:30:38 -0500 (Thu, 12 Feb 2009)

Log Message

removed network relationships

Modified Paths

Removed Paths

Diff

Deleted: trunk/app/controllers/relationships_controller.rb (2096 => 2097)


--- trunk/app/controllers/relationships_controller.rb	2009-02-12 21:27:36 UTC (rev 2096)
+++ trunk/app/controllers/relationships_controller.rb	2009-02-12 21:30:38 UTC (rev 2097)
@@ -1,178 +0,0 @@
-# myExperiment: app/controllers/relationships_controller.rb
-#
-# Copyright (c) 2007 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-class RelationshipsController < ApplicationController
-  before_filter :login_required, :except => [:index, :show]
-  
-  before_filter :find_relationships, : [:index]
-  before_filter :find_relationship, : [:show]
-  before_filter :find_relationship_auth, : [:accept, :edit, :update, :destroy]
-  
-  # GET /networks/1/relationships/1;accept
-  # GET /relationships/1;accept
-  def accept
-    respond_to do |format|
-      if @relationship.accept!
-        flash[:notice] = 'Relationship was successfully accepted.'
-        format.html { redirect_to relationships_url(@relationship.network_id) }
-      else
-        error("Relationship already accepted", "already accepted")
-      end
-    end
-  end
-  
-  # GET /networks/1/relationships
-  # GET /relationships
-  def index
-    respond_to do |format|
-      format.html # index.rhtml
-    end
-  end
-
-  # GET /networks/1/relationships/1
-  # GET /relationships/1
-  def show
-    respond_to do |format|
-      format.html # show.rhtml
-    end
-  end
-
-  # GET /networks/1/relationships/new
-  # GET /relationships/new
-  def new
-    if params[:network_id]
-      @relationship = Relationship.new(:network_id => params[:network_id])
-    else
-      @relationship = Relationship.new
-    end
-    
-    # only allow relation_id to be in @owned_networks
-    @networks_owned = current_user.networks_owned
-  end
-
-  # GET /networks/1/relationships/1;edit
-  # GET /relationships/1;edit
-  def edit
-    
-  end
-
-  # POST /networks/1/relationships
-  # POST /relationships
-  def create
-    if (@relationship = Relationship.new(params[:relationship]) unless Relationship.find_by_network_id_and_relation_id(params[:relationship][:network_id], params[:relationship][:relation_id]))
-      # set initial datetime
-      @relationship.accepted_at = nil
-      
-      # current_user must be the owner of Network.find(relation_id)
-      @relationship.errors.add :relation_id, "not authorized (not owned)" unless current_user.networks_owned.include? Network.find(params[:relationship][:network_id])
-
-      respond_to do |format|
-        if @relationship.save
-          flash[:notice] = 'Relationship was successfully created.'
-          format.html { redirect_to relationship_url(@relationship.network_id, @relationship) }
-        else
-          format.html { render :action ="" "new" }
-        end
-      end
-    else
-      error("Relationship not created (already exists)", "not created, already exists")
-    end
-  end
-
-  # PUT /networks/1/relationships/1
-  # PUT /relationships/1
-  def update
-    # no spoofing of acceptance
-    params[:relationship].delete('accepted_at') if params[:relationship][:accepted_at]
-    
-    respond_to do |format|
-      if @relationship.update_attributes(params[:relationship])
-        flash[:notice] = 'Relationship was successfully updated.'
-        format.html { redirect_to relationship_url(@relationship.network_id, @relationship) }
-      else
-        format.html { render :action ="" "edit" }
-      end
-    end
-  end
-
-  # DELETE /networks/1/relationships/1
-  # DELETE /relationships/1
-  def destroy
-    network_id = @relationship.network_id
-    
-    @relationship.destroy
-
-    respond_to do |format|
-      format.html { redirect_to relationships_url(network_id) }
-    end
-  end
-  
-protected
-
-  def find_relationships
-    if params[:network_id]
-      begin
-        n = Network.find(params[:network_id])
-      
-        @relationships = n.relationships
-      rescue ActiveRecord::RecordNotFound
-        error("Network not found", "is invalid", :network_id)
-      end
-    else
-      @relationships = Relationship.find(:all, :order => "created_at DESC")
-    end
-  end
-
-  def find_relationship
-    if params[:network_id]
-      begin
-        n = Network.find(params[:network_id])
-    
-        begin
-          @relationship = Relationship.find(params[:id], :conditions => ["network_id = ?", n.id])
-        rescue ActiveRecord::RecordNotFound
-          error("Relationship not found", "is invalid")
-        end
-      rescue ActiveRecord::RecordNotFound
-        error("Network not found", "is invalid", :network_id)
-      end
-    else
-      begin
-        @relationship = Relationship.find(params[:id])
-      rescue ActiveRecord::RecordNotFound
-        error("Relationship not found", "is invalid")
-      end
-    end
-  end
-  
-  def find_relationship_auth
-    if params[:network_id]
-      begin
-        relationship = Relationship.find(params[:id])
-      
-        if Network.find(relationship.network_id).owner? current_user.id
-          @relationship = relationship
-        else
-          error("Relationship not found (id not authorized)", "is invalid (not owner)", :network_id)
-        end
-      rescue ActiveRecord::RecordNotFound
-        error("Relationship not found", "is invalid")
-      end
-    else
-      error("Relationship not found (id not authorized)", "is invalid (not owner)")
-    end
-  end
-
-private
-
-  def error(notice, message, attr=:id)
-    flash[:error] = notice
-    (err = Relationship.new.errors).add(attr, message)
-    
-    respond_to do |format|
-      format.html { redirect_to relationships_url(params[:network_id]) }
-    end
-  end
-end

Deleted: trunk/app/helpers/relationships_helper.rb (2096 => 2097)


--- trunk/app/helpers/relationships_helper.rb	2009-02-12 21:27:36 UTC (rev 2096)
+++ trunk/app/helpers/relationships_helper.rb	2009-02-12 21:30:38 UTC (rev 2097)
@@ -1,7 +0,0 @@
-# myExperiment: app/helpers/relationships_helper.rb
-#
-# Copyright (c) 2007 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-module RelationshipsHelper
-end

Modified: trunk/app/models/network.rb (2096 => 2097)


--- trunk/app/models/network.rb	2009-02-12 21:27:36 UTC (rev 2096)
+++ trunk/app/models/network.rb	2009-02-12 21:30:38 UTC (rev 2097)
@@ -56,79 +56,7 @@
   def owner_name
     owner.name
   end
-  
-#  has_many :relationships_completed, #accepted (by others)
-#           :class_name => "Relationship",
-#           :foreign_key => :network_id,
-#           :conditions => ["accepted_at < ?", Time.now],
-#           :order => "created_at DESC",
-#           :dependent => :destroy
-#           
-#  has_many :relationships_requested, #unaccepted (by others)
-#           :class_name => "Relationship",
-#           :foreign_key => :network_id,
-#           :conditions => "accepted_at IS NULL",
-#           :order => "created_at DESC",
-#           :dependent => :destroy
-#           
-#  has_many :relationships_accepted, #accepted (by me)
-#           :class_name => "Relationship",
-#           :foreign_key => :relation_id,
-#           :conditions => ["accepted_at < ?", Time.now],
-#           :order => "accepted_at DESC",
-#           :dependent => :destroy
-#           
-#  has_many :relationships_pending, #unaccepted (by me)
-#           :class_name => "Relationship",
-#           :foreign_key => :relation_id,
-#           :conditions => "accepted_at IS NULL",
-#           :order => "created_at DESC",
-#           :dependent => :destroy
-#
-#  def relationships
-#    (relationships_completed + relationships_requested + relationships_accepted + relationships_pending).sort do |a, b|
-#      b.created_at <=> a.created_at
-#    end
-#  end
-  
-  has_and_belongs_to_many :relations,
-                          :class_name => "Network",
-                          :join_table => :relationships,
-                          :foreign_key => :network_id,
-                          :association_foreign_key => :relation_id,
-                          :conditions => "accepted_at IS NOT NULL",
-                          :order => "accepted_at DESC"
                           
-  alias_method :original_relations, :relations
-  def relations
-    rtn = []
-    
-    original_relations.each do |r|
-      rtn << Network.find(r.relation_id)
-    end
-    
-    return rtn
-  end
-  
-#  has_and_belongs_to_many :parents,
-#                          :class_name => "Network",
-#                          :join_table => :relationships,
-#                          :foreign_key => :relation_id,
-#                          :association_foreign_key => :network_id,
-#                          :conditions => ["accepted_at < ?", Time.now],
-#                          :order => "accepted_at DESC"
-#                          
-#  alias_method :original_parents, :parents
-#  def parents
-#    rtn = []
-#    
-#    original_parents.each do |r|
-#      rtn << Network.find(r.network_id)
-#    end
-    
-#    return rtn
-#  end
-
   # announcements belonging to the group;
   #
   # "announcements_public" are just the public announcements;
@@ -210,50 +138,6 @@
     return false
   end
   
-  def member_recursive?(userid)
-    member_r? userid
-  end
-  
-  # alias for member_recursive?
-  def member!(userid)
-    member_r? userid
-  end
-  
-  def relation?(network_id)
-    relations.each do |r|
-      return true if r.id.to_i == network_id.to_i
-    end
-    
-    false
-  end
-  
-  def relation_recursive?(network_id)
-    relation_r? network_id
-  end
-  
-  # alias for relation_recursive?
-  def relation!(userid)
-    relation_r? userid
-  end
-  
-  def members_recursive
-    members_r
-  end
-  
-  # alias for members_recursive
-  def members!
-    members_r
-  end
-  
-  def relations_recursive
-    relations_r
-  end
-  
-  # alias for relations_recursive
-  def relations!
-    relations_r
-  end
-  
   # Finds all the contributions that have been explicitly shared via Permissions
   def shared_contributions
     list = []
@@ -272,62 +156,4 @@
     # filter out blogs until they've gone completely
     c.select do |x| x.class != Blog end
   end
-
-protected
-
-  def member_r?(userid, depth=0)
-    unless depth > @@maxdepth
-      return true if member? userid
-    
-      relations.each do |r|
-        return true if r.member_r? userid, depth+1
-      end
-    end
-    
-    false
-  end
-  
-  def relation_r?(network_id, depth=0)
-    unless depth > @@maxdepth
-      return true if relation? network_id
-    
-      relations.each do |r|
-        return true if r.relation_r? network_id, depth+1
-      end
-    end
-    
-    false
-  end
-  
-  def members_r(depth=0)
-    unless depth > @@maxdepth
-      rtn = members
-    
-      relations.each do |r|
-         rtn = (rtn + r.members_r(depth+1))
-      end
-    
-      return rtn.uniq
-    end
-    
-    []
-  end
-  
-  def relations_r(depth=0)
-    unless depth > @@maxdepth
-      rtn = relations
-    
-      relations.each do |r|
-        rtn = (rtn + r.relations_r(depth+1))
-      end
-    
-      return rtn # no need for uniq (there shouldn't be any loops)
-    end
-    
-    []
-  end
-  
-private
-  
-  @@maxdepth = 7 # maximum level of recursion for depth first search
 end

Deleted: trunk/app/models/relationship.rb (2096 => 2097)


--- trunk/app/models/relationship.rb	2009-02-12 21:27:36 UTC (rev 2096)
+++ trunk/app/models/relationship.rb	2009-02-12 21:30:38 UTC (rev 2097)
@@ -1,29 +0,0 @@
-# myExperiment: app/models/relationship.rb
-#
-# Copyright (c) 2007 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-class Relationship < ActiveRecord::Base
-  validates_associated :network, :relation
-  
-  validates_presence_of :network_id, :relation_id
-  
-  belongs_to :network
-  
-  belongs_to :relation,
-             :class_name => "Network",
-             :foreign_key => :relation_id
-             
-  def accept!
-    unless accepted?
-      update_attribute :accepted_at, Time.now
-      return true
-    else
-      return false
-    end
-  end
-
-  def accepted?
-    self.accepted_at != nil
-  end
-end

Modified: trunk/app/models/user.rb (2096 => 2097)


--- trunk/app/models/user.rb	2009-02-12 21:27:36 UTC (rev 2096)
+++ trunk/app/models/user.rb	2009-02-12 21:30:38 UTC (rev 2097)
@@ -475,16 +475,6 @@
     self.networks + self.networks_owned
   end
   
-  def relationships_pending
-    rtn = []
-    
-    networks_owned.each do |n|
-      rtn.concat n.relations_pending
-    end
-    
-    return rtn
-  end
-           
   has_many :messages_sent,
            :class_name => "Message",
            :foreign_key => :from,

Deleted: trunk/test/functional/relationships_controller_test.rb (2096 => 2097)


--- trunk/test/functional/relationships_controller_test.rb	2009-02-12 21:27:36 UTC (rev 2096)
+++ trunk/test/functional/relationships_controller_test.rb	2009-02-12 21:30:38 UTC (rev 2097)
@@ -1,68 +0,0 @@
-# myExperiment: test/functional/relationships_controller_test.rb
-#
-# Copyright (c) 2007 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-require File.dirname(__FILE__) + '/../test_helper'
-require 'relationships_controller'
-
-# Re-raise errors caught by the controller.
-class RelationshipsController; def rescue_action(e) raise e end; end
-
-class RelationshipsControllerTest < Test::Unit::TestCase
-  fixtures :relationships
-
-  def test_truth
-    assert true
-  end
-
-# Commented out as relationships controller not being used, so no point in fixing tests
-#
-#  def setup
-#    @controller = RelationshipsController.new
-#    @request    = ActionController::TestRequest.new
-#    @response   = ActionController::TestResponse.new
-#  end
-#
-#  def test_should_get_index
-#    get :index
-#    assert_response :success
-#    assert assigns(:relationships)
-#  end
-#
-#  def test_should_get_new
-#    get :new
-#    assert_response :success
-#  end
-#  
-#  def test_should_create_relationship
-#    old_count = Relationship.count
-#    post :create, :relationship => { }
-#    assert_equal old_count+1, Relationship.count
-#    
-#    assert_redirected_to relationship_path(assigns(:relationship))
-#  end
-#
-#  def test_should_show_relationship
-#    get :show, :id => 1
-#    assert_response :success
-#  end
-#
-#  def test_should_get_edit
-#    get :edit, :id => 1
-#    assert_response :success
-#  end
-#  
-#  def test_should_update_relationship
-#    put :update, :id => 1, :relationship => { }
-#    assert_redirected_to relationship_path(assigns(:relationship))
-#  end
-#  
-#  def test_should_destroy_relationship
-#    old_count = Relationship.count
-#    delete :destroy, :id => 1
-#    assert_equal old_count-1, Relationship.count
-#    
-#    assert_redirected_to relationships_path
-#  end
-end

reply via email to

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