app/controllers/socials_controller.rb
# Edit a single friendship.
#
# === Params:
#     id: the id of the swimming buddy (user) to be edited.
#
# === GET:
#     Renderes the edit form.
#
# === POST:
#     Update the changes (news feed generated only for new sharings).
#
#     Changing an already "agreed" share (setting to true something that
#     was already set as false) will re-set to ON the pending status of
#     the friendship.
Edit a single friendship.
Params:
id: the id of the swimming buddy (user) to be edited.

Renderes the edit form.

Update the changes (news feed generated only for new sharings).

Changing an already "agreed" share (setting to true something that
was already set as false) will re-set to ON the pending status of
the friendship.
Edit a single friendship . Params : id : the id of the swimming buddy ( user ) to be edited . Renderes the edit form . Update the changes ( news feed generated only for new sharings ) . Changing an already " agreed " share ( setting to true something that was already set as false ) will re - set to ON the pending status of the friendship .
def edit
    unless SwimmerUserStrategy.new(@swimming_buddy.swimmer).is_editable_by( current_user )
      flash[:warning] = I18n.t( 'social.warning_could_not_find_valid_or_pending_friendship' )
        .gsub( "{SWIMMER_NAME}", @swimming_buddy.name )
      redirect_to( socials_show_all_path() ) and return
    end
    @title = I18n.t('social.edit_title')
    @submit_title = I18n.t('social.ok')
    @friendship = current_user.find_any_friendship_with(@swimming_buddy)
    if request.post?                                
      shares_passages  = (params[:shares_passages].to_i > 0)
      shares_trainings = (params[:shares_trainings].to_i > 0)
      shares_calendars = (params[:shares_calendars].to_i > 0)
       In other words, this friendship will be pending only if the "friendable" is actually
       the one making the edit request. If it is the friend who received the original invite
       (thus the one accepting it), it won't matter and the editing will be "plain & simple":
      must_reset_pending_status = (@friendship.friendable_id == current_user.id) &&
                                  (
                                    (!@friendship.shares_passages  && shares_passages) ||
                                    (!@friendship.shares_trainings && shares_trainings) ||
                                    (!@friendship.shares_calendars && shares_calendars)
                                  )
      @friendship.shares_passages  = shares_passages
      @friendship.shares_trainings = shares_trainings
      @friendship.shares_calendars = shares_calendars
      @friendship.pending = true if must_reset_pending_status
      if @friendship.save
        flash[:info] = I18n.t('social.changes_saved')
      else
        flash[:error] = I18n.t('social.edit_error')
      end
      redirect_to( socials_show_all_path() ) and return
    end
  end
def edit unless SwimmerUserStrategy . new ( @swimming_buddy . swimmer ) . is_editable_by ( current_user ) flash [ :warning ] = I18n . t ( 'social.warning_could_not_find_valid_or_pending_friendship' ) . gsub ( "{SWIMMER_NAME}" , @swimming_buddy . name ) redirect_to ( socials_show_all_path ( ) ) and return end @title = I18n . t ( 'social.edit_title' ) @submit_title = I18n . t ( 'social.ok' ) @friendship = current_user . find_any_friendship_with ( @swimming_buddy ) if request . post? shares_passages = ( params [ :shares_passages ] . to_i > 0 ) shares_trainings = ( params [ :shares_trainings ] . to_i > 0 ) shares_calendars = ( params [ :shares_calendars ] . to_i > 0 ) must_reset_pending_status = ( @friendship . friendable_id == current_user . id ) && ( ( ! @friendship . shares_passages && shares_passages ) || ( ! @friendship . shares_trainings && shares_trainings ) || ( ! @friendship . shares_calendars && shares_calendars ) ) @friendship . shares_passages = shares_passages @friendship . shares_trainings = shares_trainings @friendship . shares_calendars = shares_calendars @friendship . pending = true if must_reset_pending_status if @friendship . save flash [ :info ] = I18n . t ( 'social.changes_saved' ) else flash [ :error ] = I18n . t ( 'social.edit_error' ) end redirect_to ( socials_show_all_path ( ) ) and return end end
Edit a single friendship.
Edit a single friendship .
# === GET: (shared assigns with POST) === # === POST: === # If the friendable changes to true some share that is currently set to false for # the friendship, this will issue a new approval request for the friend (by setting the # friendship pending status back to true) # # In other words, this friendship will be pending only if the "friendable" is actually # the one making the edit request. If it is the friend who received the original invite # (thus the one accepting it), it won't matter and the editing will be "plain & simple":