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

Skip to content

Team member Delete Api#454

Merged
supriya3105 merged 5 commits intodevelopfrom
team-member-delete-api
Jun 10, 2022
Merged

Team member Delete Api#454
supriya3105 merged 5 commits intodevelopfrom
team-member-delete-api

Conversation

@harshaanNihal
Copy link
Contributor

@harshaanNihal harshaanNihal commented Jun 7, 2022

Notion card

https://www.notion.so/saeloun/API-development-for-delete-team-member-ba3b8f43bff5483a8c3bb456bc28a4cc

Summary

  • Add internal api for Team page with destroy Method
  • Add specs for Api team_controller#destroy method

Preview

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • 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

@pr-triage pr-triage bot added the PR: draft label Jun 7, 2022
@github-actions
Copy link

github-actions bot commented Jun 7, 2022

Current Code Coverage Percent of this PR:

87.78 %

Files having coverage below 100%

Impacted Files Coverage
/app/controllers/users/invitations_controller.rb 86.36 %
/app/policies/payments/provider_policy.rb 85.71 %
/app/services/invoice_payment/checkout.rb 44.0 %
/app/services/invoice_payment/pdf_generation.rb 70.97 %
/app/services/report/filters.rb 87.1 %
/app/controllers/internal_api/v1/profile_controller.rb 96.88 %
/app/controllers/internal_api/v1/payment_settings_controller.rb 93.33 %
/app/controllers/internal_api/v1/payments/providers_controller.rb 94.74 %
/lib/benchmarking/benchmarker.rb 0.0 %

@harshaanNihal harshaanNihal force-pushed the team-member-delete-api branch from 03fdcea to e483ff3 Compare June 8, 2022 08:39
@harshaanNihal harshaanNihal marked this pull request as ready for review June 8, 2022 08:39
Copy link
Member

@akhilgkrishnan akhilgkrishnan left a comment

Choose a reason for hiding this comment

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

@harshaanNihal Added some comments

class InternalApi::V1::TeamController < InternalApi::V1::ApplicationController
def destroy
authorize current_user, policy_class: TeamPolicy
user.discard!
Copy link
Member

Choose a reason for hiding this comment

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

what is the response when a team member does not discard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in case user.discard! is not successful it will raise an Exception, which will get rescued here

@@ -0,0 +1,18 @@
# frozen_string_literal: true

class InternalApi::V1::TeamController < InternalApi::V1::ApplicationController
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class InternalApi::V1::TeamController < InternalApi::V1::ApplicationController
class InternalApi::V1::TeamsController < InternalApi::V1::ApplicationController

Can we use a plural name

@@ -0,0 +1,80 @@
# frozen_string_literal: true
Copy link
Member

Choose a reason for hiding this comment

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

Add a test for negative condition, when user is not discarded properly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a Model spec for negative condition and mocking the failure negative condition in controller specs

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.

I have a few concerns with this PR and hence stopped reviewing further. We are not checking if the user being deleted is part of other companies or not.
Discarding the user directly would discard the company_users associated with other companies making the user unable to login into other workspaces
This scenario is not tested in the specs as well.

What is the exact requirement of this API? We can probably split this API into two.

  • User destroy API which will completely remove the access to Miru (For all the workspaces)
  • Company User destroy API which will destroy one particular company_user (For a particular workspace)

Also when we say team member it is not immediately clear if we are talking about the company_user or the larger user record cc @supriya3105 @harshaanNihal @akhilgkrishnan

@@ -0,0 +1,18 @@
# frozen_string_literal: true

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

Choose a reason for hiding this comment

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

NIt: TeamController -> TeamsController


RSpec.describe "InternalApi::V1::Team#destroy", type: :request do
let(:company) { create(:company) }
let(:user) { create(:user, current_workspace_id: company.id) }
Copy link
Contributor

Choose a reason for hiding this comment

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

You can rename this user as admin or admin_user and in the "when user is unauthorised" call it employee or employee_user to be more specific

@akhilgkrishnan
Copy link
Member

I have a few concerns with this PR and hence stopped reviewing further. We are not checking if the user being deleted is part of other companies or not. Discarding the user directly would discard the company_users associated with other companies making the user unable to login into other workspaces This scenario is not tested in the specs as well.

What is the exact requirement of this API? We can probably split this API into two.

  • User destroy API which will completely remove the access to Miru (For all the workspaces)
  • Company User destroy API which will destroy one particular company_user (For a particular workspace)

Also when we say team member it is not immediately clear if we are talking about the company_user or the larger user record cc @supriya3105 @harshaanNihal @akhilgkrishnan

Yes I agree with you.

