A platform for community discussion. Free, open, simple.
DEV: Update API documentation for invites (#12360)
Dan Ungureanu9c93a62b97ea
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rbindex 9cb6c02a511..9804308c4d1 100644--- a/app/controllers/invites_controller.rb+++ b/app/controllers/invites_controller.rb@@ -57,7 +57,6 @@ class InvitesController < ApplicationControllerbegininvite = Invite.generate(current_user,- invite_key: params[:invite_key],email: params[:email],skip_email: params[:skip_email],invited_by: current_user,diff --git a/app/models/invite.rb b/app/models/invite.rbindex 7aa89062d54..ed5638b2186 100644--- a/app/models/invite.rb+++ b/app/models/invite.rb@@ -133,7 +133,7 @@ class Invite < ActiveRecord::Baseemailed_status: emailed_status)else- create_args = opts.slice(:invite_key, :email, :moderator, :custom_message, :max_redemptions_allowed)+ create_args = opts.slice(:email, :moderator, :custom_message, :max_redemptions_allowed)create_args[:invited_by] = invited_bycreate_args[:email] = emailcreate_args[:emailed_status] = emailed_statusdiff --git a/app/serializers/invite_serializer.rb b/app/serializers/invite_serializer.rbindex 4e9a0fae8f9..c09ec9f5740 100644--- a/app/serializers/invite_serializer.rb+++ b/app/serializers/invite_serializer.rb@@ -5,9 +5,10 @@ class InviteSerializer < ApplicationSerializer:link,:email,:emailed,- :redemption_count,:max_redemptions_allowed,+ :redemption_count,:custom_message,+ :created_at,:updated_at,:expires_at,:expired@@ -27,6 +28,18 @@ class InviteSerializer < ApplicationSerializerobject.emailed_status != Invite.emailed_status_types[:not_required]end+ def include_custom_message?+ email.present?+ end++ def include_max_redemptions_allowed?+ email.blank?+ end++ def include_redemption_count?+ email.blank?+ end+def expiredobject.expired?enddiff --git a/spec/requests/api/invites_spec.rb b/spec/requests/api/invites_spec.rbindex 5084ae7f0c1..cace13aa162 100644--- a/spec/requests/api/invites_spec.rb+++ b/spec/requests/api/invites_spec.rb@@ -7,7 +7,7 @@ describe 'invites' dolet(:'Api-Username') { 'system' }path '/invites.json' do- post 'Invite to site by email' do+ post 'Create an invite' dotags 'Invites'consumes 'application/json'parameter name: 'Api-Key', in: :header, type: :string, required: true@@ -16,16 +16,31 @@ describe 'invites' doparameter name: :request_body, in: :body, schema: {type: :object,properties: {- email: { type: :string },- group_names: { type: :string },- custom_message: { type: :string },- }, required: ['email']+ email: { type: :string, example: "[email protected]", description: "required for email invites only" },+ skip_email: { type: :boolean, default: false },+ custom_message: { type: :string, description: "optional, for email invites" },+ max_redemptions_allowed: { type: :integer, example: 5, default: 1, description: "optional, for link invites" },+ topic_id: { type: :int },+ group_id: { type: [:int], description: "optional, either this or `group_names`" },+ group_names: { type: :string, description: "optional, either this or `group_id`" },+ expires_at: { type: :string, default: "controlled by invite_expiry_days site setting" },+ }}produces 'application/json'response '200', 'success response' doschema type: :object, properties: {- success: { type: :string, example: "OK" }+ id: { type: :integer, example: 42 },+ link: { type: :string, example: "http://example.com/invites/9045fd767efe201ca60c6658bcf14158" },+ email: { type: :string, example: "[email protected]" },+ emailed: { type: :boolean, example: false },+ custom_message: { type: :string, example: "Hello world!", nullable: true },+ topics: { type: :array, example: [] },+ groups: { type: :array, example: [] },+ created_at: { type: :string, example: "2021-01-01T12:00:00.000Z" },+ updated_at: { type: :string, example: "2021-01-01T12:00:00.000Z" },+ expires_at: { type: :string, example: "2021-02-01T12:00:00.000Z" },+ expired: { type: :boolean, example: false },}let(:request_body) { { email: '[email protected]' } }