@rothenbergt/backstage-plugin-roadmap-backend 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -0
- package/dist/config.cjs.js +15 -0
- package/dist/config.cjs.js.map +1 -0
- package/dist/database/RoadmapDatabaseClient.cjs.js +212 -0
- package/dist/database/RoadmapDatabaseClient.cjs.js.map +1 -0
- package/dist/index.cjs.js +12 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +151 -0
- package/dist/plugin.cjs.js +66 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/routes/commentsRouter.cjs.js +47 -0
- package/dist/routes/commentsRouter.cjs.js.map +1 -0
- package/dist/routes/featuresRouter.cjs.js +66 -0
- package/dist/routes/featuresRouter.cjs.js.map +1 -0
- package/dist/routes/permissionCheckRouter.cjs.js +31 -0
- package/dist/routes/permissionCheckRouter.cjs.js.map +1 -0
- package/dist/routes/router.cjs.js +40 -0
- package/dist/routes/router.cjs.js.map +1 -0
- package/dist/routes/votesRouter.cjs.js +81 -0
- package/dist/routes/votesRouter.cjs.js.map +1 -0
- package/dist/services/CommentService.cjs.js +38 -0
- package/dist/services/CommentService.cjs.js.map +1 -0
- package/dist/services/FeatureService.cjs.js +59 -0
- package/dist/services/FeatureService.cjs.js.map +1 -0
- package/dist/services/PermissionService.cjs.js +63 -0
- package/dist/services/PermissionService.cjs.js.map +1 -0
- package/dist/services/VoteService.cjs.js +30 -0
- package/dist/services/VoteService.cjs.js.map +1 -0
- package/migrations/20250330000000_init.js +56 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Backstage Roadmap Plugin Backend
|
|
2
|
+
|
|
3
|
+
This is the backend part of the Roadmap Plugin for Backstage, providing API endpoints to manage a public product roadmap with features, voting, and comments.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
This plugin follows a layered architecture with clear separation of concerns:
|
|
8
|
+
|
|
9
|
+
### 1. Database Layer
|
|
10
|
+
|
|
11
|
+
- **RoadmapDatabaseClient**: Handles direct database operations through Knex
|
|
12
|
+
- Uses transactions for all write operations to ensure data consistency
|
|
13
|
+
- Maps database errors to Backstage's error types for consistent error handling
|
|
14
|
+
|
|
15
|
+
### 2. Service Layer
|
|
16
|
+
|
|
17
|
+
- Implements business logic and validation rules
|
|
18
|
+
- Services include:
|
|
19
|
+
- **FeatureService**: Feature management and validation
|
|
20
|
+
- **CommentService**: Comment creation and retrieval
|
|
21
|
+
- **VoteService**: Vote toggling and counting
|
|
22
|
+
- **PermissionService**: Authorization and permission checks
|
|
23
|
+
|
|
24
|
+
### 3. Route Layer
|
|
25
|
+
|
|
26
|
+
- RESTful API endpoints that connect to frontend
|
|
27
|
+
- Routes include:
|
|
28
|
+
- `/features`: CRUD operations for roadmap items
|
|
29
|
+
- `/comments`: Add and retrieve comments for features
|
|
30
|
+
- `/votes`: Toggle votes and get vote counts
|
|
31
|
+
- `/permissions`: Check user permissions
|
|
32
|
+
|
|
33
|
+
### 4. Error Handling
|
|
34
|
+
|
|
35
|
+
- Uses Backstage's built-in error types and middleware
|
|
36
|
+
- Errors bubble up through layers and are handled centrally
|
|
37
|
+
- Provides consistent error responses with appropriate HTTP status codes
|
|
38
|
+
|
|
39
|
+
## API Endpoints
|
|
40
|
+
|
|
41
|
+
### Features
|
|
42
|
+
|
|
43
|
+
- `GET /features`: Get all roadmap features
|
|
44
|
+
- `POST /features`: Create a new feature suggestion
|
|
45
|
+
- `GET /features/:id`: Get a specific feature
|
|
46
|
+
- `PUT /features/:id/status`: Update feature status (admin only)
|
|
47
|
+
|
|
48
|
+
### Comments
|
|
49
|
+
|
|
50
|
+
- `GET /comments?featureId=123`: Get comments for a feature
|
|
51
|
+
- `POST /comments`: Add a comment to a feature
|
|
52
|
+
|
|
53
|
+
### Votes
|
|
54
|
+
|
|
55
|
+
- `POST /votes/:featureId`: Toggle a vote on a feature
|
|
56
|
+
- `GET /votes/:featureId/count`: Get vote count for a feature
|
|
57
|
+
- `GET /votes/counts?ids=123,456`: Get vote counts for multiple features
|
|
58
|
+
- `GET /votes/:featureId/user`: Check if current user has voted
|
|
59
|
+
|
|
60
|
+
### Permissions
|
|
61
|
+
|
|
62
|
+
- `GET /permissions/check-admin`: Check if current user is an admin
|
|
63
|
+
|
|
64
|
+
## Development
|
|
65
|
+
|
|
66
|
+
### Database Schema
|
|
67
|
+
|
|
68
|
+
The plugin sets up three main tables:
|
|
69
|
+
|
|
70
|
+
- **features**: Roadmap items with title, description, status, etc.
|
|
71
|
+
- **comments**: User comments on features
|
|
72
|
+
- **votes**: User votes on features with unique constraint
|
|
73
|
+
|
|
74
|
+
### Permission Model
|
|
75
|
+
|
|
76
|
+
- Uses Backstage's permission framework
|
|
77
|
+
- Allows configuration of admin users through app-config.yaml
|
|
78
|
+
- Supports both config-based permissions and Backstage's permission framework
|
|
79
|
+
|
|
80
|
+
### Error Handling Strategy
|
|
81
|
+
|
|
82
|
+
This plugin follows Backstage's error handling patterns:
|
|
83
|
+
|
|
84
|
+
- `InputError`: For validation failures (400 errors)
|
|
85
|
+
- `NotFoundError`: When resources don't exist (404 errors)
|
|
86
|
+
- `NotAllowedError`: For authorization failures (403 errors)
|
|
87
|
+
- `ConflictError`: For database conflicts (409 errors)
|
|
88
|
+
|
|
89
|
+
Errors bubble up through layers to be handled by Backstage's middleware.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getRoadmapBackendConfig(config) {
|
|
4
|
+
try {
|
|
5
|
+
const roadmapConfig = config.getOptionalConfig("roadmap");
|
|
6
|
+
return {
|
|
7
|
+
adminUsers: roadmapConfig?.getOptionalStringArray("adminUsers") ?? []
|
|
8
|
+
};
|
|
9
|
+
} catch (error) {
|
|
10
|
+
return { adminUsers: [] };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.getRoadmapBackendConfig = getRoadmapBackendConfig;
|
|
15
|
+
//# sourceMappingURL=config.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.cjs.js","sources":["../src/config.ts"],"sourcesContent":["import { Config } from '@backstage/config';\n\nexport interface RoadmapBackendConfig {\n adminUsers: string[];\n}\n\nexport function getRoadmapBackendConfig(config: Config): RoadmapBackendConfig {\n try {\n const roadmapConfig = config.getOptionalConfig('roadmap');\n return {\n adminUsers: roadmapConfig?.getOptionalStringArray('adminUsers') ?? [],\n };\n } catch (error) {\n return { adminUsers: [] };\n }\n}\n"],"names":[],"mappings":";;AAMO,SAAS,wBAAwB,MAAsC,EAAA;AAC5E,EAAI,IAAA;AACF,IAAM,MAAA,aAAA,GAAgB,MAAO,CAAA,iBAAA,CAAkB,SAAS,CAAA;AACxD,IAAO,OAAA;AAAA,MACL,UAAY,EAAA,aAAA,EAAe,sBAAuB,CAAA,YAAY,KAAK;AAAC,KACtE;AAAA,WACO,KAAO,EAAA;AACd,IAAO,OAAA,EAAE,UAAY,EAAA,EAAG,EAAA;AAAA;AAE5B;;;;"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
4
|
+
var errors = require('@backstage/errors');
|
|
5
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
|
|
7
|
+
const migrationsDir = backendPluginApi.resolvePackagePath(
|
|
8
|
+
"@rothenbergt/backstage-plugin-roadmap-backend",
|
|
9
|
+
"migrations"
|
|
10
|
+
);
|
|
11
|
+
class RoadmapDatabaseClient {
|
|
12
|
+
static async create(options) {
|
|
13
|
+
const { database, logger } = options;
|
|
14
|
+
logger.info("Creating database for roadmap plugin");
|
|
15
|
+
const client = await database.getClient();
|
|
16
|
+
if (!database.migrations?.skip) {
|
|
17
|
+
logger.info("Running migrations for roadmap plugin");
|
|
18
|
+
await client.migrate.latest({
|
|
19
|
+
directory: migrationsDir
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return new RoadmapDatabaseClient(client, logger);
|
|
23
|
+
}
|
|
24
|
+
knex;
|
|
25
|
+
logger;
|
|
26
|
+
constructor(knexInstance, logger) {
|
|
27
|
+
this.knex = knexInstance;
|
|
28
|
+
this.logger = logger;
|
|
29
|
+
}
|
|
30
|
+
async addComment(comment) {
|
|
31
|
+
const trx = await this.knex.transaction();
|
|
32
|
+
try {
|
|
33
|
+
const feature = await trx("features").where({ id: comment.featureId }).first();
|
|
34
|
+
if (!feature) {
|
|
35
|
+
await trx.rollback();
|
|
36
|
+
throw new errors.NotFoundError(
|
|
37
|
+
`Feature with id ${comment.featureId} not found`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const [id] = await trx("comments").insert({
|
|
41
|
+
feature_id: comment.featureId,
|
|
42
|
+
text: comment.text,
|
|
43
|
+
author: comment.author
|
|
44
|
+
});
|
|
45
|
+
const newComment = await trx("comments").where({ id }).first();
|
|
46
|
+
await trx.commit();
|
|
47
|
+
return newComment;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
await trx.rollback();
|
|
50
|
+
this.logger.error(`Error inserting comment: ${error}`);
|
|
51
|
+
if (error instanceof errors.NotFoundError) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
throw new errors.ConflictError("Failed to add comment", error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async getCommentsByFeatureId(featureId) {
|
|
58
|
+
try {
|
|
59
|
+
const feature = await this.knex("features").where({ id: featureId }).first();
|
|
60
|
+
if (!feature) {
|
|
61
|
+
throw new errors.NotFoundError(`Feature with id ${featureId} not found`);
|
|
62
|
+
}
|
|
63
|
+
return this.knex("comments").where({ feature_id: featureId }).orderBy("created_at", "desc").select("*");
|
|
64
|
+
} catch (error) {
|
|
65
|
+
this.logger.error(
|
|
66
|
+
`Error fetching comments for feature ${featureId}: ${error}`
|
|
67
|
+
);
|
|
68
|
+
if (error instanceof errors.NotFoundError) {
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
throw new errors.ConflictError(
|
|
72
|
+
`Failed to get comments for feature ${featureId}`,
|
|
73
|
+
error
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async addFeature(feature) {
|
|
78
|
+
const trx = await this.knex.transaction();
|
|
79
|
+
try {
|
|
80
|
+
const [id] = await trx("features").insert({
|
|
81
|
+
...feature,
|
|
82
|
+
status: backstagePluginRoadmapCommon.FeatureStatus.Suggested,
|
|
83
|
+
votes: 0
|
|
84
|
+
});
|
|
85
|
+
const newFeature = await trx("features").where({ id }).first();
|
|
86
|
+
await trx.commit();
|
|
87
|
+
return newFeature;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
await trx.rollback();
|
|
90
|
+
this.logger.error(`Error adding feature: ${error}`);
|
|
91
|
+
throw new errors.ConflictError("Failed to add feature", error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async getAllFeatures() {
|
|
95
|
+
try {
|
|
96
|
+
return this.knex("features").orderBy("created_at", "desc").select("*");
|
|
97
|
+
} catch (error) {
|
|
98
|
+
this.logger.error(`Error fetching all features: ${error}`);
|
|
99
|
+
throw new errors.ConflictError("Failed to get all features", error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async getFeatureById(id) {
|
|
103
|
+
try {
|
|
104
|
+
const feature = await this.knex("features").where({ id }).first();
|
|
105
|
+
if (!feature) {
|
|
106
|
+
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
107
|
+
}
|
|
108
|
+
return feature;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
this.logger.error(`Error fetching feature ${id}: ${error}`);
|
|
111
|
+
if (error instanceof errors.NotFoundError) {
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
throw new errors.ConflictError(
|
|
115
|
+
`Failed to get feature with id ${id}`,
|
|
116
|
+
error
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async updateFeatureStatus(id, status) {
|
|
121
|
+
const trx = await this.knex.transaction();
|
|
122
|
+
try {
|
|
123
|
+
const feature = await trx("features").where({ id }).first();
|
|
124
|
+
if (!feature) {
|
|
125
|
+
await trx.rollback();
|
|
126
|
+
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
127
|
+
}
|
|
128
|
+
await trx("features").where({ id }).update({
|
|
129
|
+
status,
|
|
130
|
+
updated_at: this.knex.fn.now()
|
|
131
|
+
});
|
|
132
|
+
const updatedFeature = await trx("features").where({ id }).first();
|
|
133
|
+
await trx.commit();
|
|
134
|
+
return updatedFeature;
|
|
135
|
+
} catch (error) {
|
|
136
|
+
await trx.rollback();
|
|
137
|
+
this.logger.error(`Error updating feature status: ${error}`);
|
|
138
|
+
if (error instanceof errors.NotFoundError) {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
throw new errors.ConflictError(
|
|
142
|
+
`Failed to update status for feature ${id}`,
|
|
143
|
+
error
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async toggleVote(featureId, voter) {
|
|
148
|
+
const trx = await this.knex.transaction();
|
|
149
|
+
try {
|
|
150
|
+
const feature = await trx("features").where({ id: featureId }).first();
|
|
151
|
+
if (!feature) {
|
|
152
|
+
await trx.rollback();
|
|
153
|
+
throw new errors.NotFoundError(`Feature with id ${featureId} not found`);
|
|
154
|
+
}
|
|
155
|
+
const existingVote = await trx("votes").where({ feature_id: featureId, voter }).first();
|
|
156
|
+
if (existingVote) {
|
|
157
|
+
await trx("votes").where({ feature_id: featureId, voter }).delete();
|
|
158
|
+
await trx("features").where({ id: featureId }).decrement("votes", 1);
|
|
159
|
+
await trx.commit();
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
await trx("votes").insert({ feature_id: featureId, voter });
|
|
163
|
+
await trx("features").where({ id: featureId }).increment("votes", 1);
|
|
164
|
+
await trx.commit();
|
|
165
|
+
return true;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
await trx.rollback();
|
|
168
|
+
this.logger.error(`Error toggling vote: ${error}`);
|
|
169
|
+
if (error instanceof errors.NotFoundError) {
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
throw new errors.ConflictError(
|
|
173
|
+
`Failed to toggle vote for feature ${featureId}`,
|
|
174
|
+
error
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async getVoteCount(featureId) {
|
|
179
|
+
const counts = await this.getVoteCounts([featureId]);
|
|
180
|
+
return counts[featureId] || 0;
|
|
181
|
+
}
|
|
182
|
+
async getVoteCounts(featureIds) {
|
|
183
|
+
try {
|
|
184
|
+
if (featureIds.length === 0) {
|
|
185
|
+
return {};
|
|
186
|
+
}
|
|
187
|
+
const results = await this.knex("features").whereIn("id", featureIds).select("id", "votes");
|
|
188
|
+
return results.reduce((acc, { id, votes }) => {
|
|
189
|
+
acc[id] = votes;
|
|
190
|
+
return acc;
|
|
191
|
+
}, {});
|
|
192
|
+
} catch (error) {
|
|
193
|
+
this.logger.error(`Error getting vote counts: ${error}`);
|
|
194
|
+
throw new errors.ConflictError("Failed to get vote counts", error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async hasVoted(featureId, voter) {
|
|
198
|
+
try {
|
|
199
|
+
const vote = await this.knex("votes").where({ feature_id: featureId, voter }).first();
|
|
200
|
+
return !!vote;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
this.logger.error(`Error checking if user has voted: ${error}`);
|
|
203
|
+
throw new errors.ConflictError(
|
|
204
|
+
`Failed to check if user ${voter} has voted on feature ${featureId}`,
|
|
205
|
+
error
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
exports.RoadmapDatabaseClient = RoadmapDatabaseClient;
|
|
212
|
+
//# sourceMappingURL=RoadmapDatabaseClient.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoadmapDatabaseClient.cjs.js","sources":["../../src/database/RoadmapDatabaseClient.ts"],"sourcesContent":["import { Knex } from 'knex';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { RoadmapDatabase } from './types';\nimport { LoggerService, DatabaseService } from '@backstage/backend-plugin-api';\nimport { NotFoundError, ConflictError } from '@backstage/errors';\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\n\nconst migrationsDir = resolvePackagePath(\n '@rothenbergt/backstage-plugin-roadmap-backend',\n 'migrations',\n);\n\n/**\n * Implementation of the RoadmapDatabase interface using Knex\n */\nexport class RoadmapDatabaseClient implements RoadmapDatabase {\n static async create(options: {\n database: DatabaseService;\n logger: LoggerService;\n }): Promise<RoadmapDatabaseClient> {\n const { database, logger } = options;\n logger.info('Creating database for roadmap plugin');\n\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n logger.info('Running migrations for roadmap plugin');\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new RoadmapDatabaseClient(client, logger);\n }\n\n private readonly knex: Knex;\n private readonly logger: LoggerService;\n\n constructor(knexInstance: Knex, logger: LoggerService) {\n this.knex = knexInstance;\n this.logger = logger;\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features')\n .where({ id: comment.featureId })\n .first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(\n `Feature with id ${comment.featureId} not found`,\n );\n }\n\n // Insert comment\n const [id] = await trx('comments').insert({\n feature_id: comment.featureId,\n text: comment.text,\n author: comment.author,\n });\n\n // Get the inserted comment\n const newComment = await trx('comments').where({ id }).first();\n\n await trx.commit();\n return newComment;\n } catch (error) {\n await trx.rollback();\n this.logger.error(`Error inserting comment: ${error}`);\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError('Failed to add comment', error as Error);\n }\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n try {\n // First check if the feature exists\n const feature = await this.knex('features')\n .where({ id: featureId })\n .first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n // Get comments ordered by creation date (newest first)\n return this.knex('comments')\n .where({ feature_id: featureId })\n .orderBy('created_at', 'desc')\n .select('*');\n } catch (error) {\n this.logger.error(\n `Error fetching comments for feature ${featureId}: ${error}`,\n );\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get comments for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async addFeature(feature: NewFeature & { author: string }): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n const [id] = await trx('features').insert({\n ...feature,\n status: FeatureStatus.Suggested,\n votes: 0,\n });\n\n const newFeature = await trx('features').where({ id }).first();\n\n await trx.commit();\n return newFeature;\n } catch (error) {\n await trx.rollback();\n this.logger.error(`Error adding feature: ${error}`);\n throw new ConflictError('Failed to add feature', error as Error);\n }\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n try {\n return this.knex('features').orderBy('created_at', 'desc').select('*');\n } catch (error) {\n this.logger.error(`Error fetching all features: ${error}`);\n throw new ConflictError('Failed to get all features', error as Error);\n }\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n try {\n const feature = await this.knex('features').where({ id }).first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n return feature;\n } catch (error) {\n this.logger.error(`Error fetching feature ${id}: ${error}`);\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get feature with id ${id}`,\n error as Error,\n );\n }\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n // Update the status\n await trx('features').where({ id }).update({\n status,\n updated_at: this.knex.fn.now(),\n });\n\n // Get the updated feature\n const updatedFeature = await trx('features').where({ id }).first();\n\n await trx.commit();\n return updatedFeature;\n } catch (error) {\n await trx.rollback();\n this.logger.error(`Error updating feature status: ${error}`);\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to update status for feature ${id}`,\n error as Error,\n );\n }\n }\n\n async toggleVote(featureId: string, voter: string): Promise<boolean> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id: featureId }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n const existingVote = await trx('votes')\n .where({ feature_id: featureId, voter })\n .first();\n\n if (existingVote) {\n // Remove the vote\n await trx('votes').where({ feature_id: featureId, voter }).delete();\n await trx('features').where({ id: featureId }).decrement('votes', 1);\n await trx.commit();\n return false;\n }\n\n // Add the vote\n await trx('votes').insert({ feature_id: featureId, voter });\n await trx('features').where({ id: featureId }).increment('votes', 1);\n await trx.commit();\n return true;\n } catch (error) {\n await trx.rollback();\n this.logger.error(`Error toggling vote: ${error}`);\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to toggle vote for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n const counts = await this.getVoteCounts([featureId]);\n return counts[featureId] || 0;\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const results = await this.knex('features')\n .whereIn('id', featureIds)\n .select('id', 'votes');\n\n return results.reduce((acc, { id, votes }) => {\n acc[id] = votes;\n return acc;\n }, {} as Record<string, number>);\n } catch (error) {\n this.logger.error(`Error getting vote counts: ${error}`);\n throw new ConflictError('Failed to get vote counts', error as Error);\n }\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n try {\n const vote = await this.knex('votes')\n .where({ feature_id: featureId, voter })\n .first();\n return !!vote;\n } catch (error) {\n this.logger.error(`Error checking if user has voted: ${error}`);\n throw new ConflictError(\n `Failed to check if user ${voter} has voted on feature ${featureId}`,\n error as Error,\n );\n }\n }\n}\n"],"names":["resolvePackagePath","NotFoundError","ConflictError","FeatureStatus"],"mappings":";;;;;;AAaA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,+CAAA;AAAA,EACA;AACF,CAAA;AAKO,MAAM,qBAAiD,CAAA;AAAA,EAC5D,aAAa,OAAO,OAGe,EAAA;AACjC,IAAM,MAAA,EAAE,QAAU,EAAA,MAAA,EAAW,GAAA,OAAA;AAC7B,IAAA,MAAA,CAAO,KAAK,sCAAsC,CAAA;AAElD,IAAM,MAAA,MAAA,GAAS,MAAM,QAAA,CAAS,SAAU,EAAA;AAExC,IAAI,IAAA,CAAC,QAAS,CAAA,UAAA,EAAY,IAAM,EAAA;AAC9B,MAAA,MAAA,CAAO,KAAK,uCAAuC,CAAA;AACnD,MAAM,MAAA,MAAA,CAAO,QAAQ,MAAO,CAAA;AAAA,QAC1B,SAAW,EAAA;AAAA,OACZ,CAAA;AAAA;AAGH,IAAO,OAAA,IAAI,qBAAsB,CAAA,MAAA,EAAQ,MAAM,CAAA;AAAA;AACjD,EAEiB,IAAA;AAAA,EACA,MAAA;AAAA,EAEjB,WAAA,CAAY,cAAoB,MAAuB,EAAA;AACrD,IAAA,IAAA,CAAK,IAAO,GAAA,YAAA;AACZ,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA;AAAA;AAChB,EAEA,MAAM,WAAW,OAAuC,EAAA;AACtD,IAAA,MAAM,GAAM,GAAA,MAAM,IAAK,CAAA,IAAA,CAAK,WAAY,EAAA;A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AA,IAAA,CAAK,MAAO,CAAA,KAAA,CAAM,CAAqC,kCAAA,EAAA,KAAK,CAAE,CAAA,CAAA;AAC9D,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,CAAA,wBAAA,EAA2B,KAAK,CAAA,sBAAA,EAAyB,SAAS,CAAA,CAAA;AAAA,QAClE;AAAA,OACF;AAAA;AACF;AAEJ;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var router = require('./routes/router.cjs.js');
|
|
6
|
+
var plugin = require('./plugin.cjs.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.createRouter = router.createRouter;
|
|
11
|
+
exports.default = plugin.roadmapPlugin;
|
|
12
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { DatabaseService, LoggerService, HttpAuthService, UserInfoService, PermissionsService, CacheService } from '@backstage/backend-plugin-api';
|
|
3
|
+
import { Config } from '@backstage/config';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import { Knex } from 'knex';
|
|
6
|
+
import { NewComment, Comment, NewFeature, Feature, FeatureStatus } from '@rothenbergt/backstage-plugin-roadmap-common';
|
|
7
|
+
|
|
8
|
+
interface RoadmapDatabase {
|
|
9
|
+
/**
|
|
10
|
+
* Add a comment to a feature
|
|
11
|
+
*
|
|
12
|
+
* @param comment - The comment to add
|
|
13
|
+
* @returns The created comment
|
|
14
|
+
* @throws {NotFoundError} When the referenced feature does not exist
|
|
15
|
+
* @throws {ConflictError} When the database operation fails
|
|
16
|
+
*/
|
|
17
|
+
addComment(comment: NewComment): Promise<Comment>;
|
|
18
|
+
/**
|
|
19
|
+
* Get all comments for a feature
|
|
20
|
+
*
|
|
21
|
+
* @param featureId - The ID of the feature
|
|
22
|
+
* @returns Array of comments
|
|
23
|
+
* @throws {NotFoundError} When the feature does not exist
|
|
24
|
+
* @throws {ConflictError} When the database operation fails
|
|
25
|
+
*/
|
|
26
|
+
getCommentsByFeatureId(featureId: string): Promise<Comment[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Add a new feature
|
|
29
|
+
*
|
|
30
|
+
* @param feature - The feature to add
|
|
31
|
+
* @returns The created feature
|
|
32
|
+
* @throws {ConflictError} When the database operation fails
|
|
33
|
+
*/
|
|
34
|
+
addFeature(feature: NewFeature & {
|
|
35
|
+
author: string;
|
|
36
|
+
}): Promise<Feature>;
|
|
37
|
+
/**
|
|
38
|
+
* Get all features
|
|
39
|
+
*
|
|
40
|
+
* @returns Array of all features
|
|
41
|
+
* @throws {ConflictError} When the database operation fails
|
|
42
|
+
*/
|
|
43
|
+
getAllFeatures(): Promise<Feature[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Get a feature by its ID
|
|
46
|
+
*
|
|
47
|
+
* @param id - The ID of the feature
|
|
48
|
+
* @returns The feature
|
|
49
|
+
* @throws {NotFoundError} When the feature does not exist
|
|
50
|
+
* @throws {ConflictError} When the database operation fails
|
|
51
|
+
*/
|
|
52
|
+
getFeatureById(id: string): Promise<Feature>;
|
|
53
|
+
/**
|
|
54
|
+
* Update the status of a feature
|
|
55
|
+
*
|
|
56
|
+
* @param id - The ID of the feature
|
|
57
|
+
* @param status - The new status
|
|
58
|
+
* @returns The updated feature
|
|
59
|
+
* @throws {NotFoundError} When the feature does not exist
|
|
60
|
+
* @throws {ConflictError} When the database operation fails
|
|
61
|
+
*/
|
|
62
|
+
updateFeatureStatus(id: string, status: FeatureStatus): Promise<Feature>;
|
|
63
|
+
/**
|
|
64
|
+
* Toggle a vote on a feature
|
|
65
|
+
*
|
|
66
|
+
* @param featureId - The ID of the feature
|
|
67
|
+
* @param voter - The user voting
|
|
68
|
+
* @returns Boolean indicating if the vote was added (true) or removed (false)
|
|
69
|
+
* @throws {NotFoundError} When the feature does not exist
|
|
70
|
+
* @throws {ConflictError} When the database operation fails
|
|
71
|
+
*/
|
|
72
|
+
toggleVote(featureId: string, voter: string): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Get the vote count for a feature
|
|
75
|
+
*
|
|
76
|
+
* @param featureId - The ID of the feature
|
|
77
|
+
* @returns The number of votes
|
|
78
|
+
* @throws {NotFoundError} When the feature does not exist
|
|
79
|
+
* @throws {ConflictError} When the database operation fails
|
|
80
|
+
*/
|
|
81
|
+
getVoteCount(featureId: string): Promise<number>;
|
|
82
|
+
/**
|
|
83
|
+
* Get vote counts for multiple features
|
|
84
|
+
*
|
|
85
|
+
* @param featureIds - Array of feature IDs
|
|
86
|
+
* @returns Object mapping feature IDs to vote counts
|
|
87
|
+
* @throws {ConflictError} When the database operation fails
|
|
88
|
+
*/
|
|
89
|
+
getVoteCounts(featureIds: string[]): Promise<Record<string, number>>;
|
|
90
|
+
/**
|
|
91
|
+
* Check if a user has voted on a feature
|
|
92
|
+
*
|
|
93
|
+
* @param featureId - The ID of the feature
|
|
94
|
+
* @param voter - The user
|
|
95
|
+
* @returns Boolean indicating if the user has voted
|
|
96
|
+
* @throws {ConflictError} When the database operation fails
|
|
97
|
+
*/
|
|
98
|
+
hasVoted(featureId: string, voter: string): Promise<boolean>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Implementation of the RoadmapDatabase interface using Knex
|
|
103
|
+
*/
|
|
104
|
+
declare class RoadmapDatabaseClient implements RoadmapDatabase {
|
|
105
|
+
static create(options: {
|
|
106
|
+
database: DatabaseService;
|
|
107
|
+
logger: LoggerService;
|
|
108
|
+
}): Promise<RoadmapDatabaseClient>;
|
|
109
|
+
private readonly knex;
|
|
110
|
+
private readonly logger;
|
|
111
|
+
constructor(knexInstance: Knex, logger: LoggerService);
|
|
112
|
+
addComment(comment: NewComment): Promise<Comment>;
|
|
113
|
+
getCommentsByFeatureId(featureId: string): Promise<Comment[]>;
|
|
114
|
+
addFeature(feature: NewFeature & {
|
|
115
|
+
author: string;
|
|
116
|
+
}): Promise<Feature>;
|
|
117
|
+
getAllFeatures(): Promise<Feature[]>;
|
|
118
|
+
getFeatureById(id: string): Promise<Feature>;
|
|
119
|
+
updateFeatureStatus(id: string, status: FeatureStatus): Promise<Feature>;
|
|
120
|
+
toggleVote(featureId: string, voter: string): Promise<boolean>;
|
|
121
|
+
getVoteCount(featureId: string): Promise<number>;
|
|
122
|
+
getVoteCounts(featureIds: string[]): Promise<Record<string, number>>;
|
|
123
|
+
hasVoted(featureId: string, voter: string): Promise<boolean>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Options for configuring the roadmap plugin router
|
|
128
|
+
*/
|
|
129
|
+
interface RouterOptions {
|
|
130
|
+
logger: LoggerService;
|
|
131
|
+
config: Config;
|
|
132
|
+
db: RoadmapDatabaseClient;
|
|
133
|
+
httpAuth: HttpAuthService;
|
|
134
|
+
userInfo: UserInfoService;
|
|
135
|
+
permissions?: PermissionsService;
|
|
136
|
+
cache: CacheService;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Creates the main router for the roadmap plugin
|
|
140
|
+
* Sets up sub-routers for features, comments, votes, and permissions
|
|
141
|
+
*/
|
|
142
|
+
declare function createRouter(options: RouterOptions): Promise<express.Router>;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Backend plugin for the Roadmap feature
|
|
146
|
+
*
|
|
147
|
+
* Provides endpoints for managing roadmap features, comments, and votes
|
|
148
|
+
*/
|
|
149
|
+
declare const roadmapPlugin: _backstage_backend_plugin_api.BackendFeature;
|
|
150
|
+
|
|
151
|
+
export { type RouterOptions, createRouter, roadmapPlugin as default };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var router = require('./routes/router.cjs.js');
|
|
5
|
+
require('express-promise-router');
|
|
6
|
+
require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
7
|
+
require('@backstage/errors');
|
|
8
|
+
require('@backstage/plugin-permission-common');
|
|
9
|
+
var RoadmapDatabaseClient = require('./database/RoadmapDatabaseClient.cjs.js');
|
|
10
|
+
|
|
11
|
+
const roadmapPlugin = backendPluginApi.createBackendPlugin({
|
|
12
|
+
pluginId: "roadmap",
|
|
13
|
+
register(env) {
|
|
14
|
+
env.registerInit({
|
|
15
|
+
deps: {
|
|
16
|
+
httpRouter: backendPluginApi.coreServices.httpRouter,
|
|
17
|
+
logger: backendPluginApi.coreServices.logger,
|
|
18
|
+
config: backendPluginApi.coreServices.rootConfig,
|
|
19
|
+
database: backendPluginApi.coreServices.database,
|
|
20
|
+
userInfo: backendPluginApi.coreServices.userInfo,
|
|
21
|
+
httpAuth: backendPluginApi.coreServices.httpAuth,
|
|
22
|
+
permissions: backendPluginApi.coreServices.permissions,
|
|
23
|
+
cache: backendPluginApi.coreServices.cache
|
|
24
|
+
},
|
|
25
|
+
async init({
|
|
26
|
+
httpRouter,
|
|
27
|
+
logger,
|
|
28
|
+
config,
|
|
29
|
+
database,
|
|
30
|
+
userInfo,
|
|
31
|
+
httpAuth,
|
|
32
|
+
permissions,
|
|
33
|
+
cache
|
|
34
|
+
}) {
|
|
35
|
+
const db = await RoadmapDatabaseClient.RoadmapDatabaseClient.create({
|
|
36
|
+
database,
|
|
37
|
+
logger
|
|
38
|
+
});
|
|
39
|
+
const permissionEnabled = config.getOptionalBoolean("permission.enabled") ?? false;
|
|
40
|
+
if (!permissionEnabled) {
|
|
41
|
+
logger.warn(
|
|
42
|
+
"Permissions are disabled. Using configArray for admin users."
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
httpRouter.use(
|
|
46
|
+
await router.createRouter({
|
|
47
|
+
logger,
|
|
48
|
+
config,
|
|
49
|
+
db,
|
|
50
|
+
userInfo,
|
|
51
|
+
httpAuth,
|
|
52
|
+
permissions: permissionEnabled ? permissions : void 0,
|
|
53
|
+
cache
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
httpRouter.addAuthPolicy({
|
|
57
|
+
path: "/health",
|
|
58
|
+
allow: "unauthenticated"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
exports.roadmapPlugin = roadmapPlugin;
|
|
66
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["import {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './routes';\nimport { RoadmapDatabaseClient } from './database/RoadmapDatabaseClient';\n\n/**\n * Backend plugin for the Roadmap feature\n *\n * Provides endpoints for managing roadmap features, comments, and votes\n */\nexport const roadmapPlugin = createBackendPlugin({\n pluginId: 'roadmap',\n register(env) {\n env.registerInit({\n deps: {\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n database: coreServices.database,\n userInfo: coreServices.userInfo,\n httpAuth: coreServices.httpAuth,\n permissions: coreServices.permissions,\n cache: coreServices.cache,\n },\n async init({\n httpRouter,\n logger,\n config,\n database,\n userInfo,\n httpAuth,\n permissions,\n cache,\n }) {\n const db = await RoadmapDatabaseClient.create({\n database,\n logger,\n });\n\n const permissionEnabled =\n config.getOptionalBoolean('permission.enabled') ?? false;\n\n if (!permissionEnabled) {\n logger.warn(\n 'Permissions are disabled. Using configArray for admin users.',\n );\n }\n\n httpRouter.use(\n await createRouter({\n logger,\n config,\n db,\n userInfo,\n httpAuth,\n permissions: permissionEnabled ? permissions : undefined,\n cache,\n }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","RoadmapDatabaseClient","createRouter"],"mappings":";;;;;;;;;;AAYO,MAAM,gBAAgBA,oCAAoB,CAAA;AAAA,EAC/C,QAAU,EAAA,SAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,YAAYC,6BAAa,CAAA,UAAA;AAAA,QACzB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,aAAaA,6BAAa,CAAA,WAAA;AAAA,QAC1B,OAAOA,6BAAa,CAAA;AAAA,OACtB;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,QACT,UAAA;AAAA,QACA,MAAA;AAAA,QACA,MAAA;AAAA,QACA,QAAA;AAAA,QACA,QAAA;AAAA,QACA,QAAA;AAAA,QACA,WAAA;AAAA,QACA;AAAA,OACC,EAAA;AACD,QAAM,MAAA,EAAA,GAAK,MAAMC,2CAAA,CAAsB,MAAO,CAAA;AAAA,UAC5C,QAAA;AAAA,UACA;AAAA,SACD,CAAA;AAED,QAAA,MAAM,iBACJ,GAAA,MAAA,CAAO,kBAAmB,CAAA,oBAAoB,CAAK,IAAA,KAAA;AAErD,QAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,UAAO,MAAA,CAAA,IAAA;AAAA,YACL;AAAA,WACF;AAAA;AAGF,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMC,mBAAa,CAAA;AAAA,YACjB,MAAA;AAAA,YACA,MAAA;AAAA,YACA,EAAA;AAAA,YACA,QAAA;AAAA,YACA,QAAA;AAAA,YACA,WAAA,EAAa,oBAAoB,WAAc,GAAA,MAAA;AAAA,YAC/C;AAAA,WACD;AAAA,SACH;AACA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,IAAM,EAAA,SAAA;AAAA,UACN,KAAO,EAAA;AAAA,SACR,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Router = require('express-promise-router');
|
|
4
|
+
var CommentService = require('../services/CommentService.cjs.js');
|
|
5
|
+
var PermissionService = require('../services/PermissionService.cjs.js');
|
|
6
|
+
var errors = require('@backstage/errors');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
|
|
11
|
+
|
|
12
|
+
function commentsRouter(options) {
|
|
13
|
+
const { logger, db } = options;
|
|
14
|
+
const router = Router__default.default();
|
|
15
|
+
const commentService = new CommentService.CommentService(db, logger);
|
|
16
|
+
const permissionService = new PermissionService.PermissionService(options);
|
|
17
|
+
router.post("/", async (req, res, next) => {
|
|
18
|
+
try {
|
|
19
|
+
const username = await permissionService.getUsername(req);
|
|
20
|
+
const { featureId, text } = req.body;
|
|
21
|
+
const comment = await commentService.addComment({
|
|
22
|
+
featureId,
|
|
23
|
+
text,
|
|
24
|
+
author: username
|
|
25
|
+
});
|
|
26
|
+
res.status(201).json(comment);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
next(error);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
router.get("/", async (req, res, next) => {
|
|
32
|
+
try {
|
|
33
|
+
const { featureId } = req.query;
|
|
34
|
+
if (!featureId || typeof featureId !== "string") {
|
|
35
|
+
throw new errors.InputError("featureId is required and must be a string");
|
|
36
|
+
}
|
|
37
|
+
const comments = await commentService.getCommentsByFeatureId(featureId);
|
|
38
|
+
res.status(200).json(comments);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
next(error);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return router;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.commentsRouter = commentsRouter;
|
|
47
|
+
//# sourceMappingURL=commentsRouter.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commentsRouter.cjs.js","sources":["../../src/routes/commentsRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { CommentService } from '../services/CommentService';\nimport { PermissionService } from '../services/PermissionService';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Router for comment-related endpoints\n */\nexport function commentsRouter(options: RouterOptions): express.Router {\n const { logger, db } = options;\n const router = Router();\n\n // Initialize services\n const commentService = new CommentService(db, logger);\n const permissionService = new PermissionService(options);\n\n // Add a comment to a feature\n router.post('/', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const { featureId, text } = req.body;\n\n const comment = await commentService.addComment({\n featureId,\n text,\n author: username,\n });\n\n res.status(201).json(comment);\n } catch (error) {\n next(error);\n }\n });\n\n // Get comments for a specific feature\n router.get('/', async (req, res, next) => {\n try {\n const { featureId } = req.query;\n if (!featureId || typeof featureId !== 'string') {\n throw new InputError('featureId is required and must be a string');\n }\n\n const comments = await commentService.getCommentsByFeatureId(featureId);\n res.status(200).json(comments);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","CommentService","PermissionService","InputError"],"mappings":";;;;;;;;;;;AAUO,SAAS,eAAe,OAAwC,EAAA;AACrE,EAAM,MAAA,EAAE,MAAQ,EAAA,EAAA,EAAO,GAAA,OAAA;AACvB,EAAA,MAAM,SAASA,uBAAO,EAAA;AAGtB,EAAA,MAAM,cAAiB,GAAA,IAAIC,6BAAe,CAAA,EAAA,EAAI,MAAM,CAAA;AACpD,EAAM,MAAA,iBAAA,GAAoB,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
var FeatureService = require('../services/FeatureService.cjs.js');
|
|
5
|
+
var PermissionService = require('../services/PermissionService.cjs.js');
|
|
6
|
+
var errors = require('@backstage/errors');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
|
|
11
|
+
|
|
12
|
+
function featuresRouter(options) {
|
|
13
|
+
const { logger, db } = options;
|
|
14
|
+
const router = Router__default.default();
|
|
15
|
+
const featureService = new FeatureService.FeatureService(db, logger);
|
|
16
|
+
const permissionService = new PermissionService.PermissionService(options);
|
|
17
|
+
router.post("/", async (req, res, next) => {
|
|
18
|
+
try {
|
|
19
|
+
const username = await permissionService.getUsername(req);
|
|
20
|
+
const newFeature = req.body;
|
|
21
|
+
const feature = await featureService.addFeature(newFeature, username);
|
|
22
|
+
res.status(201).json(feature);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
next(error);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
router.get("/", async (_, res, next) => {
|
|
28
|
+
try {
|
|
29
|
+
const features = await featureService.getAllFeatures();
|
|
30
|
+
res.status(200).json(features);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
next(error);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
router.get("/:id", async (req, res, next) => {
|
|
36
|
+
try {
|
|
37
|
+
const { id } = req.params;
|
|
38
|
+
const feature = await featureService.getFeatureById(id);
|
|
39
|
+
res.status(200).json(feature);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
next(error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
router.put("/:id/status", async (req, res, next) => {
|
|
45
|
+
try {
|
|
46
|
+
const { id } = req.params;
|
|
47
|
+
const status = req.body.status;
|
|
48
|
+
const username = await permissionService.getUsername(req);
|
|
49
|
+
const isAdmin = await permissionService.isRoadmapAdmin(req, username);
|
|
50
|
+
if (!isAdmin) {
|
|
51
|
+
throw new errors.NotAllowedError("User is not a Roadmap admin");
|
|
52
|
+
}
|
|
53
|
+
const updatedFeature = await featureService.updateFeatureStatus(
|
|
54
|
+
id,
|
|
55
|
+
status
|
|
56
|
+
);
|
|
57
|
+
res.status(200).json(updatedFeature);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
next(error);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return router;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.featuresRouter = featuresRouter;
|
|
66
|
+
//# sourceMappingURL=featuresRouter.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"featuresRouter.cjs.js","sources":["../../src/routes/featuresRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { FeatureStatus } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { FeatureService } from '../services/FeatureService';\nimport { PermissionService } from '../services/PermissionService';\n\nimport { NotAllowedError } from '@backstage/errors';\n/**\n * Router for feature-related endpoints\n */\nexport function featuresRouter(options: RouterOptions): express.Router {\n const { logger, db } = options;\n const router = Router();\n\n // Initialize services\n const featureService = new FeatureService(db, logger);\n const permissionService = new PermissionService(options);\n\n // Create new feature\n router.post('/', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const newFeature = req.body;\n\n const feature = await featureService.addFeature(newFeature, username);\n res.status(201).json(feature);\n } catch (error) {\n next(error);\n }\n });\n\n // Get all features\n router.get('/', async (_, res, next) => {\n try {\n const features = await featureService.getAllFeatures();\n res.status(200).json(features);\n } catch (error) {\n next(error);\n }\n });\n\n // Get feature by ID\n router.get('/:id', async (req, res, next) => {\n try {\n const { id } = req.params;\n const feature = await featureService.getFeatureById(id);\n res.status(200).json(feature);\n } catch (error) {\n next(error);\n }\n });\n\n // Update feature status (admin only)\n router.put('/:id/status', async (req, res, next) => {\n try {\n const { id } = req.params;\n const status = req.body.status as FeatureStatus;\n\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.isRoadmapAdmin(req, username);\n\n if (!isAdmin) {\n throw new NotAllowedError('User is not a Roadmap admin');\n }\n\n const updatedFeature = await featureService.updateFeatureStatus(\n id,\n status,\n );\n res.status(200).json(updatedFeature);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","FeatureService","PermissionService","NotAllowedError"],"mappings":";;;;;;;;;;;AAWO,SAAS,eAAe,OAAwC,EAAA;AACrE,EAAM,MAAA,EAAE,MAAQ,EAAA,EAAA,EAAO,GAAA,OAAA;AACvB,EAAA,MAAM,SAASA,uBAAO,EAAA;AAGtB,EAAA,MAAM,cAAiB,GAAA,IAAIC,6BAAe,CAAA,EAAA,EAAI,MAAM,CAAA;AACpD,EAAM,MAAA,iBAAA,GAAoB,IAAIC,mCAAA,CAAkB,OAAO,CAAA;AAGvD,EAAA,MAAA,CAAO,IAAK,CAAA,GAAA,EAAK,OAAO,GAAA,EAAK,KAAK,IAAS,KAAA;AACzC,IAAI,IAAA;AACF,MAAA,MAAM,QAAW,GAAA,MAAM,iBAAkB,CAAA,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,aAAa,GAAI,CAAA,IAAA;AAEvB,MAAA,MAAM,OAAU,GAAA,MAAM,cAAe,CAAA,UAAA,CAAW,YAAY,QAAQ,CAAA;AACpE,MAAA,GAAA,CAAI,MAAO,CAAA,GAAG,CAAE,CAAA,IAAA,CAAK,OAAO,CAAA;AAAA,aACrB,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA;AACZ,GACD,CAAA;AAGD,EAAA,MAAA,CAAO,GAAI,CAAA,GAAA,EAAK,OAAO,CAAA,EAAG,KAAK,IAAS,KAAA;AACtC,IAAI,IAAA;AACF,MAAM,MAAA,QAAA,GAAW,MAAM,cAAA,CAAe,cAAe,EAAA;AACrD,MAAA,GAAA,CAAI,MAAO,CAAA,GAAG,CAAE,CAAA,IAAA,CAAK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AAA;AACT;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Router = require('express-promise-router');
|
|
4
|
+
var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
5
|
+
var PermissionService = require('../services/PermissionService.cjs.js');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
|
|
10
|
+
|
|
11
|
+
function permissionCheckRouter(options) {
|
|
12
|
+
const router = Router__default.default();
|
|
13
|
+
const permissionService = new PermissionService.PermissionService(options);
|
|
14
|
+
router.get("/check-admin", async (req, res, next) => {
|
|
15
|
+
try {
|
|
16
|
+
const username = await permissionService.getUsername(req);
|
|
17
|
+
const isAdmin = await permissionService.checkPermission(
|
|
18
|
+
req,
|
|
19
|
+
username,
|
|
20
|
+
backstagePluginRoadmapCommon.roadmapAdminPermission
|
|
21
|
+
);
|
|
22
|
+
res.json(isAdmin);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
next(error);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return router;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.permissionCheckRouter = permissionCheckRouter;
|
|
31
|
+
//# sourceMappingURL=permissionCheckRouter.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissionCheckRouter.cjs.js","sources":["../../src/routes/permissionCheckRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { roadmapAdminPermission } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { PermissionService } from '../services/PermissionService';\n\n/**\n * Router for permission-checking endpoints\n */\nexport function permissionCheckRouter(options: RouterOptions): express.Router {\n const router = Router();\n\n // Initialize service\n const permissionService = new PermissionService(options);\n\n // Check if the current user is an admin\n router.get('/check-admin', async (req, res, next) => {\n try {\n const username = await permissionService.getUsername(req);\n const isAdmin = await permissionService.checkPermission(\n req,\n username,\n roadmapAdminPermission,\n );\n\n res.json(isAdmin);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","PermissionService","roadmapAdminPermission"],"mappings":";;;;;;;;;;AASO,SAAS,sBAAsB,OAAwC,EAAA;AAC5E,EAAA,MAAM,SAASA,uBAAO,EAAA;AAGtB,EAAM,MAAA,iBAAA,GAAoB,IAAIC,mCAAA,CAAkB,OAAO,CAAA;AAGvD,EAAA,MAAA,CAAO,GAAI,CAAA,cAAA,EAAgB,OAAO,GAAA,EAAK,KAAK,IAAS,KAAA;AACnD,IAAI,IAAA;AACF,MAAA,MAAM,QAAW,GAAA,MAAM,iBAAkB,CAAA,WAAA,CAAY,GAAG,CAAA;AACxD,MAAM,MAAA,OAAA,GAAU,MAAM,iBAAkB,CAAA,eAAA;AAAA,QACtC,GAAA;AAAA,QACA,QAAA;AAAA,QACAC;AAAA,OACF;AAEA,MAAA,GAAA,CAAI,KAAK,OAAO,CAAA;AAAA,aACT,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA;AACZ,GACD,CAAA;AAED,EAAO,OAAA,MAAA;AACT;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var rootHttpRouter = require('@backstage/backend-defaults/rootHttpRouter');
|
|
4
|
+
var express = require('express');
|
|
5
|
+
var Router = require('express-promise-router');
|
|
6
|
+
var pluginPermissionNode = require('@backstage/plugin-permission-node');
|
|
7
|
+
var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
8
|
+
var commentsRouter = require('./commentsRouter.cjs.js');
|
|
9
|
+
var featuresRouter = require('./featuresRouter.cjs.js');
|
|
10
|
+
var votesRouter = require('./votesRouter.cjs.js');
|
|
11
|
+
var permissionCheckRouter = require('./permissionCheckRouter.cjs.js');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var express__default = /*#__PURE__*/_interopDefaultCompat(express);
|
|
16
|
+
var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
|
|
17
|
+
|
|
18
|
+
async function createRouter(options) {
|
|
19
|
+
const { logger, config } = options;
|
|
20
|
+
const router = Router__default.default();
|
|
21
|
+
router.use(express__default.default.json());
|
|
22
|
+
const permissionIntegrationRouter = pluginPermissionNode.createPermissionIntegrationRouter({
|
|
23
|
+
permissions: backstagePluginRoadmapCommon.roadmapPermissions
|
|
24
|
+
});
|
|
25
|
+
router.get("/health", (_, response) => {
|
|
26
|
+
logger.info("PONG!");
|
|
27
|
+
response.json({ status: "ok" });
|
|
28
|
+
});
|
|
29
|
+
router.use(permissionIntegrationRouter);
|
|
30
|
+
router.use("/comments", commentsRouter.commentsRouter(options));
|
|
31
|
+
router.use("/features", featuresRouter.featuresRouter(options));
|
|
32
|
+
router.use("/votes", votesRouter.votesRouter(options));
|
|
33
|
+
router.use("/permissions", permissionCheckRouter.permissionCheckRouter(options));
|
|
34
|
+
const middleware = rootHttpRouter.MiddlewareFactory.create({ logger, config });
|
|
35
|
+
router.use(middleware.error());
|
|
36
|
+
return router;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.createRouter = createRouter;
|
|
40
|
+
//# sourceMappingURL=router.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.cjs.js","sources":["../../src/routes/router.ts"],"sourcesContent":["import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport { CacheService, LoggerService } from '@backstage/backend-plugin-api';\nimport { Config } from '@backstage/config';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { RoadmapDatabaseClient } from '../database/RoadmapDatabaseClient';\nimport {\n HttpAuthService,\n UserInfoService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport { createPermissionIntegrationRouter } from '@backstage/plugin-permission-node';\nimport { roadmapPermissions } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { commentsRouter } from './commentsRouter';\nimport { featuresRouter } from './featuresRouter';\nimport { votesRouter } from './votesRouter';\nimport { permissionCheckRouter } from './permissionCheckRouter';\n\n/**\n * Options for configuring the roadmap plugin router\n */\nexport interface RouterOptions {\n logger: LoggerService;\n config: Config;\n db: RoadmapDatabaseClient;\n httpAuth: HttpAuthService;\n userInfo: UserInfoService;\n permissions?: PermissionsService;\n cache: CacheService;\n}\n\n/**\n * Creates the main router for the roadmap plugin\n * Sets up sub-routers for features, comments, votes, and permissions\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { logger, config } = options;\n\n const router = Router();\n router.use(express.json());\n\n // Set up permission integration for Backstage permission framework\n const permissionIntegrationRouter = createPermissionIntegrationRouter({\n permissions: roadmapPermissions,\n });\n\n // Health check endpoint\n router.get('/health', (_, response) => {\n logger.info('PONG!');\n response.json({ status: 'ok' });\n });\n\n router.use(permissionIntegrationRouter);\n\n // Register sub-routers\n router.use('/comments', commentsRouter(options));\n router.use('/features', featuresRouter(options));\n router.use('/votes', votesRouter(options));\n router.use('/permissions', permissionCheckRouter(options));\n\n // Add error handling middleware\n const middleware = MiddlewareFactory.create({ logger, config });\n router.use(middleware.error());\n\n return router;\n}\n"],"names":["Router","express","createPermissionIntegrationRouter","roadmapPermissions","commentsRouter","featuresRouter","votesRouter","permissionCheckRouter","MiddlewareFactory"],"mappings":";;;;;;;;;;;;;;;;;AAmCA,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAM,MAAA,EAAE,MAAQ,EAAA,MAAA,EAAW,GAAA,OAAA;AAE3B,EAAA,MAAM,SAASA,uBAAO,EAAA;AACtB,EAAO,MAAA,CAAA,GAAA,CAAIC,wBAAQ,CAAA,IAAA,EAAM,CAAA;AAGzB,EAAA,MAAM,8BAA8BC,sDAAkC,CAAA;AAAA,IACpE,WAAa,EAAAC;AAAA,GACd,CAAA;AAGD,EAAA,MAAA,CAAO,GAAI,CAAA,SAAA,EAAW,CAAC,CAAA,EAAG,QAAa,KAAA;AACrC,IAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACnB,IAAA,QAAA,CAAS,IAAK,CAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA;AAAA,GAC/B,CAAA;AAED,EAAA,MAAA,CAAO,IAAI,2BAA2B,CAAA;AAGtC,EAAA,MAAA,CAAO,GAAI,CAAA,WAAA,EAAaC,6BAAe,CAAA,OAAO,CAAC,CAAA;AAC/C,EAAA,MAAA,CAAO,GAAI,CAAA,WAAA,EAAaC,6BAAe,CAAA,OAAO,CAAC,CAAA;AAC/C,EAAA,MAAA,CAAO,GAAI,CAAA,QAAA,EAAUC,uBAAY,CAAA,OAAO,CAAC,CAAA;AACzC,EAAA,MAAA,CAAO,GAAI,CAAA,cAAA,EAAgBC,2CAAsB,CAAA,OAAO,CAAC,CAAA;AAGzD,EAAA,MAAM,aAAaC,gCAAkB,CAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,QAAQ,CAAA;AAC9D,EAAO,MAAA,CAAA,GAAA,CAAI,UAAW,CAAA,KAAA,EAAO,CAAA;AAE7B,EAAO,OAAA,MAAA;AACT;;;;"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Router = require('express-promise-router');
|
|
4
|
+
var VoteService = require('../services/VoteService.cjs.js');
|
|
5
|
+
var PermissionService = require('../services/PermissionService.cjs.js');
|
|
6
|
+
var errors = require('@backstage/errors');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
|
|
11
|
+
|
|
12
|
+
function votesRouter(options) {
|
|
13
|
+
const { logger, db } = options;
|
|
14
|
+
const router = Router__default.default();
|
|
15
|
+
const voteService = new VoteService.VoteService(db, logger);
|
|
16
|
+
const permissionService = new PermissionService.PermissionService(options);
|
|
17
|
+
router.post("/:featureId", async (req, res, next) => {
|
|
18
|
+
try {
|
|
19
|
+
const featureId = req.params.featureId;
|
|
20
|
+
if (!featureId) {
|
|
21
|
+
throw new errors.InputError("Feature ID is required");
|
|
22
|
+
}
|
|
23
|
+
const username = await permissionService.getUsername(req);
|
|
24
|
+
const voteAdded = await voteService.toggleVote(featureId, username);
|
|
25
|
+
const newVoteCount = await voteService.getVoteCount(featureId);
|
|
26
|
+
res.status(200).json({
|
|
27
|
+
voteAdded,
|
|
28
|
+
voteCount: newVoteCount
|
|
29
|
+
});
|
|
30
|
+
} catch (error) {
|
|
31
|
+
next(error);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
router.get("/:featureId/count", async (req, res, next) => {
|
|
35
|
+
try {
|
|
36
|
+
const featureId = req.params.featureId;
|
|
37
|
+
if (!featureId) {
|
|
38
|
+
throw new errors.InputError("Feature ID is required");
|
|
39
|
+
}
|
|
40
|
+
const count = await voteService.getVoteCount(featureId);
|
|
41
|
+
res.json(count);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
next(error);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
router.get("/counts", async (req, res, next) => {
|
|
47
|
+
try {
|
|
48
|
+
const idsParam = req.query.ids;
|
|
49
|
+
if (!idsParam || typeof idsParam !== "string" || idsParam === "") {
|
|
50
|
+
res.json({});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const featureIds = idsParam.split(",");
|
|
54
|
+
if (featureIds.length === 0) {
|
|
55
|
+
res.json({});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const voteCounts = await voteService.getVoteCounts(featureIds);
|
|
59
|
+
res.json(voteCounts);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
next(error);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
router.get("/:featureId/user", async (req, res, next) => {
|
|
65
|
+
try {
|
|
66
|
+
const featureId = req.params.featureId;
|
|
67
|
+
if (!featureId) {
|
|
68
|
+
throw new errors.InputError("Feature ID is required");
|
|
69
|
+
}
|
|
70
|
+
const username = await permissionService.getUsername(req);
|
|
71
|
+
const hasVoted = await voteService.hasVoted(featureId, username);
|
|
72
|
+
res.json(hasVoted);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
next(error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return router;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
exports.votesRouter = votesRouter;
|
|
81
|
+
//# sourceMappingURL=votesRouter.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"votesRouter.cjs.js","sources":["../../src/routes/votesRouter.ts"],"sourcesContent":["import express from 'express';\nimport Router from 'express-promise-router';\nimport { RouterOptions } from './router';\nimport { VoteService } from '../services/VoteService';\nimport { PermissionService } from '../services/PermissionService';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Router for vote-related endpoints\n */\nexport function votesRouter(options: RouterOptions): express.Router {\n const { logger, db } = options;\n const router = Router();\n\n // Initialize services\n const voteService = new VoteService(db, logger);\n const permissionService = new PermissionService(options);\n\n // Toggle vote for a feature\n router.post('/:featureId', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const username = await permissionService.getUsername(req);\n const voteAdded = await voteService.toggleVote(featureId, username);\n const newVoteCount = await voteService.getVoteCount(featureId);\n\n res.status(200).json({\n voteAdded,\n voteCount: newVoteCount,\n });\n } catch (error) {\n next(error);\n }\n });\n\n // Get vote count for a feature\n router.get('/:featureId/count', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const count = await voteService.getVoteCount(featureId);\n res.json(count);\n } catch (error) {\n next(error);\n }\n });\n\n // Get vote counts for multiple features\n router.get('/counts', async (req, res, next) => {\n try {\n const idsParam = req.query.ids;\n\n // Handle empty parameter case gracefully\n if (!idsParam || typeof idsParam !== 'string' || idsParam === '') {\n res.json({});\n return;\n }\n\n const featureIds = idsParam.split(',');\n\n if (featureIds.length === 0) {\n res.json({});\n return;\n }\n\n const voteCounts = await voteService.getVoteCounts(featureIds);\n res.json(voteCounts);\n } catch (error) {\n next(error);\n }\n });\n\n // Check if a user has voted on a feature\n router.get('/:featureId/user', async (req, res, next) => {\n try {\n const featureId = req.params.featureId;\n\n if (!featureId) {\n throw new InputError('Feature ID is required');\n }\n\n const username = await permissionService.getUsername(req);\n const hasVoted = await voteService.hasVoted(featureId, username);\n\n res.json(hasVoted);\n } catch (error) {\n next(error);\n }\n });\n\n return router;\n}\n"],"names":["Router","VoteService","PermissionService","InputError"],"mappings":";;;;;;;;;;;AAUO,SAAS,YAAY,OAAwC,EAAA;AAClE,EAAM,MAAA,EAAE,MAAQ,EAAA,EAAA,EAAO,GAAA,OAAA;AACvB,EAAA,MAAM,SAASA,uBAAO,EAAA;AAGtB,EAAA,MAAM,WAAc,GAAA,IAAIC,uBAAY,CAAA,EAAA,EAAI,MAAM,CAAA;AAC9C,EAAM,MAAA,iBAAA,GAAoB,IAAIC,mCAAA,CAAkB,OAAO,CAAA;AAGvD,EAAA,MAAA,CAAO,IAAK,CAAA,aAAA,EAAe,OAAO,GAAA,EAAK,KAAK,IAAS,KAAA;AACnD,IAAI,IAAA;AACF,MAAM,MAAA,SAAA,GAAY,IAAI,MAAO,CAAA,SAAA;AAE7B,MAAA,IAAI,CAAC,SAAW,EAAA;AACd,QAAM,MAAA,IAAIC,kBAAW,wBAAwB,CAAA;AAAA;AAG/C,MAAA,MAAM,QAAW,GAAA,MAAM,iBAAkB,CAAA,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,SAAY,GAAA,MAAM,WAAY,CAAA,UAAA,CAAW,WAAW,QAAQ,CAAA;AAClE,MA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MAAM,WAAY,CAAA,aAAA,CAAc,UAAU,CAAA;AAC7D,MAAA,GAAA,CAAI,KAAK,UAAU,CAAA;AAAA,aACZ,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA;AACZ,GACD,CAAA;AAGD,EAAA,MAAA,CAAO,GAAI,CAAA,kBAAA,EAAoB,OAAO,GAAA,EAAK,KAAK,IAAS,KAAA;AACvD,IAAI,IAAA;AACF,MAAM,MAAA,SAAA,GAAY,IAAI,MAAO,CAAA,SAAA;AAE7B,MAAA,IAAI,CAAC,SAAW,EAAA;AACd,QAAM,MAAA,IAAIA,kBAAW,wBAAwB,CAAA;AAAA;AAG/C,MAAA,MAAM,QAAW,GAAA,MAAM,iBAAkB,CAAA,WAAA,CAAY,GAAG,CAAA;AACxD,MAAA,MAAM,QAAW,GAAA,MAAM,WAAY,CAAA,QAAA,CAAS,WAAW,QAAQ,CAAA;AAE/D,MAAA,GAAA,CAAI,KAAK,QAAQ,CAAA;AAAA,aACV,KAAO,EAAA;AACd,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA;AACZ,GACD,CAAA;AAED,EAAO,OAAA,MAAA;AACT;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var errors = require('@backstage/errors');
|
|
4
|
+
|
|
5
|
+
class CommentService {
|
|
6
|
+
constructor(db, logger) {
|
|
7
|
+
this.db = db;
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validates a comment before adding it
|
|
12
|
+
*/
|
|
13
|
+
validateNewComment(comment) {
|
|
14
|
+
if (!comment.featureId) {
|
|
15
|
+
throw new errors.InputError("Feature ID is required");
|
|
16
|
+
}
|
|
17
|
+
if (!comment.text || comment.text.trim() === "") {
|
|
18
|
+
throw new errors.InputError("Comment text is required and cannot be empty");
|
|
19
|
+
}
|
|
20
|
+
if (comment.text.length > 1e3) {
|
|
21
|
+
throw new errors.InputError(
|
|
22
|
+
"Comment text cannot be longer than 1000 characters"
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async addComment(comment) {
|
|
27
|
+
this.logger.info(`Adding comment to feature ${comment.featureId}`);
|
|
28
|
+
this.validateNewComment(comment);
|
|
29
|
+
return this.db.addComment(comment);
|
|
30
|
+
}
|
|
31
|
+
async getCommentsByFeatureId(featureId) {
|
|
32
|
+
this.logger.info(`Fetching comments for feature ${featureId}`);
|
|
33
|
+
return this.db.getCommentsByFeatureId(featureId);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.CommentService = CommentService;
|
|
38
|
+
//# sourceMappingURL=CommentService.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommentService.cjs.js","sources":["../../src/services/CommentService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatabase } from '../database/types';\nimport { CommentServiceInterface } from './types';\nimport {\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Implementation of the Comment Service\n */\nexport class CommentService implements CommentServiceInterface {\n constructor(\n private readonly db: RoadmapDatabase,\n private readonly logger: LoggerService,\n ) {}\n\n /**\n * Validates a comment before adding it\n */\n private validateNewComment(comment: NewComment): void {\n if (!comment.featureId) {\n throw new InputError('Feature ID is required');\n }\n\n if (!comment.text || comment.text.trim() === '') {\n throw new InputError('Comment text is required and cannot be empty');\n }\n\n if (comment.text.length > 1000) {\n throw new InputError(\n 'Comment text cannot be longer than 1000 characters',\n );\n }\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n this.logger.info(`Adding comment to feature ${comment.featureId}`);\n this.validateNewComment(comment);\n return this.db.addComment(comment);\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n this.logger.info(`Fetching comments for feature ${featureId}`);\n return this.db.getCommentsByFeat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');
|
|
4
|
+
var errors = require('@backstage/errors');
|
|
5
|
+
|
|
6
|
+
class FeatureService {
|
|
7
|
+
constructor(db, logger) {
|
|
8
|
+
this.db = db;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Validates a feature before adding it
|
|
13
|
+
*/
|
|
14
|
+
validateNewFeature(feature) {
|
|
15
|
+
if (!feature.title || feature.title.trim() === "") {
|
|
16
|
+
throw new errors.InputError("Title is required and cannot be empty");
|
|
17
|
+
}
|
|
18
|
+
if (!feature.description || feature.description.trim() === "") {
|
|
19
|
+
throw new errors.InputError("Description is required and cannot be empty");
|
|
20
|
+
}
|
|
21
|
+
if (feature.title.length > 100) {
|
|
22
|
+
throw new errors.InputError("Title cannot be longer than 100 characters");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Validates a feature status before updating
|
|
27
|
+
*/
|
|
28
|
+
validateStatus(status) {
|
|
29
|
+
const validStatuses = Object.values(backstagePluginRoadmapCommon.FeatureStatus);
|
|
30
|
+
if (!validStatuses.includes(status)) {
|
|
31
|
+
throw new errors.InputError(
|
|
32
|
+
`Invalid status: ${status}. Must be one of: ${validStatuses.join(
|
|
33
|
+
", "
|
|
34
|
+
)}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async getAllFeatures() {
|
|
39
|
+
this.logger.info("Fetching all features");
|
|
40
|
+
return this.db.getAllFeatures();
|
|
41
|
+
}
|
|
42
|
+
async getFeatureById(id) {
|
|
43
|
+
this.logger.info(`Fetching feature with id ${id}`);
|
|
44
|
+
return this.db.getFeatureById(id);
|
|
45
|
+
}
|
|
46
|
+
async addFeature(feature, author) {
|
|
47
|
+
this.logger.info(`Adding new feature: ${feature.title} by ${author}`);
|
|
48
|
+
this.validateNewFeature(feature);
|
|
49
|
+
return this.db.addFeature({ ...feature, author });
|
|
50
|
+
}
|
|
51
|
+
async updateFeatureStatus(id, status) {
|
|
52
|
+
this.logger.info(`Updating feature ${id} status to ${status}`);
|
|
53
|
+
this.validateStatus(status);
|
|
54
|
+
return this.db.updateFeatureStatus(id, status);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.FeatureService = FeatureService;
|
|
59
|
+
//# sourceMappingURL=FeatureService.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeatureService.cjs.js","sources":["../../src/services/FeatureService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatabase } from '../database/types';\nimport { FeatureServiceInterface } from './types';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Implementation of the Feature Service\n */\nexport class FeatureService implements FeatureServiceInterface {\n constructor(\n private readonly db: RoadmapDatabase,\n private readonly logger: LoggerService,\n ) {}\n\n /**\n * Validates a feature before adding it\n */\n private validateNewFeature(feature: NewFeature): void {\n if (!feature.title || feature.title.trim() === '') {\n throw new InputError('Title is required and cannot be empty');\n }\n\n if (!feature.description || feature.description.trim() === '') {\n throw new InputError('Description is required and cannot be empty');\n }\n\n if (feature.title.length > 100) {\n throw new InputError('Title cannot be longer than 100 characters');\n }\n }\n\n /**\n * Validates a feature status before updating\n */\n private validateStatus(status: FeatureStatus): void {\n const validStatuses = Object.values(FeatureStatus);\n if (!validStatuses.includes(status)) {\n throw new InputError(\n `Invalid status: ${status}. Must be one of: ${validStatuses.join(\n ', ',\n )}`,\n );\n }\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n this.logger.info('Fetching all features');\n return this.db.getAllFeatures();\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n this.logger.info(`Fetching feature with id ${id}`);\n return this.db.getFeatureById(id);\n }\n\n async addFeature(feature: NewFeature, author: string): Promise<Feature> {\n this.logger.info(`Adding new feature: ${feature.title} by ${author}`);\n this.validateNewFeature(feature);\n return this.db.addFeature({ ...feature, author });\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n this.logger.info(`Updating feature ${id} status to ${status}`);\n this.validateStatus(status);\n return this.db.updateFeatureStatus(id, status);\n }\n}\n"],"names":["InputError","FeatureStatus"],"mappings":";;;;;AAaO,MAAM,cAAkD,CAAA;AAAA,EAC7D,WAAA,CACmB,IACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAChB;AAAA;AAAA;AAAA,EAKK,mBAAmB,OAA2B,EAAA;AACpD,IAAA,IAAI,CAAC,OAAQ,CAAA,KAAA,IAAS,QAAQ,KAAM,CAAA,IAAA,OAAW,EAAI,EAAA;AACjD,MAAM,MAAA,IAAIA,kBAAW,uCAAuC,CAAA;AAAA;AAG9D,IAAA,IAAI,CAAC,OAAQ,CAAA,WAAA,IAAe,QAAQ,WAAY,CAAA,IAAA,OAAW,EAAI,EAAA;AAC7D,MAAM,MAAA,IAAIA,kBAAW,6CAA6C,CAAA;AAAA;AAGpE,IAAI,IAAA,OAAA,CAAQ,KAAM,CAAA,MAAA,GAAS,GAAK,EAAA;AAC9B,MAAM,MAAA,IAAIA,kBAAW,4CAA4C,CAAA;AAAA;AACnE;AACF;AAAA;AAAA;AAAA,EAKQ,eAAe,MAA6B,EAAA;AAClD,IAAM,MAAA,aAAA,GAAgB,MAAO,CAAA,MAAA,CAAOC,0CAAa,CAAA;AACjD,IAAA,IAAI,CAAC,aAAA,CAAc,QAAS,CAAA,MAAM,CAAG,EAAA;AACnC,MAAA,MAAM,IAAID,iBAAA;AAAA,QACR,CAAA,gBAAA,EAAmB,MAAM,CAAA,kBAAA,EAAqB,aAAc,CAAA,IAAA;AAAA,UAC1D;AAAA,SACD,CAAA;AAAA,OACH;AAAA;AACF;AACF,EAEA,MAAM,cAAqC,GAAA;AACzC,IAAK,IAAA,CAAA,MAAA,CAAO,KAAK,uBAAuB,CAAA;AACxC,IAAO,OAAA,IAAA,CAAK,GAAG,cAAe,EAAA;AAAA;AAChC,EAEA,MAAM,eAAe,EAA8B,EAAA;AACjD,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAA4B,yBAAA,EAAA,EAAE,CAAE,CAAA,CAAA;AACjD,IAAO,OAAA,IAAA,CAAK,EAAG,CAAA,cAAA,CAAe,EAAE,CAAA;AAAA;AAClC,EAEA,MAAM,UAAW,CAAA,OAAA,EAAqB,MAAkC,EAAA;AACtE,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,oBAAA,EAAuB,QAAQ,KAAK,CAAA,IAAA,EAAO,MAAM,CAAE,CAAA,CAAA;AACpE,IAAA,IAAA,CAAK,mBAAmB,OAAO,CAAA;AAC/B,IAAA,OAAO,KAAK,EAAG,CAAA,UAAA,CAAW,EAAE,GAAG,OAAA,EAAS,QAAQ,CAAA;AAAA;AAClD,EAEA,MAAM,mBACJ,CAAA,EAAA,EACA,MACkB,EAAA;AAClB,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,iBAAA,EAAoB,EAAE,CAAA,WAAA,EAAc,MAAM,CAAE,CAAA,CAAA;AAC7D,IAAA,IAAA,CAAK,eAAe,MAAM,CAAA;AAC1B,IAAA,OAAO,IAAK,CAAA,EAAA,CAAG,mBAAoB,CAAA,EAAA,EAAI,MAAM,CAAA;AAAA;AAEjD;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
4
|
+
var errors = require('@backstage/errors');
|
|
5
|
+
var config = require('../config.cjs.js');
|
|
6
|
+
var pluginPermissionCommon = require('@backstage/plugin-permission-common');
|
|
7
|
+
|
|
8
|
+
class PermissionService {
|
|
9
|
+
options;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
async getUsername(req) {
|
|
14
|
+
const { httpAuth, userInfo, logger } = this.options;
|
|
15
|
+
const credentials = await httpAuth.credentials(req);
|
|
16
|
+
if (!credentials) {
|
|
17
|
+
logger.warn("Unauthorized access attempt");
|
|
18
|
+
throw new errors.NotAllowedError("Unauthorized access");
|
|
19
|
+
}
|
|
20
|
+
const user = await userInfo.getUserInfo(credentials);
|
|
21
|
+
const username = user?.userEntityRef?.toString();
|
|
22
|
+
if (!username) {
|
|
23
|
+
logger.warn("User not found");
|
|
24
|
+
throw new errors.NotFoundError("User not found");
|
|
25
|
+
}
|
|
26
|
+
return username;
|
|
27
|
+
}
|
|
28
|
+
async checkPermission(req, username, permission) {
|
|
29
|
+
const { config: config$1, logger, permissions, httpAuth } = this.options;
|
|
30
|
+
const roadmapConfig = config.getRoadmapBackendConfig(config$1);
|
|
31
|
+
if (roadmapConfig.adminUsers.includes(username)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (!permissions) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const credentials = await httpAuth.credentials(req);
|
|
38
|
+
if (!credentials) {
|
|
39
|
+
logger.warn(`Unauthorized access attempt by user ${username}`);
|
|
40
|
+
throw new errors.NotAllowedError("Unauthorized access");
|
|
41
|
+
}
|
|
42
|
+
let decision = { result: pluginPermissionCommon.AuthorizeResult.DENY };
|
|
43
|
+
try {
|
|
44
|
+
decision = (await permissions.authorize([{ permission }], {
|
|
45
|
+
credentials
|
|
46
|
+
}))[0];
|
|
47
|
+
const isAllowed = decision.result === pluginPermissionCommon.AuthorizeResult.ALLOW;
|
|
48
|
+
logger.info(
|
|
49
|
+
`Permission ${permission.name} ${isAllowed ? "granted" : "denied"} to user ${username}`
|
|
50
|
+
);
|
|
51
|
+
return isAllowed;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
logger.error(`Error while authorizing user ${username}`);
|
|
54
|
+
throw new errors.NotAllowedError("Permission check failed");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async isRoadmapAdmin(req, username) {
|
|
58
|
+
return this.checkPermission(req, username, backstagePluginRoadmapCommon.roadmapAdminPermission);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.PermissionService = PermissionService;
|
|
63
|
+
//# sourceMappingURL=PermissionService.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PermissionService.cjs.js","sources":["../../src/services/PermissionService.ts"],"sourcesContent":["import { Request } from 'express';\nimport { PermissionServiceInterface } from './types';\nimport { RouterOptions } from '../routes/router';\nimport { roadmapAdminPermission } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { BasicPermission } from '@backstage/plugin-permission-common';\nimport { NotFoundError, NotAllowedError } from '@backstage/errors';\nimport { getRoadmapBackendConfig } from '../config';\nimport {\n AuthorizeResult,\n DefinitivePolicyDecision,\n} from '@backstage/plugin-permission-common';\n\n/**\n * Implementation of the Permission Service\n */\nexport class PermissionService implements PermissionServiceInterface {\n private readonly options: RouterOptions;\n\n constructor(options: RouterOptions) {\n this.options = options;\n }\n\n async getUsername(req: Request): Promise<string> {\n const { httpAuth, userInfo, logger } = this.options;\n const credentials = await httpAuth.credentials(req);\n if (!credentials) {\n logger.warn('Unauthorized access attempt');\n throw new NotAllowedError('Unauthorized access');\n }\n const user = await userInfo.getUserInfo(credentials);\n const username = user?.userEntityRef?.toString();\n if (!username) {\n logger.warn('User not found');\n throw new NotFoundError('User not found');\n }\n return username;\n }\n\n async checkPermission(\n req: Request,\n username: string,\n permission: BasicPermission,\n ): Promise<boolean> {\n const { config, logger, permissions, httpAuth } = this.options;\n const roadmapConfig = getRoadmapBackendConfig(config);\n\n // Admin users early exit\n if (roadmapConfig.adminUsers.includes(username)) {\n return true;\n }\n\n // Check if permissions service is available\n if (!permissions) {\n return false;\n }\n\n // Authenticate request credentials\n const credentials = await httpAuth.credentials(req);\n if (!credentials) {\n logger.warn(`Unauthorized access attempt by user ${username}`);\n throw new NotAllowedError('Unauthorized access');\n }\n\n let decision: DefinitivePolicyDecision = { result: AuthorizeResult.DENY };\n\n try {\n // Authorize user with permission service\n decision = (\n await permissions.authorize([{ permission }], {\n credentials,\n })\n )[0];\n\n const isAllowed = decision.result === AuthorizeResult.ALLOW;\n logger.info(\n `Permission ${permission.name} ${\n isAllowed ? 'granted' : 'denied'\n } to user ${username}`,\n );\n\n return isAllowed;\n } catch (error) {\n logger.error(`Error while authorizing user ${username}`);\n throw new NotAllowedError('Permission check failed');\n }\n }\n\n async isRoadmapAdmin(req: Request, username: string): Promise<boolean> {\n return this.checkPermission(req, username, roadmapAdminPermission);\n }\n}\n"],"names":["NotAllowedError","NotFoundError","config","getRoadmapBackendConfig","AuthorizeResult","roadmapAdminPermission"],"mappings":";;;;;;;AAeO,MAAM,iBAAwD,CAAA;AAAA,EAClD,OAAA;AAAA,EAEjB,YAAY,OAAwB,EAAA;AAClC,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA;AAAA;AACjB,EAEA,MAAM,YAAY,GAA+B,EAAA;AAC/C,IAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,MAAA,KAAW,IAAK,CAAA,OAAA;AAC5C,IAAA,MAAM,WAAc,GAAA,MAAM,QAAS,CAAA,WAAA,CAAY,GAAG,CAAA;AAClD,IAAA,IAAI,CAAC,WAAa,EAAA;AAChB,MAAA,MAAA,CAAO,KAAK,6BAA6B,CAAA;AACzC,MAAM,MAAA,IAAIA,uBAAgB,qBAAqB,CAAA;AAAA;AAEjD,IAAA,MAAM,IAAO,GAAA,MAAM,QAAS,CAAA,WAAA,CAAY,WAAW,CAAA;AACnD,IAAM,MAAA,QAAA,GAAW,IAAM,EAAA,aAAA,EAAe,QAAS,EAAA;AAC/C,IAAA,IAAI,CAAC,QAAU,EAAA;AACb,MAAA,MAAA,CAAO,KAAK,gBAAgB,CAAA;AAC5B,MAAM,MAAA,IAAIC,qBAAc,gBAAgB,CA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,CAAE,CAAA,CAAA;AACvD,MAAM,MAAA,IAAIJ,uBAAgB,yBAAyB,CAAA;AAAA;AACrD;AACF,EAEA,MAAM,cAAe,CAAA,GAAA,EAAc,QAAoC,EAAA;AACrE,IAAA,OAAO,IAAK,CAAA,eAAA,CAAgB,GAAK,EAAA,QAAA,EAAUK,mDAAsB,CAAA;AAAA;AAErE;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class VoteService {
|
|
4
|
+
constructor(db, logger) {
|
|
5
|
+
this.db = db;
|
|
6
|
+
this.logger = logger;
|
|
7
|
+
}
|
|
8
|
+
async toggleVote(featureId, voter) {
|
|
9
|
+
this.logger.info(`Toggling vote for feature ${featureId} by ${voter}`);
|
|
10
|
+
return this.db.toggleVote(featureId, voter);
|
|
11
|
+
}
|
|
12
|
+
async getVoteCount(featureId) {
|
|
13
|
+
this.logger.info(`Getting vote count for feature ${featureId}`);
|
|
14
|
+
return this.db.getVoteCount(featureId);
|
|
15
|
+
}
|
|
16
|
+
async getVoteCounts(featureIds) {
|
|
17
|
+
this.logger.info(`Getting vote counts for ${featureIds.length} features`);
|
|
18
|
+
if (featureIds.length === 0) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
return this.db.getVoteCounts(featureIds);
|
|
22
|
+
}
|
|
23
|
+
async hasVoted(featureId, voter) {
|
|
24
|
+
this.logger.info(`Checking if ${voter} has voted on feature ${featureId}`);
|
|
25
|
+
return this.db.hasVoted(featureId, voter);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.VoteService = VoteService;
|
|
30
|
+
//# sourceMappingURL=VoteService.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoteService.cjs.js","sources":["../../src/services/VoteService.ts"],"sourcesContent":["import { LoggerService } from '@backstage/backend-plugin-api';\nimport { RoadmapDatabase } from '../database/types';\nimport { VoteServiceInterface } from './types';\n\n/**\n * Implementation of the Vote Service\n */\nexport class VoteService implements VoteServiceInterface {\n constructor(\n private readonly db: RoadmapDatabase,\n private readonly logger: LoggerService,\n ) {}\n\n async toggleVote(featureId: string, voter: string): Promise<boolean> {\n this.logger.info(`Toggling vote for feature ${featureId} by ${voter}`);\n return this.db.toggleVote(featureId, voter);\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n this.logger.info(`Getting vote count for feature ${featureId}`);\n return this.db.getVoteCount(featureId);\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n this.logger.info(`Getting vote counts for ${featureIds.length} features`);\n if (featureIds.length === 0) {\n return {};\n }\n return this.db.getVoteCounts(featureIds);\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n this.logger.info(`Checking if ${voter} has voted on feature ${featureId}`);\n return this.db.hasVoted(featureId, voter);\n }\n}\n"],"names":[],"mappings":";;AAOO,MAAM,WAA4C,CAAA;AAAA,EACvD,WAAA,CACmB,IACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAChB,EAEH,MAAM,UAAW,CAAA,SAAA,EAAmB,KAAiC,EAAA;AACnE,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,0BAAA,EAA6B,SAAS,CAAA,IAAA,EAAO,KAAK,CAAE,CAAA,CAAA;AACrE,IAAA,OAAO,IAAK,CAAA,EAAA,CAAG,UAAW,CAAA,SAAA,EAAW,KAAK,CAAA;AAAA;AAC5C,EAEA,MAAM,aAAa,SAAoC,EAAA;AACrD,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAAkC,+BAAA,EAAA,SAAS,CAAE,CAAA,CAAA;AAC9D,IAAO,OAAA,IAAA,CAAK,EAAG,CAAA,YAAA,CAAa,SAAS,CAAA;AAAA;AACvC,EAEA,MAAM,cAAc,UAAuD,EAAA;AACzE,IAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,CAA2B,wBAAA,EAAA,UAAA,CAAW,MAAM,CAAW,SAAA,CAAA,CAAA;AACxE,IAAI,IAAA,UAAA,CAAW,WAAW,CAAG,EAAA;AAC3B,MAAA,OAAO,EAAC;AAAA;AAEV,IAAO,OAAA,IAAA,CAAK,EAAG,CAAA,aAAA,CAAc,UAAU,CAAA;AAAA;AACzC,EAEA,MAAM,QAAS,CAAA,SAAA,EAAmB,KAAiC,EAAA;AACjE,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAA,YAAA,EAAe,KAAK,CAAA,sBAAA,EAAyB,SAAS,CAAE,CAAA,CAAA;AACzE,IAAA,OAAO,IAAK,CAAA,EAAA,CAAG,QAAS,CAAA,SAAA,EAAW,KAAK,CAAA;AAAA;AAE5C;;;;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
exports.up = async function up(knex) {
|
|
2
|
+
// Create features table
|
|
3
|
+
await knex.schema.createTable('features', table => {
|
|
4
|
+
table.increments('id').primary();
|
|
5
|
+
table.string('title').notNullable();
|
|
6
|
+
table.text('description').notNullable();
|
|
7
|
+
table
|
|
8
|
+
.enum('status', [
|
|
9
|
+
'Suggested',
|
|
10
|
+
'Planned',
|
|
11
|
+
'InProgress',
|
|
12
|
+
'Completed',
|
|
13
|
+
'Declined',
|
|
14
|
+
])
|
|
15
|
+
.notNullable()
|
|
16
|
+
.defaultTo('Suggested');
|
|
17
|
+
table.integer('votes').notNullable().defaultTo(0);
|
|
18
|
+
table.string('author').notNullable();
|
|
19
|
+
table.timestamps(true, true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Create comments table
|
|
23
|
+
await knex.schema.createTable('comments', table => {
|
|
24
|
+
table.increments('id').primary();
|
|
25
|
+
table.integer('feature_id').unsigned().notNullable();
|
|
26
|
+
table.text('text').notNullable();
|
|
27
|
+
table.string('author').notNullable();
|
|
28
|
+
table.timestamps(true, true);
|
|
29
|
+
table
|
|
30
|
+
.foreign('feature_id')
|
|
31
|
+
.references('id')
|
|
32
|
+
.inTable('features')
|
|
33
|
+
.onDelete('CASCADE');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Create votes table
|
|
37
|
+
await knex.schema.createTable('votes', table => {
|
|
38
|
+
table.increments('id').primary();
|
|
39
|
+
table.integer('feature_id').unsigned().notNullable();
|
|
40
|
+
table.string('voter').notNullable();
|
|
41
|
+
table.timestamps(true, true);
|
|
42
|
+
table
|
|
43
|
+
.foreign('feature_id')
|
|
44
|
+
.references('id')
|
|
45
|
+
.inTable('features')
|
|
46
|
+
.onDelete('CASCADE');
|
|
47
|
+
table.unique(['feature_id', 'voter']);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.down = async function down(knex) {
|
|
52
|
+
// Drop tables in reverse order to avoid foreign key constraints
|
|
53
|
+
await knex.schema.dropTable('votes');
|
|
54
|
+
await knex.schema.dropTable('comments');
|
|
55
|
+
await knex.schema.dropTable('features');
|
|
56
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rothenbergt/backstage-plugin-roadmap-backend",
|
|
3
|
+
"description": "Backstage Roadmap plugin backend",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"main": "dist/index.cjs.js",
|
|
11
|
+
"types": "dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"backstage": {
|
|
14
|
+
"role": "backend-plugin",
|
|
15
|
+
"pluginId": "roadmap",
|
|
16
|
+
"pluginPackages": [
|
|
17
|
+
"@rothenbergt/backstage-plugin-roadmap",
|
|
18
|
+
"@rothenbergt/backstage-plugin-roadmap-common",
|
|
19
|
+
"@rothenbergt/backstage-plugin-roadmap-backend"
|
|
20
|
+
],
|
|
21
|
+
"features": {
|
|
22
|
+
".": "@backstage/BackendFeature"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"start": "backstage-cli package start",
|
|
27
|
+
"build": "backstage-cli package build",
|
|
28
|
+
"lint": "backstage-cli package lint",
|
|
29
|
+
"test": "backstage-cli package test",
|
|
30
|
+
"clean": "backstage-cli package clean",
|
|
31
|
+
"prepack": "backstage-cli package prepack",
|
|
32
|
+
"postpack": "backstage-cli package postpack"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@backstage/backend-defaults": "^0.8.2",
|
|
36
|
+
"@backstage/backend-plugin-api": "^1.2.1",
|
|
37
|
+
"@backstage/config": "^1.3.2",
|
|
38
|
+
"@backstage/errors": "^1.2.7",
|
|
39
|
+
"@backstage/plugin-permission-common": "^0.8.4",
|
|
40
|
+
"@backstage/plugin-permission-node": "^0.9.0",
|
|
41
|
+
"@rothenbergt/backstage-plugin-roadmap-common": "^0.1.0",
|
|
42
|
+
"express": "^4.17.1",
|
|
43
|
+
"express-promise-router": "^4.1.0",
|
|
44
|
+
"knex": "^3.1.0",
|
|
45
|
+
"node-fetch": "^2.6.7"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@backstage/backend-test-utils": "^1.3.1",
|
|
49
|
+
"@backstage/cli": "^0.31.0",
|
|
50
|
+
"@backstage/plugin-auth-backend": "^0.24.4",
|
|
51
|
+
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.6",
|
|
52
|
+
"@types/express": "*",
|
|
53
|
+
"@types/supertest": "^2.0.12",
|
|
54
|
+
"msw": "^2.3.1",
|
|
55
|
+
"supertest": "^6.2.4"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"dist",
|
|
59
|
+
"migrations"
|
|
60
|
+
]
|
|
61
|
+
}
|