@harshaanNihal
Copy link
Contributor Author

I have a few concerns with this PR and hence stopped reviewing further. We are not checking if the user being deleted is part of other companies or not. Discarding the user directly would discard the company_users associated with other companies making the user unable to login into other workspaces This scenario is not tested in the specs as well.

What is the exact requirement of this API? We can probably split this API into two.

User destroy API which will completely remove the access to Miru (For all the workspaces)
Company User destroy API which will destroy one particular company_user (For a particular workspace)
Also when we say team member it is not immediately clear if we are talking about the company_user or the larger user record cc @supriya3105 @harshaanNihal @akhilgkrishnan

Agree we should discard the conmpany_user instead of user in this scenario.
Initially I was trying to port prewritten team_controller to internal API which was discarding user directly hence I overlooked this scenario.

Moving the PR to Draft for now

@harshaanNihal harshaanNihal marked this pull request as draft June 8, 2022 11:03
@harshaanNihal harshaanNihal force-pushed the team-member-delete-api branch from 1990aaa to 4749cce Compare June 9, 2022 05:27
@harshaanNihal
Copy link
Contributor Author

harshaanNihal commented Jun 9, 2022

I have kept the controller name singular team instead of teams.
The controller will mainly manage the company_users and it's not tied to a specific model i.e. Team.

Since each company will technically have only one team (company_users belong to that company). As Team controller is not associated with any particular model / resource, but rather handle a set of functionality. In this case, the pluralization doesn't make any sense to me.

Please let me know if you think otherwise and I will update the controller name to a plural form.
@rohitjoshixyz @akhilgkrishnan

@harshaanNihal harshaanNihal marked this pull request as ready for review June 9, 2022 05:46
@rohitjoshixyz
Copy link
Contributor

Since each company will technically have only one team (company users belong to that company). As Team controller is not associated with any particular model / resource, but rather handle a set of functionality. In this case, the pluralization doesn't make any sense to me.

That makes sense, considering this and our previous discussion since this controller is only going to handle the company_user model's destroy action let's name it as company_users_controller. What do you think?

@harshaanNihal
Copy link
Contributor Author

There is already a company_users_controller present. [for now it is been used for project Page ]
The Team_controller will be handling functionality specific to team page. [It is already implemented for ERB files]. We are porting it to APIs so that the team page can be ported into react components.

beside destroy method controller will have index update and probably edit.

Maybe once after the Team page is ported we can merge both team and company_user controller into single controller. if they share the functionality.

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.

@harshaanNihal
Summarizing our discussion here.

The original rails controller's (app/controllers/team_controller) implementation itself is wrong.
Instead of discarding the User it should ideally discard only the current_workspace's CompanyUser record.
According to the latest changes I asked you to make here, this PR will do that correctly.

But as you said the intent of this PR is to port the functionality of the rails controller into an internal API to be used for React we are in a fix. 😓

I won't block this PR since this is an internal API but we need to address and add API for both:

  1. Discarding the User record
  2. Discarding the Company User record
    And name the controllers accordingly on priority as a follow-up

Please check and update the language and grammar used in the spec description. It should be consistent.

Overall nice work with the specs. LGTM 👍

expect(json_response["errors"]).to eq(I18n.t("pundit.team_policy.destroy?"))
end

it "does not Discard the team member" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Capitalizing "discard" is unnecessary

end
end

context "when user is not signed In" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Captailizing "In" is unnecessary

context "when user is not signed In" do
let(:team_user) { create(:user, current_workspace_id: company.id) }

it "return unauthorized response with error" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit return => returns

send_request :delete, internal_api_v1_team_path(team_user)
end

it "return forbidden response with error" do
Copy link
Contributor

Choose a reason for hiding this comment

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

returns

end
end

context "when current user is employee" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
context "when current user is employee" do
context "when current user is an employee" do

  - Add destroy method
  - add internal_api routes
  - add translations
  - Update user with company_user in team_controller
  - use shordhand for team policy
  - add spec for multiple company condition
  - add descard specs.
  - review changes
@supriya3105 supriya3105 merged commit bb17c70 into develop Jun 10, 2022
@supriya3105 supriya3105 deleted the team-member-delete-api branch June 10, 2022 08:26
vipulnsward pushed a commit that referenced this pull request Feb 15, 2026
* Add team controller
  - Add destroy method
  - add internal_api routes
  - add translations

* add specs for API team_controller#destroy method

* code refactor

* Add Discard to company_user
  - Update user with company_user in team_controller
  - use shordhand for team policy
  - add spec for multiple company condition
  - add descard specs.

* fix specs language/grammer
  - review changes
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.

4 participants