From 3b2a01827ad76343bf58ef3eb24758341658dbbe Mon Sep 17 00:00:00 2001 From: Joe Jaworski Date: Mon, 16 Mar 2015 14:56:35 -0700 Subject: [PATCH] (#104) - removing GET /user/:username and GET /repo/:id from Permissive API --- app/server/apps/repos/routes.js | 9 ---- app/server/apps/users/routes.js | 9 ---- app/server/components/repositories/repos.js | 4 -- app/server/components/repositories/users.js | 4 -- .../components/repositories/util/repos.js | 8 ---- app/server/it/TestRepos.js | 45 ++----------------- app/server/it/TestUsers.js | 45 ++----------------- app/server/middleware/repos.js | 11 ----- app/server/middleware/users.js | 11 ----- documents/API.md | 15 ++----- documents/ServiceMapping.md | 25 ++++------- 11 files changed, 18 insertions(+), 168 deletions(-) diff --git a/app/server/apps/repos/routes.js b/app/server/apps/repos/routes.js index 69c7c83..509b928 100644 --- a/app/server/apps/repos/routes.js +++ b/app/server/apps/repos/routes.js @@ -17,15 +17,6 @@ module.exports = { send.json ] }, - read: { - method: 'GET', - path: '/repos/:id', - middleware: [ - auth.authenticate, - repos.readRepo, - send.json - ] - }, editUserPermission: { method: 'PUT', path: '/repos/:id/users/:username/permissions/:permission', diff --git a/app/server/apps/users/routes.js b/app/server/apps/users/routes.js index 27003d9..5588c7c 100644 --- a/app/server/apps/users/routes.js +++ b/app/server/apps/users/routes.js @@ -16,15 +16,6 @@ module.exports = { send.json ] }, - read: { - method: 'GET', - path: '/users/:username', - middleware: [ - auth.authenticate, - users.readUser, - send.json - ] - }, editRepoPermission: { method: 'PUT', path: '/users/:username/repos/:id/permissions/:permission', diff --git a/app/server/components/repositories/repos.js b/app/server/components/repositories/repos.js index 29a7d98..dc62980 100644 --- a/app/server/components/repositories/repos.js +++ b/app/server/components/repositories/repos.js @@ -6,10 +6,6 @@ module.exports = { getRepos () { return repoUtil.getGithubRepos(); - }, - - getRepo (repoId) { - return repoUtil.getGithubRepo(repoId); } }; diff --git a/app/server/components/repositories/users.js b/app/server/components/repositories/users.js index 262d95b..efd58c8 100644 --- a/app/server/components/repositories/users.js +++ b/app/server/components/repositories/users.js @@ -10,10 +10,6 @@ module.exports = { let profiles = users.map(user => userUtil.getGithubUser(user.username).then(profile => user.name = profile.name)); return Bluebird.all(profiles).then(() => users); }); - }, - - getUser (username) { - return userUtil.getGithubUser(username); } }; diff --git a/app/server/components/repositories/util/repos.js b/app/server/components/repositories/util/repos.js index 72880d9..3d4d3bb 100644 --- a/app/server/components/repositories/util/repos.js +++ b/app/server/components/repositories/util/repos.js @@ -17,14 +17,6 @@ module.exports = { getGithubRepos () { let args = provider.getDefaultListArgs(); return provider.github.getRepos(args).then(repos => repos.map(repo => convertGithubRepo(repo))); - }, - - getGithubRepo (repoId) { - let args = provider.getDefaultItemArgs(); - return provider.github.getRepos(args).then(repos => { - let id = parseInt(repoId, 10); - return convertGithubRepo(repos.find(repo => repo.id === id)); - }); } }; diff --git a/app/server/it/TestRepos.js b/app/server/it/TestRepos.js index 526bab8..e4e41e7 100644 --- a/app/server/it/TestRepos.js +++ b/app/server/it/TestRepos.js @@ -57,31 +57,9 @@ describe('Repo model HTTP requests', function () { chai.assert.ok(items[0].id); }); - it('repo has links', () => { - chai.assert.ok(items[0].links.length > 0); - }); - - }); - - describe('pull', () => { - - let item, - statusCode; - - before((done) => { - util.get('/repos/1').then((result) => { - item = JSON.parse(result.body); - statusCode = result.statusCode; - done(); - }); - }); - - it('returns a 200', () => { - chai.assert.equal(statusCode, 200); - }); - - it('returns a repo', () => { - chai.assert.ok(item.id); + //TODO: use authenticated user to check for links + it('repo has no links', () => { + chai.assert.isUndefined(items[0].links); }); }); @@ -103,21 +81,4 @@ describe('Repo model HTTP requests', function () { }); - describe('removeUserPermission', () => { - - let statusCode; - - before((done) => { - util.del('/repos/1/users/testuser1').then((result) => { - statusCode = result.statusCode; - done(); - }); - }); - - it('returns a 204', () => { - chai.assert.equal(statusCode, 204); - }); - - }); - }); diff --git a/app/server/it/TestUsers.js b/app/server/it/TestUsers.js index 054a69b..512a217 100644 --- a/app/server/it/TestUsers.js +++ b/app/server/it/TestUsers.js @@ -57,31 +57,9 @@ describe('User model HTTP requests', function () { chai.assert.ok(items[0].username); }); - it('user has links', () => { - chai.assert.ok(items[0].links.length > 0); - }); - - }); - - describe('pull', () => { - - let item, - statusCode; - - before((done) => { - util.get('/users/testuser1').then((result) => { - item = JSON.parse(result.body); - statusCode = result.statusCode; - done(); - }); - }); - - it('returns a 200', () => { - chai.assert.equal(statusCode, 200); - }); - - it('returns a user', () => { - chai.assert.ok(item.username); + //TODO: use authenticated user to check for links + it('user has no links', () => { + chai.assert.isUndefined(items[0].links); }); }); @@ -103,21 +81,4 @@ describe('User model HTTP requests', function () { }); - describe('removeRepoPermission', () => { - - let statusCode; - - before((done) => { - util.del('/users/testuser1/repos/1').then((result) => { - statusCode = result.statusCode; - done(); - }); - }); - - it('returns a 204', () => { - chai.assert.equal(statusCode, 204); - }); - - }); - }); diff --git a/app/server/middleware/repos.js b/app/server/middleware/repos.js index 24a4978..dbe0c29 100644 --- a/app/server/middleware/repos.js +++ b/app/server/middleware/repos.js @@ -56,16 +56,5 @@ module.exports = { } else { next(); } - }, - - readRepo (req, res, next) { - debug('getting repo [' + req.path + ']'); - debug('params:' + JSON.stringify(req.params, null, 2)); - - let repoId = req.params.id; - repoRepository.getRepo(repoId).then(repo => { - req.entity = repo; - next(); - }).catch(err => next(err)); } }; diff --git a/app/server/middleware/users.js b/app/server/middleware/users.js index 228e8d5..cca8c6d 100644 --- a/app/server/middleware/users.js +++ b/app/server/middleware/users.js @@ -55,16 +55,5 @@ module.exports = { } else { next(); } - }, - - readUser (req, res, next) { - debug('getting user [' + req.path + ']'); - debug('params:' + JSON.stringify(req.params, null, 2)); - - let username = req.params.username; - userRepository.getUser(username).then(user => { - req.entity = user; - next(); - }).catch(err => next(err)); } }; diff --git a/documents/API.md b/documents/API.md index 8fb5823..eea245e 100644 --- a/documents/API.md +++ b/documents/API.md @@ -8,31 +8,24 @@ This is a draft of the operations available to meet the initial views of the app GET /users[?permission_repo=:id] returns User[] -2. Get details for a user - GET /users/:username - returns User - -3. Add/update/remove repo permissions for a user +2. Add/update/remove repo permissions for a user PUT /users/:username/repos/:id/permissions/:permission returns null, 204 -4. Get list of repos. If permission_user is specified, the "permission" flag on each repo will be present, reporting the access available for that user. +3. Get list of repos. If permission_user is specified, the "permission" flag on each repo will be present, reporting the access available for that user. GET /repos[?permission_user=:username] returns Repo[] -5. Get details for a repo - GET /repos/:id - returns Repo -6. Add/update/remove user permissions for a repo +4. Add/update/remove user permissions for a repo PUT /repos/:id/users/:username/permissions/:permission returns null, 204 -Note that 3/6 are effectively aliases to each other, suitable for different views. +Note that 2/4 are effectively aliases to each other, suitable for different views. Also note that some PUT operations have no body, as the URL contains sufficient data. See [GitHub documentation](https://developer.github.com/v3/#http-verbs). diff --git a/documents/ServiceMapping.md b/documents/ServiceMapping.md index 1d7b59a..b786ef3 100644 --- a/documents/ServiceMapping.md +++ b/documents/ServiceMapping.md @@ -46,11 +46,7 @@ The following details the node-github methods that will be called by permissive. 1. Return the mapping for the requested repo -### 2 Get details for a user -1. Get the user data (user.getFrom) - - -### 3 Add repo permission for a user +### 2 Add repo permission for a user 1. Get a list of repos in the organization (repos.getFromOrg) 1. Find the appropriate repo 1. Get a list of teams in the organization (orgs.getTeams) @@ -58,7 +54,7 @@ The following details the node-github methods that will be called by permissive. 1. Add the user to the team (orgs.addTeamMember) -### 3a Update repo permission for a user +### 2a Update repo permission for a user 1. Get a list of repos in the organization (repos.getFromOrg) 1. Find the appropriate repo 1. Get a list of teams in the organization (orgs.getTeams) @@ -68,7 +64,7 @@ The following details the node-github methods that will be called by permissive. 1. Add the user to the team (orgs.addTeamMember) -### 3b Remove repo access for a user +### 2b Remove repo access for a user 1. Get a list of repos in the organization (repos.getFromOrg) 1. Find the appropriate repo 1. Get a list of teams in the organization (orgs.getTeams) @@ -77,11 +73,11 @@ The following details the node-github methods that will be called by permissive. 1. If the user is on the team, remove them (orgs.deleteTeamMember) -### 4 Get list of repos +### 3 Get list of repos 1. Get a list of repos in the organization (repos.getFromOrg) -### 4a Get a list of repos with permission for a specific user +### 3a Get a list of repos with permission for a specific user 1. Get a list of members in the organization (orgs.getMembers) 1. For each member 1. Get the user data (user.getFrom) @@ -95,12 +91,7 @@ The following details the node-github methods that will be called by permissive. 1. Return a mapping for the requested user -### 5 Get details for a repo -1. Get a list of repos in the organization (repos.getFromOrg) -1. Find the appropriate repo - - -### 6 Add user permission for a repo +### 5 Add user permission for a repo 1. Get a list of repos in the organization (repos.getFromOrg) 1. Find the appropriate repo 1. Get a list of teams in the organization (orgs.getTeams) @@ -108,7 +99,7 @@ The following details the node-github methods that will be called by permissive. 1. Add the user to the team (orgs.addTeamMember) -### 6a Update user permission for a repo +### 5a Update user permission for a repo 1. Get a list of repos in the organization (repos.getFromOrg) 1. Find the appropriate repo 1. Get a list of teams in the organization (orgs.getTeams) @@ -118,7 +109,7 @@ The following details the node-github methods that will be called by permissive. 1. Add the user to the team (orgs.addTeamMember) -### 6b Remove user access to a repo +### 5b Remove user access to a repo 1. Get a list of repos in the organization (repos.getFromOrg) 1. Find the appropriate repo 1. Get a list of teams in the organization (orgs.getTeams)