Skip to content

Commit

Permalink
chore(naming): renamed apps to auth
Browse files Browse the repository at this point in the history
  • Loading branch information
didimitrie committed Jul 19, 2020
1 parent a80d851 commit 13b6ccb
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 79 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ type ServerApp {
scopes: [Scope]
}

extend type User {
"""
Apps used by this user.
"""
apps: [ServerApp]
}
# extend type User {
# """
# Apps used by this user.
# """
# apps: [ServerApp]
# }

extend type ServerInfo {
authStrategies: [AuthStrategy]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 14 additions & 6 deletions modules/core/graph/resolvers/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ const {

module.exports = {
Query: {},
Stream: {},
Branch: {},
Stream: {
async branches( parent, args, context, info ) {
throw new ApolloError('not implemented')
},
async branch( parent, args, context, info ) {
throw new ApolloError('not implemented')
},
},
Branch: {
async author( parent, args, context, info ) {
throw new ApolloError( 'not implemented' )
}
},
Mutation: {
async branchCreate( parent, args, context, info ) {
await validateServerRole( context, 'server:user' )
Expand All @@ -49,9 +60,6 @@ module.exports = {

await deleteBranchById( args.branchId )
return true
},
async commitCreate( parent, args, context, info ) {},
async commitUpdate( parent, args, context, info ) {},
async commitDelete( parent, args, context, info ) {}
}
}
}
37 changes: 31 additions & 6 deletions modules/core/graph/resolvers/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const {
updateCommit,
deleteCommit,
getCommitsByBranchId,
getCommitsByBranchName
getCommitsByBranchName,
getCommitsByUserId,
getCommitsTotalCountByUserId
} = require( '../../services/commits' )

const {
Expand All @@ -23,11 +25,34 @@ const {

module.exports = {
Query: {},
Stream: {},
Branch: {},
Stream: {
async commit( parent, args, context, info ) {
throw new ApolloError( 'not implemented' )
}
},
User: {
async commits( parent, args, context, info ) {
// TODO
throw new ApolloError( 'not implemented' )
}
},
Branch: {
async commits( parent, args, context, info ) {
throw new ApolloError( 'not implemented' )
}
},
Mutation: {
async commitCreate( parent, args, context, info ) {},
async commitUpdate( parent, args, context, info ) {},
async commitDelete( parent, args, context, info ) {}
async commitCreate( parent, args, context, info ) {
throw new ApolloError('not implemented')

},
async commitUpdate( parent, args, context, info ) {
throw new ApolloError('not implemented')

},
async commitDelete( parent, args, context, info ) {
throw new ApolloError('not implemented')

}
}
}
18 changes: 10 additions & 8 deletions modules/core/graph/resolvers/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
await validateScopes( context.scopes, 'streams:read' )
await authorizeResolver( context.userId, args.id, 'stream:reviewer' )

let stream = await getStream( args.id, context.userId )
let stream = await getStream( { streamId: args.id } )
return stream
}
},
Expand All @@ -22,9 +22,9 @@ module.exports = {
},
User: {
async streams( parent, args, context, info ) {
// TODO: Return only the user's public streams if parent.id !== context.userId
// Return only the user's public streams if parent.id !== context.userId
let publicOnly = parent.id !== context.userId
let streams = await getUserStreams( parent.id, args.offset, args.limit, publicOnly )
let streams = await getUserStreams( { userId: parent.id, offset: args.offset, limit: args.limit, publicOnly } )
// TODO: Implement offsets in service, not in friggin array slice
return { totalCount: streams.length, streams: streams.slice( args.offset, args.offset + args.limit ) }
}
Expand All @@ -34,15 +34,15 @@ module.exports = {
await validateServerRole( context, 'server:user' )
await validateScopes( context.scopes, 'streams:write' )

let id = await createStream( args.stream, context.userId )
let id = await createStream( { ...args.stream, ownerId: context.userId } )
return id
},
async streamUpdate( parent, args, context, info ) {
await validateServerRole( context, 'server:user' )
await validateScopes( context.scopes, 'streams:write' )
await authorizeResolver( context.userId, args.stream.id, 'stream:owner' )
await updateStream( args.stream )

await updateStream( { streamId: args.stream.id, name: args.stream.name, description: args.stream.description } )
return true
},
async streamDelete( parent, args, context, info ) {
Expand All @@ -57,15 +57,17 @@ module.exports = {
await validateServerRole( context, 'server:user' )
await validateScopes( context.scopes, 'streams:write' )
await authorizeResolver( context.userId, args.streamId, 'stream:owner' )

if ( context.userId === args.userId ) throw new AuthorizationError( 'You cannot set roles for yourself.' )
return await grantPermissionsStream( args.streamId, args.userId, args.role.toLowerCase( ) || 'read' )

return await grantPermissionsStream( { streamId: args.streamId, userId: args.userId, role: args.role.toLowerCase( ) || 'read' } )
},
async streamRevokePermission( parent, args, context, info ) {
await validateServerRole( context, 'server:user' )
await validateScopes( context.scopes, 'streams:write' )
await authorizeResolver( context.userId, args.streamId, 'stream:owner' )

return await revokePermissionsStream( args.streamId, args.userId )
return await revokePermissionsStream( { ...args } )
}
}
}
1 change: 0 additions & 1 deletion modules/core/graph/schemas/branchesAndCommits.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extend type Stream {
commit( id: String! ): Commit
branches( limit: Int! = 20, cursor: String ): BranchCollection
branch( name: String! ): Branch
branchById( id: String! ): Branch
}

extend type User {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/tests/branches.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe( 'Branches', ( ) => {
expect( branches ).to.have.lengthOf( 4 )
} )

it( 'Should delete a bracnh', async ( ) => {
it( 'Should delete a branch', async ( ) => {
await deleteBranchById( { id: branch.id } )
let branches = await getBranchesByStreamId( { streamId: stream.id } )
expect( branches ).to.have.lengthOf( 3 )
Expand Down
53 changes: 2 additions & 51 deletions modules/core/tests/graph.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe( 'GraphQL API Core', ( ) => {
} )

after( async ( ) => {
// await knex.migrate.rollback( )
testServer.close( )
} )

Expand All @@ -66,11 +65,6 @@ describe( 'GraphQL API Core', ( ) => {
let c1 = { description: 'test first commit' }
let c2 = { description: 'test second commit' }

// some tags
let tag1 = { name: 'v.10.0.0', description: 'test tag' }
let tag2 = { name: 'v.20.0.0' }
let tag3 = { name: 'v.21.0.1-alpha' }

// some branches
let b1 = { name: 'branch 1', description: 'test branch' }
let b2 = { name: 'master', description: 'master branch' }
Expand Down Expand Up @@ -142,7 +136,7 @@ describe( 'GraphQL API Core', ( ) => {

it( 'Should update a stream', async ( ) => {
const resS1 = await sendRequest( userA.token, { query: `mutation { streamUpdate(stream: {id:"${ts1}" name: "TS1 (u A) Private UPDATED", description: "Hello World, Again!", isPublic:false } ) }` } )

// console.log( resS1.body.errors )
expect( resS1 ).to.be.json
expect( resS1.body.errors ).to.not.exist
expect( resS1.body.data ).to.have.property( 'streamUpdate' )
Expand Down Expand Up @@ -183,7 +177,7 @@ describe( 'GraphQL API Core', ( ) => {

it( 'Should revoke permissions', async ( ) => {
// first test if we can get it
const res = await sendRequest( userC.token, { query: `query { stream(id:"${ts3}") { id name role } }` } )
const res = await sendRequest( userC.token, { query: `query { stream(id:"${ts3}") { id name } }` } )
expect( res ).to.be.json
expect( res.body.errors ).to.not.exist
expect( res.body.data.stream.name ).to.equal( 'TS3 (u B) Private' )
Expand Down Expand Up @@ -243,49 +237,6 @@ describe( 'GraphQL API Core', ( ) => {
c2.id = res.body.data.commitCreate
} )

it( 'Should create two tags', async ( ) => {
tag1.commitId = c1.id
tag2.commitId = c2.id

let res = await sendRequest( userA.token, { query: `
mutation($tag: TagCreateInput){tagCreate(streamId:"${ts1}", tag: $tag) }`, variables: { tag: tag1 } } )

expect( res ).to.be.json
expect( res.body.errors ).to.not.exist
expect( res.body.data ).to.have.property( 'tagCreate' )
tag1.id = res.body.data.tagCreate

// create a second tag
res = await sendRequest( userA.token, { query: `
mutation($tag: TagCreateInput){tagCreate(streamId:"${ts1}", tag: $tag)}`, variables: { tag: tag2 } } )
expect( res ).to.be.json
expect( res.body.errors ).to.not.exist
expect( res.body.data ).to.have.property( 'tagCreate' )
tag2.id = res.body.data.tagCreate

tag3.commitId = c2.id
res = await sendRequest( userA.token, { query: `
mutation($tag: TagCreateInput){tagCreate(streamId:"${ts1}", tag: $tag)}`, variables: { tag: tag3 } } )
tag3.id = res.body.data.tagCreate
} )

it( 'Should update a tag', async ( ) => {
const res = await sendRequest( userA.token, { query: `
mutation($tag: TagUpdateInput){tagUpdate(streamId:"${ts1}", tag: $tag)}`, variables: { tag: { id: tag2.id, description: 'Cool description!' } } } )
expect( res ).to.be.json
expect( res.body.errors ).to.not.exist
expect( res.body.data ).to.have.property( 'tagUpdate' )
expect( res.body.data.tagUpdate ).to.equal( true )
} )

it( 'Should delete a tag', async ( ) => {
const res = await sendRequest( userA.token, { query: `mutation{ tagDelete(streamId:"${ts1}", tagId:"${tag3.id}")}` } )
expect( res ).to.be.json
expect( res.body.errors ).to.not.exist
expect( res.body.data ).to.have.property( 'tagDelete' )
expect( res.body.data.tagDelete ).to.equal( true )
} )

it( 'Should create several branches', async ( ) => {
const res1 = await sendRequest( userA.token, { query: `mutation($branch:BranchCreateInput!) { branchCreate(streamId:"${ts1}", branch:$branch) }`, variables: { branch: b1 } } )
expect( res1 ).to.be.json
Expand Down

0 comments on commit 13b6ccb

Please sign in to comment.