Permalink
Browse files

fix(permissions): remove uneeded AuthGuard, fix all permissions on al…

…l routes
  • Loading branch information...
jkuri committed Sep 4, 2017
1 parent 9725942 commit f23f952301c17885e262c7b8e3e5ffe29d64b9a8
@@ -40,6 +40,7 @@ export function getBuilds(
}

builds = builds.toJSON();

builds = builds.map(build => {
build.jobs = build.jobs.map(job => {
if (job.runs.length > 0) {
@@ -51,9 +52,16 @@ export function getBuilds(
return job;
});

// build.hasPermission = build.repository.permissions &&
// build.repository.permissions[0].permission;
build.hasPermission = true;
userId = parseInt(<any>userId, 10);
if (build.repository.permissions && build.repository.permissions.length) {
if (build.repository.permissions.findIndex(p => p.users_id === userId) !== -1) {
build.hasPermission = true;
} else {
build.hasPermission = false;
}
} else {
build.hasPermission = false;
}

return build;
});
@@ -114,10 +122,16 @@ export function getBuild(id: number, userId?: number): Promise<any> {
build.repository.access_token = null;
}

build.hasPermission = true;

// build.hasPermission = build.repository.permissions &&
// build.repository.permissions[0].permission;
userId = parseInt(<any>userId, 10);
if (build.repository.permissions && build.repository.permissions.length) {
if (build.repository.permissions.findIndex(p => p.users_id === userId) !== -1) {
build.hasPermission = true;
} else {
build.hasPermission = false;
}
} else {
build.hasPermission = false;
}

return build;
})
@@ -175,8 +189,16 @@ export function getLastBuild(userId?: number): Promise<any> {
return job;
});

build.hasPermission = build.repository.permissions &&
build.repository.permissions[0].permission;
userId = parseInt(<any>userId, 10);
if (build.repository.permissions && build.repository.permissions.length) {
if (build.repository.permissions.findIndex(p => p.users_id === userId) !== -1) {
build.hasPermission = true;
} else {
build.hasPermission = false;
}
} else {
build.hasPermission = false;
}

resolve(build);
});
@@ -161,7 +161,7 @@ export function addRepository(data: any): Promise<any> {
reject(result);
} else {
let repository = result.toJSON();
return addRepositoryPermissionToEveryone(result.id)
return addRepositoryPermissionToEveryone(repository.id)
.then(() => resolve(repository))
.catch(err => reject(err));
}
@@ -102,7 +102,7 @@ export function buildRoutes(): express.Router {

router.get('/:id/:userid?', (req: express.Request, res: express.Response) => {
if (req.params.userid) {
getBuild(req.params.id, req.params.userId).then(build => {
getBuild(req.params.id, req.params.userid).then(build => {
return res.status(200).json({ data: build });
});
} else {
@@ -9,7 +9,6 @@ import { ConfigServiceProvider } from './services/config.service';
import { ApiServiceProvider } from './services/api.service';
import { SocketServiceProvider } from './services/socket.service';
import { AuthGuardProvider, AuthGuard } from './services/auth-guard.service';
import { AccessGuardProvider, AccessGuard } from './services/access-guard.service';
import { AuthServiceProvider } from './services/auth.service';
import { EqualValidator } from './directives/equal-validator.directive';
import { SafeHtmlPipe } from './pipes/safe-html.pipe';
@@ -69,12 +68,12 @@ import { AppTeamComponent } from './components/app-team';
{
path: 'build/:id',
component: AppBuildDetailsComponent,
canActivate: [AuthGuard, AccessGuard]
canActivate: [AuthGuard]
},
{
path: 'job/:id',
component: AppJobComponent,
canActivate: [AuthGuard, AccessGuard]
canActivate: [AuthGuard]
},
{
path: 'repositories',
@@ -84,7 +83,7 @@ import { AppTeamComponent } from './components/app-team';
{
path: 'repo/:id',
component: AppRepositoryComponent,
canActivate: [AuthGuard, AccessGuard]
canActivate: [AuthGuard]
},
{
path: 'settings',
@@ -116,8 +115,7 @@ import { AppTeamComponent } from './components/app-team';
ApiServiceProvider,
SocketServiceProvider,
AuthServiceProvider,
AuthGuardProvider,
AccessGuardProvider
AuthGuardProvider
],
bootstrap: [ AppComponent ]
})
@@ -53,8 +53,7 @@ export class AppRepositoriesComponent implements OnInit {
this.loading = true;
const userId = this.userData && this.userData.id || null;
this.apiService.getRepositories(keyword, userId).subscribe(repositories => {
this.repositories =
repositories.filter(r => r.permissions.findIndex(p => p.permission) !== -1);
this.repositories = repositories;
this.repositories.forEach((repo: any, i) => {
this.apiService.getBadge(repo.id).subscribe(badge => {
if (badge.ok) {

This file was deleted.

Oops, something went wrong.

0 comments on commit f23f952

Please sign in to comment.