brogrammers / eventhub-api

Eventhub API
1 stars 0 forks source link

Group membership and pending membership management #36

Open tsov opened 11 years ago

tsov commented 11 years ago

straight to the point:

we need...

1. two nested resources inside the groups resource

resources :groups do
  resources :members, :controller => 'group_members' # GroupMembersController
  resources :invited, :controller => 'pending_members' # PendingMembersController
end

2. two controllers

# app/controllers/group_members_controller.rb

module Api
  module V1
    class GroupMembersController < BaseController

      def index
        # GET /groups/:id/members
        #
        # Shows all the current members of this group
      end

      def create
        # POST /groups/:id/members
        #
        # Creates a new member for this group
        # IF this user is a pending member of this group
      end

      def destroy
        # DELETE /groups/:id/members
        #
        # Deletes a member from this group
      end

    end
  end
end
# app/controllers/pending_members_controller.rb

module Api
  module V1
    class PendingMembersController < BaseController

      def index
        # GET /groups/:id/invited
        #
        # Shows all the invited users of this group
      end

      def create
        # POST /groups/:id/invited
        #
        # Invites a user to this group
        # IF the currently logged in user is a member of this group
        # AND the invited user is NOT already a pending member OR current member of this group
      end

      def destroy
        # DELETE /groups/:id/members
        #
        # Deletes the invitations
      end

    end
  end
end
tsov commented 11 years ago

update! I just edited the issue

foFox commented 11 years ago

About that

  def create
    # POST /groups/:id/members
    #
    # Creates a new member for this group
    # IF this user is a pending member of this group
  end

I think this creates sort of a feeling that you can create a member directly. where this is not true. You can only invite someone, and that someone, can accept the invitation.

I think if we go ahead and say that to accept the invitation, you go to PUT /groups/:id/invited and send accepted=true / accepted=false this will be better. Then a the user moved form invited to members or deleted from invited. I think it's bit more concise with what's actually going on. What do you think ?

We can make it so you can delete the invitation, with the delete, if it's been sent already but user hasn't got a change to accept it.

tsov commented 11 years ago

Ok sounds like a good idea too, but the idea was that in the end you are creating the resource GroupMember Otherwise we would create a GroupMember resource in the PendingMember resource. Do you know what I mean? I am not objecting your idea, but I am also not very sure which way to go.

foFox commented 11 years ago

But you are not really creating group member per say, as you do not have power to do so. A group member is an outcome of you creating invitation and invited person accepting it. That is my way of thinking about it. My intuition is that POST group/:id/members is not proper as you are not creating it. No one can go and actually make a group member. You must invite someone, and that person must accept invitation. There isn't a situation where you can actually just go ahead and create member. I think doing it that way is a bit confusing, where as just accepting membership, with PUT group/:id/invited?accepted=true is more clear. But that's just my idea.

tsov commented 11 years ago

https://github.com/brogrammers/eventhub-api/pull/34

tsov commented 11 years ago

https://redmine.eventhub.com/issues/19