From 9281a379386f24591f7684b714df12d893569dcc Mon Sep 17 00:00:00 2001 From: Yuri Sidorov <403994+newstler@users.noreply.github.com> Date: Thu, 24 Aug 2023 22:16:42 +0200 Subject: [PATCH] Invitations API (#737) * Invitations API * Update invitation_example * Update automatic_paths_for Invitation * Add resend action --- .../api/v1/invitations_controller.rb | 21 +++++++++++++++++++ app/models/ability.rb | 1 + .../v1/invitations/_invitation.json.jbuilder | 9 ++++++++ app/views/api/v1/open_api/index.yaml.erb | 2 ++ .../v1/open_api/invitations/_paths.yaml.erb | 19 +++++++++++++++++ test/factories/invitations.rb | 5 +++++ 6 files changed, 57 insertions(+) create mode 100644 app/controllers/api/v1/invitations_controller.rb create mode 100644 app/views/api/v1/invitations/_invitation.json.jbuilder create mode 100644 app/views/api/v1/open_api/invitations/_paths.yaml.erb diff --git a/app/controllers/api/v1/invitations_controller.rb b/app/controllers/api/v1/invitations_controller.rb new file mode 100644 index 000000000..bf4e15b64 --- /dev/null +++ b/app/controllers/api/v1/invitations_controller.rb @@ -0,0 +1,21 @@ +class Api::V1::InvitationsController < Api::V1::ApplicationController + include Api::V1::Invitations::ControllerBase + + private + + def permitted_fields + [ + # 🚅 super scaffolding will insert new fields above this line. + ] + end + + def permitted_arrays + { + # 🚅 super scaffolding will insert new arrays above this line. + } + end + + def process_params(strong_params) + strong_params + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index dddd1d640..a9fecb726 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -17,6 +17,7 @@ def initialize(user) can :manage, User, id: user.id can :read, User, id: user.collaborating_user_ids can :destroy, Membership, user_id: user.id + can :manage, Invitation, id: user.teams.map(&:invitations).flatten.map(&:id) can :create, Team diff --git a/app/views/api/v1/invitations/_invitation.json.jbuilder b/app/views/api/v1/invitations/_invitation.json.jbuilder new file mode 100644 index 000000000..f16aeaf79 --- /dev/null +++ b/app/views/api/v1/invitations/_invitation.json.jbuilder @@ -0,0 +1,9 @@ +json.extract! invitation, + :id, + :email, + :uuid, + :from_membership_id, + :team_id, + # 🚅 super scaffolding will insert new fields above this line. + :created_at, + :updated_at diff --git a/app/views/api/v1/open_api/index.yaml.erb b/app/views/api/v1/open_api/index.yaml.erb index c726bc71e..2ebff1cdf 100644 --- a/app/views/api/v1/open_api/index.yaml.erb +++ b/app/views/api/v1/open_api/index.yaml.erb @@ -18,6 +18,7 @@ components: <%= automatic_components_for Team %> <%= automatic_components_for User %> <%= automatic_components_for Membership %> + <%= automatic_components_for Invitation %> <%= automatic_components_for Webhooks::Outgoing::Endpoint %> <%= automatic_components_for Webhooks::Outgoing::Event %> <%= automatic_components_for Scaffolding::CompletelyConcrete::TangibleThing unless scaffolding_things_disabled? %> @@ -51,6 +52,7 @@ paths: <%= paths_for Team %> <%= paths_for User %> <%= automatic_paths_for Membership, Team %> + <%= automatic_paths_for Invitation, Team, except: %i[update] %> <%= automatic_paths_for Webhooks::Outgoing::Endpoint, Team %> <%= automatic_paths_for Webhooks::Outgoing::Event, Team, except: %i[create update delete] %> <%= automatic_paths_for Scaffolding::CompletelyConcrete::TangibleThing, Scaffolding::AbsolutelyAbstract::CreativeConcept unless scaffolding_things_disabled? %> diff --git a/app/views/api/v1/open_api/invitations/_paths.yaml.erb b/app/views/api/v1/open_api/invitations/_paths.yaml.erb new file mode 100644 index 000000000..bd3b5b900 --- /dev/null +++ b/app/views/api/v1/open_api/invitations/_paths.yaml.erb @@ -0,0 +1,19 @@ +/invitations/{id}/resend: + post: + tags: + - Invitation + summary: "Resend Invitation" + operationId: resendInvitation + parameters: + - $ref: "#/components/parameters/id" + responses: + "404": + description: "Not Found" + "200": + description: "OK" + content: + application/json: + schema: + $ref: "#/components/schemas/TeamAttributes" + example: + <%= FactoryBot.get_example(:invitation, version: @version) %> \ No newline at end of file diff --git a/test/factories/invitations.rb b/test/factories/invitations.rb index e2137509b..31b6cc6ca 100644 --- a/test/factories/invitations.rb +++ b/test/factories/invitations.rb @@ -4,5 +4,10 @@ association :team association :from_membership, factory: :membership sequence(:email) { |n| "example#{n}@email.com" } + + factory :invitation_example do + team { FactoryBot.example(:team) } + membership { FactoryBot.example(:membership) } + end end end