Skip to content

Conversation

@snewcomer
Copy link
Contributor

@snewcomer snewcomer commented Dec 19, 2017

Fixes #1308

# conversation
# |> where(user_id: ^id)
# |> or_where([c], c.message_id in ^scoped_message_ids)
true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshsmith what are the rules here when updating a conversations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I think it should be updated really only by someone who's an admin or the message's project is administered by a user.

The read_at in a conversation is going to be set by an update to the conversation_part, so it won't happen explicitly. The only explicit update to a conversation should be the status, which should be admin-only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lmk what you think! updated everything.

@snewcomer
Copy link
Contributor Author

Actually not sure why my commits were changed but tons of merge conflicts

@joshsmith
Copy link
Contributor

@snewcomer I had rebased for you. Sorry about that. Was trying to be helpful but was not.

@snewcomer
Copy link
Contributor Author

@joshsmith ah no worries! I thought I did something. Does this need tracking? Not totally sure what the strategy as it relates to tracking....

@joshsmith
Copy link
Contributor

We can circle back to figure out the tracking/analytics side of this later. I haven't really formed a coherent strategy around it yet for this feature set.

Copy link
Contributor

@joshsmith joshsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was unclear about the policy earlier. My more detailed notes here should help.

with %Conversation{} = conversation <- Messages.get_conversation(id) |> preload(),
%User{} = current_user <- conn |> CodeCorps.Guardian.Plug.current_resource,
{:ok, :authorized} <- current_user |> Policy.authorize(:update, conversation),
{:ok, %Conversation{} = updated_conversation} <- conversation |> Conversation.update_changeset(params) |> Repo.update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make use of the context here, so instead use Messages.update_conversation(conversation, params).

def show?(_, _), do: false

def update?(%User{admin: true}, _conversation), do: true
def update?(_, _), do: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs the following clause:

def update(%User{} = user, %Conversation{} = conversation) do
  conversation |> get_message() |> get_project() |> administered_by?(user)
end

conversation = insert(:conversation, message: message, user: user)

refute update?(user, conversation)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need tests added like in the show? tests above once the policy is updated per the above comment.

@tag authenticated: :admin
test "updates and renders chosen resource when data is valid", %{conn: conn, current_user: current_user} do
message = insert(:message)
conversation = insert(:conversation, user: current_user, message: message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will need modified using logic similar to the index's conversation_on_user_administered_project when the policy is changed, rather than relying on admin here.

@joshsmith joshsmith added this to the ✉️ Messages milestone Dec 20, 2017
@snewcomer
Copy link
Contributor Author

@joshsmith fixed! Thanks for reviewing it all!


def update_conversation(conversation, params) do
Conversation.update_changeset(conversation, params) |> Repo.update
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style thing but I would consider leading with the pipe, so conversation |> Conversation.update_changeset...

message_on_user_administered_project = insert(:message, project: project)
conversation_on_user_administered_project =
insert(:conversation, message: message_on_user_administered_project)
assert conn |> request_update(conversation_on_user_administered_project, %{status: "wat"}) |> json_response(422)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're doing a 422 assert in here. This line probably needs removed.

@joshsmith joshsmith merged commit faa4353 into develop Dec 20, 2017
@joshsmith joshsmith deleted the update-conversation branch December 20, 2017 05:17
@joshsmith
Copy link
Contributor

🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants