-
Notifications
You must be signed in to change notification settings - Fork 43
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
Application Rating & Review #186
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b824a0b
Add App User Rating
x4d3 25328df
Merge pull request #159 from x4d3/feature/rating
x4d3 a22b92c
Implement comments management in Admin Panel
hedudelgado 0748434
Ratings property is always displayed, even as an empry array
alexnoox cf3a82d
Merge pull request #165 from alexnoox/feature/app-rating
x4d3 f8073f2
Merge pull request #161 from hedudelgado/implement-comments-in-admin-…
x4d3 5a9e268
Rename model Rating to Review
x4d3 3d0e8ed
Merge pull request #167 from x4d3/feature/rating
x4d3 cb08e97
Add missing locales for reviews
c6fe257
Add route to expose comments for a single app
hedudelgado 952c8a2
Add pagination
hedudelgado afe587f
Fix specs and refactoring
hedudelgado f76351f
Refactor App Review API
ouranos 4665231
Merge pull request #177 from hedudelgado/comments-pagination
ouranos b8ec8fa
Add locales in mnoe
alexnoox 9d4bf24
Merge pull request #179 from alexnoox/feature/app-rating
ouranos ca79ec9
Frogot to commit specs :s
ouranos cb86691
Merge pull request #180 from ouranos/comments-pagination
ouranos 05fa0b8
Merge remote-tracking branch 'upstream/master' into feature/app-rating
ouranos 6754b44
App Rating - Add feature flag
ouranos 5a44cb5
Update locales
ouranos a5badc4
Style: Remove empty lines
ouranos 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 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
32 changes: 32 additions & 0 deletions
32
api/app/controllers/mno_enterprise/jpi/v1/admin/app_reviews_controller.rb
This file contains 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,32 @@ | ||
module MnoEnterprise | ||
class Jpi::V1::Admin::AppReviewsController < Jpi::V1::Admin::BaseResourceController | ||
# GET /mnoe/jpi/v1/admin/app_reviews | ||
def index | ||
@app_reviews = MnoEnterprise::AppReview | ||
@app_reviews = @app_reviews.limit(params[:limit]) if params[:limit] | ||
@app_reviews = @app_reviews.skip(params[:offset]) if params[:offset] | ||
@app_reviews = @app_reviews.order_by(params[:order_by]) if params[:order_by] | ||
@app_reviews = @app_reviews.where(params[:where]) if params[:where] | ||
@app_reviews = @app_reviews.all.fetch | ||
response.headers['X-Total-Count'] = @app_reviews.metadata[:pagination][:count] | ||
end | ||
|
||
# GET /mnoe/jpi/v1/admin/app_reviews/1 | ||
def show | ||
@app_review = MnoEnterprise::AppReview.find(params[:id]) | ||
end | ||
|
||
|
||
# PATCH /mnoe/jpi/v1/admin/app_reviews/1 | ||
def update | ||
@app_review = MnoEnterprise::AppReview.find(params[:id]) | ||
@app_review.update(app_review_params) | ||
render :show | ||
end | ||
|
||
def app_review_params | ||
params.require(:app_review).permit(:status) | ||
end | ||
|
||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
api/app/controllers/mno_enterprise/jpi/v1/app_reviews_controller.rb
This file contains 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,34 @@ | ||
module MnoEnterprise | ||
class Jpi::V1::AppReviewsController < Jpi::V1::BaseResourceController | ||
# GET /mnoe/jpi/v1/marketplace/:id/app_reviews | ||
def index | ||
@app_reviews = MnoEnterprise::AppReview.approved.where(reviewable_id: params[:id]) | ||
@app_reviews = @app_reviews.limit(params[:limit]) if params[:limit] | ||
@app_reviews = @app_reviews.skip(params[:offset]) if params[:offset] | ||
@app_reviews = @app_reviews.order_by(params[:order_by]) if params[:order_by] | ||
@app_reviews = @app_reviews.where(params[:where]) if params[:where] | ||
@app_reviews = @app_reviews.all.fetch | ||
response.headers['X-Total-Count'] = @app_reviews.metadata[:pagination][:count] | ||
end | ||
|
||
# POST /mnoe/jpi/v1/marketplace/:id/app_reviews | ||
def create | ||
@app = MnoEnterprise::App.find(params[:id]) | ||
return render json: "could not find App #{params[:id]}", status: :not_found unless @app | ||
|
||
# TODO: use the has_many associations -> @app.reviews.build | ||
@app_review = MnoEnterprise::AppReview.new(review_params(@app.id)) | ||
if @app_review.save | ||
@average_rating = @app.reload.average_rating | ||
render :show | ||
else | ||
render json: @app_review.errors, status: :bad_request | ||
end | ||
end | ||
|
||
def review_params(app_id) | ||
params.require(:app_review).permit(:rating, :description, :organization_id) | ||
.merge(app_id: app_id, user_id: current_user.id) | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
api/app/views/mno_enterprise/jpi/v1/admin/app_reviews/_app_review.json.jbuilder
This file contains 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,12 @@ | ||
json.id app_review.id | ||
json.rating app_review.rating | ||
json.description app_review.description | ||
json.status app_review.status | ||
json.app_id app_review.app_id | ||
json.app_name app_review.app_name | ||
json.user_id app_review.user_id | ||
json.user_name app_review.user_name | ||
json.organization_id app_review.organization_id | ||
json.organization_name app_review.organization_name | ||
json.created_at app_review.created_at | ||
json.updated_at app_review.updated_at |
1 change: 1 addition & 0 deletions
1
api/app/views/mno_enterprise/jpi/v1/admin/app_reviews/index.json.jbuilder
This file contains 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 @@ | ||
json.app_reviews @app_reviews, partial: 'app_review', as: :app_review |
3 changes: 3 additions & 0 deletions
3
api/app/views/mno_enterprise/jpi/v1/admin/app_reviews/show.json.jbuilder
This file contains 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,3 @@ | ||
json.app_review do | ||
json.partial! 'app_review', app_review: @app_review | ||
end |
12 changes: 12 additions & 0 deletions
12
api/app/views/mno_enterprise/jpi/v1/app_reviews/_resource.json.jbuilder
This file contains 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,12 @@ | ||
json.id app_review[:id] | ||
json.rating app_review[:rating] | ||
json.description app_review[:description] | ||
json.status app_review[:status] | ||
json.user_id app_review[:user_id] | ||
json.user_name app_review[:user_name] | ||
json.organization_id app_review[:organization_id] | ||
json.organization_name app_review[:organization_name] | ||
json.app_id app_review[:app_id] | ||
json.app_name app_review[:app_name] | ||
json.created_at app_review[:created_at] | ||
json.updated_at app_review[:updated_at] |
6 changes: 6 additions & 0 deletions
6
api/app/views/mno_enterprise/jpi/v1/app_reviews/index.json.jbuilder
This file contains 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,6 @@ | ||
json.app_reviews do | ||
json.array! @app_reviews do |app_review| | ||
json.partial! 'resource', app_review: app_review | ||
end | ||
end | ||
|
4 changes: 4 additions & 0 deletions
4
api/app/views/mno_enterprise/jpi/v1/app_reviews/show.json.jbuilder
This file contains 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,4 @@ | ||
json.app_review do | ||
json.partial! 'resource', app_review: @app_review | ||
end | ||
json.average_rating @average_rating |
This file contains 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
6 changes: 2 additions & 4 deletions
6
api/app/views/mno_enterprise/jpi/v1/marketplace/index.json.jbuilder
This file contains 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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
json.cache! ['v1', 'marketplace'], expires_in: 20.minutes do | ||
json.categories @categories | ||
json.apps @apps, partial: 'app', as: :app | ||
end | ||
json.categories @categories | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll do some perf analysis to see the impact of removing the cache |
||
json.apps @apps, partial: 'app', as: :app |
2 changes: 1 addition & 1 deletion
2
api/app/views/mno_enterprise/jpi/v1/marketplace/show.json.jbuilder
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
json.app do | ||
json.partial! 'app', app: @app | ||
end | ||
end |
This file contains 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
102 changes: 102 additions & 0 deletions
102
api/spec/controllers/mno_enterprise/jpi/v1/admin/app_reviews_controller_spec.rb
This file contains 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,102 @@ | ||
require 'rails_helper' | ||
|
||
module MnoEnterprise | ||
include MnoEnterprise::TestingSupport::SharedExamples::JpiV1Admin | ||
|
||
describe Jpi::V1::Admin::AppReviewsController, type: :controller do | ||
render_views | ||
routes { MnoEnterprise::Engine.routes } | ||
before { request.env['HTTP_ACCEPT'] = 'application/json' } | ||
let(:user) { build(:user, :admin, :with_organizations) } | ||
let(:app_review) { build(:app_review, user: user) } | ||
before do | ||
api_stub_for(get: '/app_reviews', response: from_api([app_review])) | ||
api_stub_for(get: "/app_reviews/#{app_review.id}", response: from_api(app_review)) | ||
api_stub_for(get: "/users/#{user.id}", response: from_api(user)) | ||
sign_in user | ||
end | ||
|
||
def partial_hash_for_app_review(app_review) | ||
{ | ||
'id' => app_review.id, | ||
'rating' => app_review.rating, | ||
'description' => app_review.description, | ||
'status' => app_review.status, | ||
'app_id' => app_review.app_id, | ||
'app_name' => app_review.app_name, | ||
'user_id' => app_review.user_id, | ||
'user_name' => app_review.user_name, | ||
'organization_id' => app_review.organization_id, | ||
'organization_name' => app_review.organization_name, | ||
'created_at' => app_review.created_at, | ||
'updated_at' => app_review.updated_at, | ||
} | ||
end | ||
|
||
def hash_for_app_review(app_review) | ||
{ | ||
'app_review' => partial_hash_for_app_review(app_review) | ||
} | ||
end | ||
|
||
def hash_for_app_reviews(app_reviews) | ||
{ | ||
'app_reviews' => app_reviews.map { |o| partial_hash_for_app_review(o) } | ||
} | ||
end | ||
|
||
|
||
describe '#index' do | ||
subject { get :index } | ||
|
||
it_behaves_like "a jpi v1 admin action" | ||
|
||
context 'success' do | ||
before { subject } | ||
|
||
it 'returns a list of app_review' do | ||
expect(response).to be_success | ||
expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_app_reviews([app_review]).to_json)) | ||
end | ||
end | ||
end | ||
|
||
describe 'GET #show' do | ||
subject { get :show, id: app_review.id } | ||
|
||
it_behaves_like "a jpi v1 admin action" | ||
|
||
context 'success' do | ||
before { subject } | ||
|
||
it 'returns a complete description of the app_review' do | ||
expect(response).to be_success | ||
expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_app_review(app_review).to_json)) | ||
end | ||
end | ||
end | ||
|
||
|
||
describe 'PUT #update' do | ||
subject { put :update, id: app_review.id, app_review: {status: 'rejected'} } | ||
|
||
before do | ||
sign_in user | ||
api_stub_for(put: "/app_reviews/#{app_review.id}", response: -> { app_review.status = 'rejected'; from_api(app_review) }) | ||
end | ||
|
||
it_behaves_like "a jpi v1 admin action" | ||
|
||
context 'success' do | ||
before { subject } | ||
|
||
it { expect(response).to be_success } | ||
|
||
# Test that the app_review is updated by testing the api endpoint was called | ||
it { expect(app_review.status).to eq('rejected') } | ||
end | ||
end | ||
|
||
|
||
end | ||
end |
75 changes: 75 additions & 0 deletions
75
api/spec/controllers/mno_enterprise/jpi/v1/app_reviews_controller_spec.rb
This file contains 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,75 @@ | ||
require 'rails_helper' | ||
|
||
module MnoEnterprise | ||
describe Jpi::V1::AppReviewsController, type: :controller do | ||
include MnoEnterprise::TestingSupport::JpiV1TestHelper | ||
render_views | ||
routes { MnoEnterprise::Engine.routes } | ||
before { request.env["HTTP_ACCEPT"] = 'application/json' } | ||
|
||
|
||
#=============================================== | ||
# Assignments | ||
#=============================================== | ||
let(:user) { build(:user) } | ||
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) } | ||
before { sign_in user } | ||
|
||
let(:app) { build(:app) } | ||
let(:app_review) { build(:app_review) } | ||
let(:expected_hash_for_review) do | ||
attrs = %w(id rating description status user_id user_name organization_id organization_name app_id app_name) | ||
app_review.attributes.slice(*attrs).merge({'created_at' => app_review.created_at.as_json, 'updated_at' => app_review.updated_at.as_json}) | ||
end | ||
let(:expected_hash_for_reviews) do | ||
{ | ||
'app_reviews' => [expected_hash_for_review], | ||
# 'metadata' => {'pagination' => {'count' => 1}} | ||
} | ||
end | ||
|
||
before do | ||
api_stub_for(get: "/apps/#{app.id}", response: from_api(app)) | ||
end | ||
|
||
describe 'GET #index' do | ||
|
||
before do | ||
api_stub_for(get: "/app_reviews?filter[reviewable_id]=#{app.id}", response: from_api([app_review])) | ||
end | ||
|
||
subject { get :index, id: app.id } | ||
|
||
it_behaves_like "jpi v1 protected action" | ||
|
||
it_behaves_like "a paginated action" | ||
|
||
it 'renders the list of reviews' do | ||
subject | ||
expect(JSON.parse(response.body)).to eq(expected_hash_for_reviews) | ||
end | ||
end | ||
|
||
describe 'POST #create', focus: true do | ||
let(:params) { {organization_id: 1, description: 'A Review', rating: 5, foo: 'bar'} } | ||
let(:app_review) { build(:app_review) } | ||
|
||
before do | ||
api_stub_for(post: "/app_reviews", response: from_api(app_review)) | ||
api_stub_for(get: "/app_reviews/#{app_review.id}", response: from_api(app_review)) | ||
end | ||
|
||
subject { post :create, id: app.id, app_review: params } | ||
|
||
it_behaves_like "jpi v1 protected action" | ||
|
||
it 'renders the new review' do | ||
expect(JSON.parse(subject.body)).to include('app_review' => expected_hash_for_review) | ||
end | ||
|
||
it 'renders the new average rating' do | ||
expect(JSON.parse(subject.body)).to include('average_rating' => app.average_rating) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Oops, something went wrong.
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.
Remove an empty line.