-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature_project_setup
- Loading branch information
Showing
53 changed files
with
1,876 additions
and
224 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
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
25 changes: 25 additions & 0 deletions
25
...engines/commercial/public_api/app/controllers/web_api/v1/power_bi_templates_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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module PublicApi | ||
class WebApi::V1::PowerBiTemplatesController < ApplicationController | ||
# Download a template - files behind a controller to give permission only to admins | ||
def show | ||
authorize :'public_api/power_bi_template' | ||
|
||
case params[:id] | ||
when 'dataflow' | ||
template = Rails.root.join('engines/commercial/public_api/files/power_bi/dataflow.json') | ||
# Search and replace API base URL | ||
file_text = open(template).read | ||
host = AppConfiguration.instance.base_backend_uri | ||
replaced = file_text.gsub(/##BASE_URL##/, "#{host}/api/v2/") | ||
send_data replaced, type: 'application/octet-stream' | ||
when 'report' | ||
template = Rails.root.join('engines/commercial/public_api/files/power_bi/report.pbit') | ||
send_data open(template).read, type: 'application/octet-stream' | ||
else | ||
render json: { error: 'Not found' }, status: :not_found | ||
end | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
back/engines/commercial/public_api/app/policies/public_api/power_bi_template_policy.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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module PublicApi | ||
class PowerBiTemplatePolicy < ApplicationPolicy | ||
def show? | ||
active? && admin? | ||
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
879 changes: 879 additions & 0 deletions
879
back/engines/commercial/public_api/files/power_bi/dataflow.json
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
58 changes: 58 additions & 0 deletions
58
back/engines/commercial/public_api/spec/acceptance/web_api/power_bi_templates_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,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'rspec_api_documentation/dsl' | ||
|
||
resource 'Power BI templates' do | ||
explanation 'Download the two power BI templates - admin only' | ||
|
||
before { header 'Content-Type', 'application/json' } | ||
|
||
get 'web_api/v1/power_bi_templates/:id' do | ||
context 'as an admin' do | ||
before { admin_header_token } | ||
|
||
context 'dataflow' do | ||
let(:id) { 'dataflow' } | ||
|
||
example_request 'Dataflow template' do | ||
assert_status 200 | ||
end | ||
end | ||
|
||
context 'report' do | ||
let(:id) { 'report' } | ||
|
||
example_request 'Reporting template' do | ||
assert_status 200 | ||
end | ||
end | ||
|
||
context 'anything else' do | ||
let(:id) { 'anything' } | ||
|
||
example_request 'Not found' do | ||
assert_status 404 | ||
end | ||
end | ||
end | ||
|
||
context 'unauthenticated' do | ||
let(:id) { 'dataflow.json' } | ||
|
||
context 'as a normal user' do | ||
before { header_token_for create(:user) } | ||
|
||
example_request 'Unauthorised dataflow template' do | ||
assert_status 401 | ||
end | ||
end | ||
|
||
context 'as a public user' do | ||
example_request 'Unauthorised dataflow template' do | ||
assert_status 401 | ||
end | ||
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
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
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
105 changes: 105 additions & 0 deletions
105
front/app/containers/Admin/tools/PowerBI/PowerBITemplates/index.tsx
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,105 @@ | ||
import React from 'react'; | ||
|
||
// components | ||
import { | ||
Box, | ||
Button, | ||
colors, | ||
Text, | ||
Title, | ||
} from '@citizenlab/cl2-component-library'; | ||
import GoBackButton from 'components/UI/GoBackButton'; | ||
|
||
// intl | ||
import { FormattedMessage, useIntl } from 'utils/cl-intl'; | ||
import messages from './messages'; | ||
|
||
// hooks | ||
import useFeatureFlag from 'hooks/useFeatureFlag'; | ||
|
||
// utils | ||
import { isNilOrError } from 'utils/helperUtils'; | ||
import clHistory from 'utils/cl-router/history'; | ||
import Link from 'utils/cl-router/Link'; | ||
|
||
import { saveTemplateFile } from './saveTemplateFile'; | ||
|
||
const PowerBITemplates = () => { | ||
const isPowerBIEnabled = useFeatureFlag({ name: 'power_bi' }); | ||
const { formatMessage } = useIntl(); | ||
|
||
const handleDownloadTemplate = async (fileName, fileExtension) => { | ||
if (isNilOrError(fileName)) return; | ||
await saveTemplateFile({ fileName, fileExtension }); | ||
}; | ||
|
||
const downloadReportingTemplate = () => { | ||
handleDownloadTemplate('report', 'pbit'); | ||
}; | ||
|
||
const downloadDataFlowTemplate = () => { | ||
handleDownloadTemplate('dataflow', 'json'); | ||
}; | ||
|
||
if (!isPowerBIEnabled) return null; | ||
|
||
return ( | ||
<> | ||
<Box w="100%"> | ||
<GoBackButton onClick={clHistory.goBack} /> | ||
</Box> | ||
|
||
<Title variant="h1" mb="0"> | ||
{formatMessage(messages.title)} | ||
</Title> | ||
<Text> | ||
<FormattedMessage | ||
{...messages.intro} | ||
values={{ | ||
link: ( | ||
<Link to="/admin/tools/public-api-tokens"> | ||
{formatMessage(messages.publicApiLinkText)} | ||
</Link> | ||
), | ||
}} | ||
/> | ||
</Text> | ||
<Box background="white" px="20px" pb="10px" mb="20px"> | ||
<Title variant="h2" mb="0"> | ||
{formatMessage(messages.reportTemplateTitle)} | ||
</Title> | ||
<Box display="flex"> | ||
<Text mr="20px"> | ||
{formatMessage(messages.reportTemplateDescription)} | ||
</Text> | ||
<Button | ||
icon="download" | ||
color={colors.primary} | ||
onClick={downloadReportingTemplate} | ||
> | ||
{formatMessage(messages.reportTemplateDownload)} (.pbit) | ||
</Button> | ||
</Box> | ||
</Box> | ||
<Box background="white" px="20px" pb="10px" mb="20px"> | ||
<Title variant="h2" mb="0"> | ||
{formatMessage(messages.dataflowTemplateTitle)} | ||
</Title> | ||
<Box display="flex"> | ||
<Text mr="20px"> | ||
{formatMessage(messages.dataflowTemplateDescription)} | ||
</Text> | ||
<Button | ||
icon="download" | ||
color={colors.primary} | ||
onClick={downloadDataFlowTemplate} | ||
> | ||
{formatMessage(messages.dataflowTemplateDownload)} (.json) | ||
</Button> | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
export default PowerBITemplates; |
Oops, something went wrong.