[Git][noosfero/noosfero][master] 4 commits: adding invite endpoint
Leandro Nunes
gitlab at mg.gitlab.com
Tue Apr 25 15:58:46 BRT 2017
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
ae842f5a by Leandro Nunes dos Santos at 2017-04-25T13:43:18-03:00
adding invite endpoint
- - - - -
cc32c274 by Leandro Nunes dos Santos at 2017-04-25T14:31:09-03:00
adding unit tests for invite endpoint
- - - - -
e35850fb by Leandro Nunes dos Santos at 2017-04-25T15:11:44-03:00
change the invitation return to Entities::Response
- - - - -
308dd4df by Leandro Nunes at 2017-04-25T18:58:19+00:00
Merge branch 'send_invitation' into 'master'
adding invite endpoint
See merge request !1176
- - - - -
5 changed files:
- app/api/entities.rb
- app/api/helpers.rb
- app/api/status.rb
- app/api/v1/communities.rb
- test/api/communities_test.rb
Changes:
=====================================
app/api/entities.rb
=====================================
--- a/app/api/entities.rb
+++ b/app/api/entities.rb
@@ -358,5 +358,11 @@ module Api
type_map.first.represent(domain.owner, options) unless type_map.nil?
end
end
+
+ class Response < Entity
+ expose :success
+ expose :code
+ expose :message
+ end
end
end
=====================================
app/api/helpers.rb
=====================================
--- a/app/api/helpers.rb
+++ b/app/api/helpers.rb
@@ -363,7 +363,7 @@ module Api
end
##########################################
- # error helpers #
+ # response helpers #
##########################################
def not_found!
=====================================
app/api/status.rb
=====================================
--- a/app/api/status.rb
+++ b/app/api/status.rb
@@ -12,6 +12,7 @@ module Api
# Noosfero API Status
DEPRECATED = 299
+ INVITATION_SENT_TO_BE_PROCESSED = 298
end
end
=====================================
app/api/v1/communities.rb
=====================================
--- a/app/api/v1/communities.rb
+++ b/app/api/v1/communities.rb
@@ -53,6 +53,29 @@ module Api
present_partial community, :with => Entities::Community, :current_person => current_person, :params => params
end
+
+
+ desc 'Send invitations of users to community' do
+ detail 'The invitation must be provided by a user logged user with permission'
+ params Entities::Response.documentation
+ success Entities::Response
+ named 'CommunityInvite'
+ end
+ post ':id/invite' do
+ authenticate!
+ community = profiles_for_person(environment.communities, current_person).find_by_id(params[:id])
+ not_found! unless community.present?
+ forbidden! unless community.allow_invitation_from?(current_person)
+ Delayed::Job.enqueue InvitationJob.new(current_person.id, params[:contacts], '', community.id, nil, I18n.locale)
+ msg = {
+ :success => true,
+ :message => _('Your invitation was registered. The community administrators are reviewing your solicitation.'),
+ :code => Api::Status::INVITATION_SENT_TO_BE_PROCESSED
+ }
+
+ present msg, :with => Entities::Response
+ end
+
end
resource :people do
=====================================
test/api/communities_test.rb
=====================================
--- a/test/api/communities_test.rb
+++ b/test/api/communities_test.rb
@@ -386,4 +386,63 @@ class CommunitiesTest < ActiveSupport::TestCase
json = JSON.parse(last_response.body)
assert_equal [community2.id], json.map {|c| c['id']}
end
+
+ should 'send inviation for comunity' do
+ login_api
+ community = fast_create(Community)
+ community.add_admin(person)
+ post "/api/v1/communities/#{community.id}/invite?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal Api::Status::CREATED, last_response.status
+ end
+
+ should 'not send inviation for unexisting community ' do
+ login_api
+ community = fast_create(Community)
+ post "/api/v1/communities/100/invite?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal Api::Status::NOT_FOUND, last_response.status
+ end
+
+ should 'not send inviation for comunity if user has no permission' do
+ login_api
+ community = fast_create(Community)
+ post "/api/v1/communities/#{community.id}/invite?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal Api::Status::FORBIDDEN, last_response.status
+ end
+
+ should 'not send invitation unlogged' do
+ community = fast_create(Community)
+ post "/api/v1/communities/#{community.id}/invite?#{params.to_query}"
+ assert_equal Api::Status::UNAUTHORIZED, last_response.status
+ end
+
+ should 'the invitation response return success true if the inivitation was sent' do
+ login_api
+ community = fast_create(Community)
+ community.add_admin(person)
+ post "/api/v1/communities/#{community.id}/invite?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert json['success']
+ end
+
+ should "the inviation response return the code #{Api::Status::INVITATION_SENT_TO_BE_PROCESSED}" do
+ login_api
+ community = fast_create(Community)
+ community.add_admin(person)
+ post "/api/v1/communities/#{community.id}/invite?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal json['code'], Api::Status::INVITATION_SENT_TO_BE_PROCESSED
+ end
+
+ should "the inviation response have some message" do
+ login_api
+ community = fast_create(Community)
+ community.add_admin(person)
+ post "/api/v1/communities/#{community.id}/invite?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_not_nil json['message']
+ end
+
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c5e601e18b62a664ac3ece6b2257355d2d9bc662...308dd4dfa1adbb08f1fecb60fce822c26b9a48e0
---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c5e601e18b62a664ac3ece6b2257355d2d9bc662...308dd4dfa1adbb08f1fecb60fce822c26b9a48e0
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170425/fece6880/attachment-0001.html>
More information about the Noosfero-dev
mailing list