Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
391 additions
and
52 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas. | ||
|
||
def gr(resource, scope: nil, params: {}, as: Role.first.person) | ||
raise "#{resource} is not a resource class" unless resource <= ApplicationResource | ||
|
||
context = OpenStruct.new(current_ability: Ability.new(as)) | ||
Graphiti.with_context(context, params: params) do | ||
action_controller_params = ActionController::Parameters.new(params) | ||
resources = resource.all(action_controller_params, scope || resource.new.base_scope) | ||
JSON.parse(resources.to_jsonapi).deep_symbolize_keys | ||
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
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas. | ||
|
||
class JsonApi::GroupsController < JsonApiController | ||
def index | ||
authorize!(:index, Group) | ||
resources = resource_class.all(params, without_archived) | ||
render(jsonapi: resources) | ||
end | ||
|
||
def show | ||
group = without_archived.find(params[:id]) | ||
authorize!(:show, group) | ||
super | ||
end | ||
|
||
private | ||
|
||
def without_archived | ||
Group.without_archived | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ def update | |
super | ||
end | ||
|
||
private | ||
|
||
def entry | ||
@entry ||= Person.find(params[:id]) | ||
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
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
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
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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas. | ||
|
||
require 'spec_helper' | ||
|
||
describe JsonApi::PeopleController, type: [:request] do | ||
let(:params) { {} } | ||
let(:top_leader) { people(:top_leader) } | ||
let(:bottom_member) { people(:bottom_member) } | ||
|
||
describe 'GET #index' do | ||
context 'unauthorized' do | ||
it 'returns 401' do | ||
jsonapi_get '/api/groups', params: params | ||
|
||
expect(response).to have_http_status(401) | ||
|
||
errors = jsonapi_errors | ||
|
||
expect(errors.first.status).to eq('401') | ||
|
||
expect(errors.first.title).to eq('Login benötigt') | ||
expect(errors.first.detail).to eq('Du must dich einloggen bevor du auf diese Resource zugreifen kannst.') | ||
end | ||
end | ||
|
||
end | ||
|
||
context 'authorized' do | ||
let(:permitted_service_token) { service_tokens(:permitted_top_layer_token) } | ||
let(:params) { { token: permitted_service_token.token } } | ||
let(:group) { groups(:bottom_group_two_one) } | ||
before { group.update!(archived_at: Time.zone.now) } | ||
|
||
it 'GET#index does not include archived group' do | ||
jsonapi_get '/api/groups', params: params | ||
expect(response).to have_http_status(200) | ||
expect(JSON.parse(response.body)['data'].size).to eq Group.count - 1 | ||
end | ||
|
||
it 'GET#show does find archived group' do | ||
groups(:bottom_group_two_one).update!(archived_at: Time.zone.now) | ||
jsonapi_get "/api/groups/#{group.id}", params: params | ||
expect(response).to have_http_status(404) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas. | ||
|
||
class JsonApi::GroupSchema | ||
|
||
def self.read | ||
self.new.data | ||
end | ||
|
||
def data | ||
{ type: :object, | ||
properties: { | ||
data: { | ||
type: :object, | ||
properties: { | ||
id: { type: :string, description: 'ID'}, | ||
type: { type: :string, enum: ['groups'], default: 'groups'}, | ||
} | ||
}, | ||
} | ||
} | ||
end | ||
|
||
def attributes | ||
{ type: :object, | ||
properties: { | ||
name: { type: :string }, | ||
description: { type: :string } | ||
}, | ||
description: 'Group attributes' } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas. | ||
|
||
require 'swagger_helper' | ||
# require_relative 'group_schema' | ||
|
||
RSpec.describe 'json_api/groups', type: :request do | ||
let(:'X-TOKEN') { service_tokens(:permitted_top_layer_token).token } | ||
let(:token) { service_tokens(:permitted_top_layer_token).token } | ||
let(:include) { [] } | ||
|
||
path '/api/groups' do | ||
|
||
# add pagination | ||
# add filter for updated_at | ||
|
||
get('list groups') do | ||
parameter( | ||
name: 'include', | ||
in: :query, | ||
required: false, | ||
explode: false, | ||
schema: { | ||
type: :array, | ||
enum: %w(contact creator updater deleter parent layer_group), | ||
nullable: true | ||
} | ||
) | ||
|
||
parameter(name: 'extra_fields', in: :query, required: false, schema: { type: :string, enum: %w(logo) }) | ||
parameter(name: 'filter[type][eq]', in: :query, required: false, schema: { type: :string, enum: Group.all_types }) | ||
|
||
response(200, 'successful') do | ||
after do |example| | ||
example.metadata[:response][:content] = { | ||
'application/vnd.json+api' => { | ||
example: JSON.parse(response.body, symbolize_names: true) | ||
} | ||
} | ||
end | ||
run_test! | ||
end | ||
|
||
response(200, 'successful') do | ||
let(:include) { %w(contact creator updater deleter parent layer_group) } | ||
run_test! | ||
end | ||
end | ||
end | ||
|
||
path '/api/groups/{id}' do | ||
let(:id) { groups(:top_group).id } | ||
parameter name: :id, in: :path, type: :string | ||
|
||
get('fetch group') do | ||
response(200, 'successful') do | ||
after do |example| | ||
example.metadata[:response][:content] = { | ||
'application/vnd.json+api' => { | ||
example: JSON.parse(response.body, symbolize_names: true) | ||
} | ||
} | ||
end | ||
run_test! | ||
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.