Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add API to get team members#471

Merged
ajinkyaa merged 7 commits intodevelopfrom
team-members-details-api
Jun 17, 2022
Merged

Add API to get team members#471
ajinkyaa merged 7 commits intodevelopfrom
team-members-details-api

Conversation

@shalapatil
Copy link
Contributor

@shalapatil shalapatil commented Jun 14, 2022

Notion card

Summary

https://www.notion.so/API-to-fetch-team-members-details-on-team-page-2104bddb4caa447bb2f91c1268493102

Preview

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Checklist:

  • I have manually tested all workflows
  • I have performed a self-review of my own code
  • I have added automated tests for my code

@github-actions
Copy link

github-actions bot commented Jun 14, 2022

Current Code Coverage Percent of this PR:

89.22 %

Files having coverage below 100%

Impacted Files Coverage
/lib/custom_failure.rb 80.0 %
/app/controllers/users/invitations_controller.rb 86.36 %
/app/controllers/users/sessions_controller.rb 85.71 %
/app/services/invoice_payment/pdf_generation.rb 70.97 %
/app/services/invoice_payment/checkout.rb 44.0 %
/app/controllers/internal_api/v1/payment_settings_controller.rb 93.33 %
/app/controllers/internal_api/v1/profile_controller.rb 96.88 %
/app/controllers/internal_api/v1/companies_controller.rb 95.45 %
/app/controllers/internal_api/v1/payments/providers_controller.rb 94.74 %
/app/controllers/internal_api/v1/wise/recipients_controller.rb 90.0 %
/lib/benchmarking/benchmarker.rb 0.0 %

Copy link
Contributor

@rohitjoshixyz rohitjoshixyz left a comment

Choose a reason for hiding this comment

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

Some changes needed

Comment on lines 13 to 21
send_request(
:post, user_invitation_path, params: {
user: {
first_name: "firstName",
last_name: "lastName",
email: "[email protected]",
roles: "employee"
}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Create the user using factory instead of making a POST request

Comment on lines 30 to 38
send_request(
:post, user_invitation_path, params: {
user: {
first_name: "firstName",
last_name: "lastName",
email: "[email protected]",
roles: "employee"
}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Create the user needed using factory

Comment on lines 80 to 94
actual_members_data = json_response["team"].map do |member|
member.slice("name", "email", "role", "status")
end
expected_members_data =
[{
"name" => user.full_name, "email" => user.email, "role" => "admin", "status" => nil
},
{
"name" => "firstName lastName", "email" => "[email protected]", "role" => "employee", "status" => nil
},
{
"name" => user2.full_name, "email" => user2.email, "role" => "employee", "status" => nil
}
]
expect(actual_members_data).to eq(expected_members_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can simplify this spec, there is a lot of repetition of keys.

end

context "when unauthenticated" do
it "is not permitted to view teamt" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo

Suggested change
it "is not permitted to view teamt" do
it "is not permitted to view team members" do

end

it "checks if profile picture is there with each team member" do
expect(json_response["team"].pluck("profilePicture")).not_to include(nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Assert with actual value instead of asserting not nil. You can create one user with an explicitly set avatar, and another with no avatar which will render the default avatar.png

Comment on lines 6 to 14
def status(member)
if current_user.has_owner_or_admin_role?(current_company)
if member.unconfirmed_email?
"reconfirmation"
elsif member.created_by_invite? && !member.invitation_accepted? && !member.has_role?(:owner, current_company)
"pending_invitation"
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Use I18n. Check for t('team.reconfirmation') and reuse it for statuses

Comment on lines 6 to 14
def status(member)
if current_user.has_owner_or_admin_role?(current_company)
if member.unconfirmed_email?
"reconfirmation"
elsif member.created_by_invite? && !member.invitation_accepted? && !member.has_role?(:owner, current_company)
"pending_invitation"
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, this method should go in a presenter class. cc @keshavbiswa
We have not added any presenters so we could keep this in the user model to keep this JBuilder file clean

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, yes. Also never liked jbuilder files, I feel it's much simpler to write Serializer classes which makes it more readable and clean in my opinion.

Copy link
Contributor

@keshavbiswa keshavbiswa left a comment

Choose a reason for hiding this comment

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

Added some comments.

# frozen_string_literal: true

class InternalApi::V1::TeamController < InternalApi::V1::ApplicationController
helper :all
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to include all helpers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because we need access touser_avatar helper method in jbuilder

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you try helper :application_helper as helper :all will include All helpers.


class TeamPolicy < ApplicationPolicy
def index?
true
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct or should there be some kind of constraints (such as: current_user should be part of the company where the teams are?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to current user we show members of his team. We want to show it to employee type of users also. That's how this is done at other places too.

Comment on lines 6 to 14
def status(member)
if current_user.has_owner_or_admin_role?(current_company)
if member.unconfirmed_email?
"reconfirmation"
elsif member.created_by_invite? && !member.invitation_accepted? && !member.has_role?(:owner, current_company)
"pending_invitation"
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, yes. Also never liked jbuilder files, I feel it's much simpler to write Serializer classes which makes it more readable and clean in my opinion.

Copy link
Contributor

@keshavbiswa keshavbiswa left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for making the changes.

@supriya3105
Copy link
Contributor

@rohitjoshixyz Please review this PR.

Copy link
Contributor

@rohitjoshixyz rohitjoshixyz left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +20 to +23
trait :with_pending_invitation do
invitation_token { Faker::String.random(length: 10) }
invitation_created_at { Time.current }
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

@supriya3105
Copy link
Contributor

@ajinkyaa @shalapatil The same is applicable for this PR too. Please do not merge this on develop branch.

@ajinkyaa
Copy link
Contributor

@supriya3105 we can merge this PR on the develop, UI we are not merging.

@ajinkyaa ajinkyaa merged commit c0df253 into develop Jun 17, 2022
@ajinkyaa ajinkyaa deleted the team-members-details-api branch June 17, 2022 08:32
vipulnsward pushed a commit that referenced this pull request Feb 15, 2026
* Add API to get team members

* Add suggested changes

* Fix robocop errors

* Use Application helper instead of including all helpers

* Use has_role method
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.

6 participants