Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user-favorited workspaces in DB and model #165

Merged
merged 1 commit into from
Jun 15, 2021

Conversation

mjgiarlo
Copy link
Member

@mjgiarlo mjgiarlo commented Jun 11, 2021

Connects to #141

TODO:

  • Add tests
  • Attach screencasts/screenshots (no user-facing changes so this seems of little value...)

@@ -14,7 +14,7 @@ def explore
end

def dashboard
@favorites = Workspace.accessible_by(current_ability, :update).favorites.order(updated_at: :desc).limit(3)
@favorites = current_user.favorite_workspaces.order(updated_at: :desc).limit(3)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we be checking if still accessible here? It's possible for a user to fav a workspace they have access to and then lose access to the workspace. 🤷‍♂️

@@ -76,8 +76,36 @@ def destroy
end
end

# POST /workspaces/1/favorite
def favorite
params.permit(:favorite, :id)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is kinda ugly and for some reason (haven't looked into it yet), an unused and unpermitted :workspace param is coming through. not sure why, but we don't use it. rails machinery?

Comment on lines 84 to 88
if params[:favorite]
@workspace.favorited_by << current_user
else
@workspace.favorited_by.delete(current_user)
end
Copy link
Member Author

Choose a reason for hiding this comment

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

Better way to do this?


respond_to do |format|
if @workspace.save
format.html { redirect_to @workspace, notice: favorite_notice(params[:favorite]) }
Copy link
Member Author

Choose a reason for hiding this comment

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

This notice is never seen in practice because all the requests come through as JSON requests.

@@ -34,7 +34,7 @@
<p class="fst-italic">There hasn't been any recent workspace activity in this project.</p>
<% end %>

<% favorites = @project.workspaces.favorites.accessible_by(current_ability) %>
<% favorites = current_user.favorite_workspaces %>
Copy link
Member Author

Choose a reason for hiding this comment

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

Check accessibility again or nah?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is relevant or not, but if a user favorited a workspace that they then lose access to, I think it would be fine to still keep track of the user's favorite status of that workspace. The user shouldn't see a favorited workspace if they don't have access to it, of course, but if they are later re-granted access to it, it does seem reasonable that upon re-access it is shown to that user as one of their favorite workspaces (since it was before and they never said it wasn't).

This might already be how things work, or might not be possible with the way things are stored in the database, but I just wanted to offer that opinion on the general workings of things.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ggeisler ok, thanks!

@mjgiarlo mjgiarlo force-pushed the user-specific-favorites#141 branch from 4aa3a12 to a35f22e Compare June 14, 2021 18:40
@mjgiarlo mjgiarlo marked this pull request as ready for review June 14, 2021 18:41
end

respond_to do |format|
format.html { redirect_to @workspace, notice: favorite_notice(params[:favorite]) }
Copy link
Member Author

Choose a reason for hiding this comment

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

In practice, no one ever sees this but just in case...

@@ -34,7 +34,7 @@
<p class="fst-italic">There hasn't been any recent workspace activity in this project.</p>
<% end %>

<% favorites = @project.workspaces.favorites.accessible_by(current_ability) %>
<% favorites = current_user.favorited_workspaces %>
Copy link
Member Author

Choose a reason for hiding this comment

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

Still check accessibility here or?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think so? it's possible to favorite a public workspace, and then the workspace owner might take it private again?

@@ -14,7 +14,7 @@ def explore
end

def dashboard
@favorites = Workspace.accessible_by(current_ability, :update).favorites.order(updated_at: :desc).limit(3)
@favorites = current_user.favorited_workspaces.order(updated_at: :desc).limit(3)
Copy link
Member

Choose a reason for hiding this comment

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

On a previous commit, I think you asked if we should keep checking accessible workspaces here? Maybe @ggeisler has thoughts about whether to:

  • just hide non-accessible workspaces
  • show... something.. to let the user know they no longer have access
  • offer a broken link?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, my earlier comment was ideally we should continue to track that a user favorited a given workspace, even if it has been made inaccessible to them (in case it later becomes accessible).

But definitely a second part of that is do we alert the user to the situation, and if so, how?

I don't know. Ideally, I guess some sort of notification might be helpful. But I'm also not sure it's a frequent or significant enough case to worry much about at this point. I'd suggest we go with "just hide non-accessible workspaces" and I can create a design-needed ticket to remember to think about this further and maybe do something more sophisticated in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK! Will see to this later in the PM. Thanks, all.

@camillevilla camillevilla merged commit 3ee32ee into main Jun 15, 2021
@camillevilla camillevilla deleted the user-specific-favorites#141 branch June 15, 2021 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants