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

List people by profile tag at /people/TAGNAME #2087

Merged
merged 1 commit into from
Mar 30, 2018

Conversation

rishabhptr
Copy link
Contributor

Fixes #2071

Make sure these boxes are checked before your pull request is ready to be reviewed and merged. Thanks!

  • all tests pass -- rake test:all
  • code is in uniquely-named feature branch, and has been rebased on top of latest master (especially if you've been asked to make additional changes)
  • pull request is descriptively named with #number reference back to original issue

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/wiki/contributing-to-public-lab-software

We have a loose schedule of reviewing and pulling in changes every Tuesday and Friday, and publishing changes on Fridays. Please alert developers on plots-dev@googlegroups.com when your request is ready or if you need assistance.

Thanks!

@PublicLabBot
Copy link

PublicLabBot commented Jan 24, 2018

1 Message
📖 @rishabhptr Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.

Generated by 🚫 Danger

Copy link
Member

@SidharthBansal SidharthBansal left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. We now at public lab uses User instead of DrupalUser for users model. DrupalUser is legacy model.

@SidharthBansal
Copy link
Member

Could you please change DrupalUser to User.

@rishabhptr
Copy link
Contributor Author

@SidharthBansal Yes I know 😃. But there is a problem using User here as we are using user.last in the list view page and it is not defined when using a User variable(using id instead of uid).

Also other cases in list function are using DrupalUsers model and issue didnt include changing the model so I went ahead with this.Maybe if @jywarren suggests we could work around to use User model for all cases.

@jywarren
Copy link
Member

We are trying to stop using DrupalUser -- it's true. You should be able to do:

User.where(id: ... ).collect(&:id)

Make sense?

@jywarren
Copy link
Member

Thank you!!!! This is exciting!

@jywarren
Copy link
Member

And indeed, you should be able to swap User in for other uses in the same method. And we won't need .joins('INNER JOIN rusers ON rusers.username = users.name') anymore, as that bridged the models!

@jywarren
Copy link
Member

I see the issue on the view, too! Good catch. We can add a method to the user.rb model to alias this:

def last
  self.drupal_user.last
end

The other spot we'd need to change would be:

      <td><%= time_ago_in_words(Time.at(user.last['changed'])) if user.last %></td>

Here, we could just switch to: time_ago_in_words(user.updated_at) if user.last

Hope that helps!!!

@rishabhptr
Copy link
Contributor Author

@jywarren There some more things I have encountered.

I think users status values are opposite in both models which I have reversed also aliased node_count method in User model.
But,
In the the third case when we normally list all people (/people)
@users = User.select('*, MAX(node.changed) AS last_updated')
.joins(:node)
.group('rusers.id')
.where('rusers.status = 1 AND node.status = 1')
.order("last_updated DESC")
.page(params[:page])
There is a problem here because I think the node model has uid as the foreign key and Users model dont have a uid attribute so joining wont work.

Also I Read the comment in User model:
#this doesn't work... we should have a uid field on User
#has_one :drupal_users, :conditions => proc { ["drupal_users.name = ?", self.username] }
has_many :images, foreign_key: :uid
has_many :node, foreign_key: 'uid'
So a migration is needed or we should use any other way around.

Also one last thing, people#id was earlier leading to 'legacy#profile' i.e. user profile so that would be overriden with this.

@jywarren
Copy link
Member

You're right -- there's some weirdness to this part of the code we need to work around.

@publiclab/reviewers -- is anyone able to help @rishabhptr work through some of these issues? I'm occupied this afternoon and I know some of you are pretty familiar with this stuff. Thank you!!

@jywarren
Copy link
Member

jywarren commented Feb 1, 2018

So, take a look at this example of how to reference revisions instead of node, which should contain the latest updated revision of a node:

plots2/app/models/user.rb

Lines 97 to 103 in f52a4f5

def coauthored_notes
coauthored_tag = "with:" + self.name.downcase
Node.where(status: 1, type: "note")
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ? OR term_data.parent = ?', coauthored_tag.to_s , coauthored_tag.to_s)
end

What do you think? Could you model on this to solve the issue?

Thank you!!!!

@rishabhptr
Copy link
Contributor Author

@jywarren Thanks for the info also I was actually waiting for the ongoing work to update user status from DrupalUser status because at people list page we check to show only users not banned so after that fix we could easily use User model without any work-around for the same. 😄

@jywarren
Copy link
Member

jywarren commented Mar 7, 2018

OK, that sounds good -- I'm trying to link to that issue or PR here, but can't find it. Based on #2156, can we now rely on them being synced?

@ViditChitkara -- what do you think?

Thanks all!

@ViditChitkara
Copy link
Member

Yes, they should now be synced. Although we have a bit of encoding issue for the same (#2209), however it won't really effect here.

@rishabhptr
Copy link
Contributor Author

Yeah the User status seems to be synced now , thanks @ViditChitkara , @jywarren I have made the required changes, sorry for the delay 😄

@rishabhptr
Copy link
Contributor Author

There was a small issue that on joining user and node table , status attribute of node was selected hence I have added rusers.status in select query, I hope that's the right way to go 😄

@jywarren
Copy link
Member

Oh no! Sorry i should've tried merging this in earlier but didn't see it marked ready. Can you resolve the users_controller conflict and we can merge it in? Thanks for figuring this out, very exciting!

@jywarren
Copy link
Member

Hi, just checking if you've gotten stuck on this at all, or if I could help in any way? Thanks!

Allow to view people by their
profile tag at /people/tag-name.
Fixes publiclab#2071
@rishabhptr
Copy link
Contributor Author

@jywarren Hey, sorry for the delay. I have resolved the conflicts 😄

@jywarren jywarren merged commit 9368ab1 into publiclab:master Mar 30, 2018
@jywarren
Copy link
Member

Awesome work!!! This is going to be great!!!

👍 👍 🎉

SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
Allow to view people by their
profile tag at /people/tag-name.
Fixes publiclab#2071
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants