Skip to content

Commit 8c71f40

Browse files
committed
chore(scopes): remove sprintf for prefixing scopes
chore(ci): add swagger preview
1 parent 90e81ab commit 8c71f40

14 files changed

Lines changed: 1775 additions & 1666 deletions

.github/workflows/l5-swagger-generate.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,99 @@ jobs:
112112
- name: Generate OpenAPI docs
113113
run: php artisan l5-swagger:generate
114114

115+
- name: Build Swagger UI preview
116+
run: |
117+
mkdir -p swagger-ui
118+
cp storage/api-docs/api-docs.json swagger-ui/api-docs.json
119+
cat > swagger-ui/index.html << 'HTMLEOF'
120+
<!doctype html>
121+
<html lang="en">
122+
<head>
123+
<meta charset="utf-8" />
124+
<title>OpenStackID API - Swagger UI</title>
125+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css" />
126+
</head>
127+
<body>
128+
<div id="swagger-ui"></div>
129+
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
130+
<script>
131+
window.onload = () => {
132+
window.ui = SwaggerUIBundle({
133+
url: 'api-docs.json',
134+
dom_id: '#swagger-ui'
135+
});
136+
};
137+
</script>
138+
</body>
139+
</html>
140+
HTMLEOF
141+
142+
- name: Upload Swagger UI artifact
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: swagger-ui
146+
path: swagger-ui/
147+
if-no-files-found: error
148+
149+
pages-preview:
150+
name: Publish Swagger UI to GitHub Pages
151+
needs: openapi-generate
152+
if: github.event_name == 'pull_request'
153+
runs-on: ubuntu-latest
154+
155+
permissions:
156+
contents: write
157+
issues: write
158+
pull-requests: write
159+
160+
steps:
161+
- name: Checkout repository
162+
uses: actions/checkout@v4
163+
164+
- name: Download Swagger UI artifact
165+
uses: actions/download-artifact@v4
166+
with:
167+
name: swagger-ui
168+
path: swagger-ui
169+
170+
- name: Build public directory for GitHub Pages
171+
run: |
172+
PR_PATH="openapi/pr-${{ github.event.number }}"
173+
mkdir -p "public/${PR_PATH}"
174+
cp -R swagger-ui/* "public/${PR_PATH}/"
175+
echo "Built GitHub Pages content at public/${PR_PATH}"
176+
177+
- name: Publish to GitHub Pages
178+
uses: peaceiris/actions-gh-pages@v4
179+
with:
180+
github_token: ${{ secrets.GITHUB_TOKEN }}
181+
publish_dir: ./public
182+
keep_files: true
183+
184+
- name: Comment preview URL on PR
185+
uses: actions/github-script@v7
186+
with:
187+
github-token: ${{ secrets.GITHUB_TOKEN }}
188+
script: |
189+
const prNumber = context.payload.pull_request.number;
190+
const owner = context.repo.owner;
191+
const repo = context.repo.repo;
192+
const baseUrl = `https://${owner}.github.io/${repo}`;
193+
const previewPath = `/openapi/pr-${prNumber}/`;
194+
const url = `${baseUrl}${previewPath}`;
195+
196+
const body = [
197+
'📘 **OpenAPI / Swagger preview**',
198+
'',
199+
`➡️ ${url}`,
200+
'',
201+
'This page is automatically updated on each push to this PR.'
202+
].join('\n');
203+
204+
await github.rest.issues.createComment({
205+
owner,
206+
repo,
207+
issue_number: prNumber,
208+
body,
209+
});
210+

app/Http/Utils/FilterAvailableSummitsStrategy.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ final class FilterAvailableSummitsStrategy
2727
*/
2828
static public function shouldReturnAllSummits(IResourceServerContext $resource_server_ctx){
2929
$scopes = $resource_server_ctx->getCurrentScope();
30-
$current_realm = Config::get('app.scope_base_realm');
31-
$needed_scope = sprintf(SummitScopes::ReadAllSummitData, $current_realm);
30+
$needed_scope = SummitScopes::ReadAllSummitData;
3231
return in_array($needed_scope, $scopes);
3332
}
3433
}

app/ModelSerializers/Summit/SummitSerializer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,7 @@ public function serialize($expand = null, array $fields = [], array $relations =
369369
// we had proper scopes
370370
if (!$summit->isAvailableOnApi()) {
371371
$scopes = $this->resource_server_context->getCurrentScope();
372-
$current_realm = Config::get('app.url');
373-
$needed_scope = sprintf(SummitScopes::ReadAllSummitData, $current_realm);
372+
$needed_scope = SummitScopes::ReadAllSummitData;
374373
if (!in_array($needed_scope, $scopes))
375374
throw new HTTP403ForbiddenException;
376375
}

app/Providers/AppServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ public function boot()
718718
public function register()
719719
{
720720

721+
if (!defined('SCOPE_BASE_REALM')) {
722+
define('SCOPE_BASE_REALM', config('app.scope_base_realm'));
723+
}
724+
721725
App::singleton(IResourceServerContext::class, ResourceServerContext::class);
722726

723727
App::bind('resource_server_context', function ($app) {

app/Security/CompanyScopes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
*/
1919
final class CompanyScopes
2020
{
21-
const Read = '%s/companies/read';
22-
const Write = '%s/companies/write';
21+
const Read = SCOPE_BASE_REALM.'/companies/read';
22+
const Write = SCOPE_BASE_REALM.'/companies/write';
2323
}

app/Security/GroupsScopes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414

1515
class GroupsScopes
1616
{
17-
const ReadData = '%s/groups/read';
17+
const ReadData = SCOPE_BASE_REALM.'/groups/read';
1818
}

app/Security/MemberScopes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*/
1919
final class MemberScopes
2020
{
21-
const ReadMemberData = '%s/members/read';
21+
const ReadMemberData = SCOPE_BASE_REALM.'/members/read';
2222

23-
const ReadMyMemberData = '%s/members/read/me';
23+
const ReadMyMemberData = SCOPE_BASE_REALM.'/members/read/me';
2424

25-
const WriteMemberData = '%s/members/write';
25+
const WriteMemberData = SCOPE_BASE_REALM.'/members/write';
2626

27-
const WriteMyMemberData = '%s/members/write/me';
27+
const WriteMyMemberData = SCOPE_BASE_REALM.'/members/write/me';
2828
}

app/Security/OrganizationScopes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
*/
1919
final class OrganizationScopes
2020
{
21-
const ReadOrganizationData = '%s/organizations/read';
22-
const WriteOrganizationData = '%s/organizations/write';
21+
const ReadOrganizationData = SCOPE_BASE_REALM.'/organizations/read';
22+
const WriteOrganizationData = SCOPE_BASE_REALM.'/organizations/write';
2323
}

app/Security/SponsoredProjectScope.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
*/
1919
final class SponsoredProjectScope
2020
{
21-
const Read = '%s/sponsored-projects/read';
22-
const Write = '%s/sponsored-projects/write';
21+
const Read = SCOPE_BASE_REALM.'/sponsored-projects/read';
22+
const Write = SCOPE_BASE_REALM.'/sponsored-projects/write';
2323
}

0 commit comments

Comments
 (0)