-
Notifications
You must be signed in to change notification settings - Fork 88
Add API to get team members #471
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
036946b
Add API to get team members
shalapatil 2bc80e6
Merge remote-tracking branch 'origin/develop' into team-members-detai…
shalapatil 5316751
Add suggested changes
shalapatil 21e867a
Fix robocop errors
shalapatil ff0059d
Merge remote-tracking branch 'origin/develop' into team-members-detai…
shalapatil ea7bb5a
Use Application helper instead of including all helpers
shalapatil 70d8929
Use has_role method
shalapatil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| json.key_format! camelize: :lower | ||
| json.deep_format_keys! | ||
|
|
||
| def status(member) | ||
| if current_user.has_role?(:owner, current_company) || current_user.has_role?(:admin, current_company) | ||
| if member.unconfirmed_email? | ||
| I18n.t("team.reconfirmation") | ||
| elsif member.created_by_invite? && !member.invitation_accepted? && !member.has_role?(:owner, current_company) | ||
| I18n.t("team.invitation") | ||
| end | ||
| end | ||
| end | ||
|
|
||
| json.team team do |member| | ||
| json.profile_picture user_avatar(member) | ||
| json.name member.full_name | ||
| json.email member.email | ||
| json.role member.primary_role | ||
| json.status status(member) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "InternalApi::V1::Team#index", type: :request do | ||
| let(:company) { create(:company) } | ||
| let(:user) { create(:user, :with_avatar, current_workspace_id: company.id) } | ||
| let(:user2) { create(:user, :with_pending_invitation, current_workspace_id: company.id) } | ||
|
|
||
| before do | ||
| create(:company_user, company:, user:) | ||
| create(:company_user, company:, user: user2) | ||
| user.add_role :admin, company | ||
| user2.add_role :employee, company | ||
| end | ||
|
|
||
| context "when user is admin" do | ||
| before do | ||
| sign_in user | ||
| send_request :get, internal_api_v1_team_index_path | ||
| end | ||
|
|
||
| it "returns http success" do | ||
| expect(response).to have_http_status(:ok) | ||
| end | ||
|
|
||
| it "checks if profile picture is there with each team member" do | ||
| expect(json_response["team"].first["profilePicture"]).to eq(JSON.parse(user.avatar.to_json)) | ||
| expect(json_response["team"].last["profilePicture"]).to include("/assets/avatar") | ||
| end | ||
|
|
||
| it "checks if correct team members data is returned" do | ||
| 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" => user2.full_name, "email" => user2.email, "role" => "employee", "status" => I18n.t("team.invitation") | ||
| }] | ||
| expect(actual_members_data).to eq(expected_members_data) | ||
| end | ||
| end | ||
|
|
||
| context "when user is employee" do | ||
| let(:user3) { create(:user, current_workspace_id: company.id) } | ||
|
|
||
| before do | ||
| create(:company_user, company:, user: user3) | ||
| user3.add_role :employee, company | ||
| sign_in user3 | ||
| send_request :get, internal_api_v1_team_index_path | ||
| end | ||
|
|
||
| it "is permitted to access Team#index page" do | ||
| expect(response).to have_http_status(:ok) | ||
| end | ||
|
|
||
| it "checks if correct team members data is returned" do | ||
| 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" => user2.full_name, "email" => user2.email, "role" => "employee", "status" => nil | ||
| }, | ||
| { | ||
| "name" => user3.full_name, "email" => user3.email, "role" => "employee", "status" => nil | ||
| } | ||
| ] | ||
| expect(actual_members_data).to eq(expected_members_data) | ||
| end | ||
| end | ||
|
|
||
| context "when unauthenticated" do | ||
| it "is not permitted to view team members" do | ||
| send_request :get, internal_api_v1_team_index_path | ||
| expect(response).to have_http_status(:unauthorized) | ||
| expect(json_response["error"]).to eq("You need to sign in or sign up before continuing.") | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice