Skip to content

Commit cba3c1a

Browse files
authored
Fix project storage for write and admin users (#759)
## Purpose Avoid 401 or 403 error. ## Summary of Changes 1. Added condition to get storage for admin and write users.
1 parent 9aaf880 commit cba3c1a

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/app/features/project/overview/project-overview.component.spec.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,7 @@ import { ProjectOverviewToolbarComponent } from './components/project-overview-t
3737
import { RecentActivityComponent } from './components/recent-activity/recent-activity.component';
3838
import { ProjectOverviewModel } from './models';
3939
import { ProjectOverviewComponent } from './project-overview.component';
40-
import {
41-
ClearProjectOverview,
42-
GetComponents,
43-
GetProjectById,
44-
GetProjectStorage,
45-
ProjectOverviewSelectors,
46-
} from './store';
40+
import { ClearProjectOverview, GetComponents, GetProjectById, ProjectOverviewSelectors } from './store';
4741

4842
import { MOCK_PROJECT_OVERVIEW } from '@testing/mocks/project-overview.mock';
4943
import { OSFTestingModule } from '@testing/osf.testing.module';
@@ -139,7 +133,6 @@ describe('ProjectOverviewComponent', () => {
139133
component.ngOnInit();
140134

141135
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetProjectById));
142-
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetProjectStorage));
143136
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetBookmarksCollectionId));
144137
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetComponents));
145138
expect(store.dispatch).toHaveBeenCalledWith(expect.any(GetLinkedResources));

src/app/features/project/overview/project-overview.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export class ProjectOverviewComponent implements OnInit {
183183

184184
if (projectId) {
185185
this.actions.getProject(projectId);
186-
this.actions.getProjectStorage(projectId);
187186
this.actions.getBookmarksId();
188187
this.actions.getComponents(projectId);
189188
this.actions.getLinkedProjects(projectId);
@@ -256,6 +255,14 @@ export class ProjectOverviewComponent implements OnInit {
256255
this.actions.getHomeWiki(ResourceType.Project, project.id);
257256
}
258257
});
258+
259+
effect(() => {
260+
const project = this.currentProject();
261+
262+
if (project && this.hasWriteAccess()) {
263+
this.actions.getProjectStorage(project.id);
264+
}
265+
});
259266
}
260267

261268
private setupAddonsEffects(): void {

src/app/shared/pipes/file-size.pipe.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@ import { Pipe, PipeTransform } from '@angular/core';
44
name: 'fileSize',
55
})
66
export class FileSizePipe implements PipeTransform {
7-
transform(bytes: number): string {
8-
if (!bytes) {
9-
return '';
10-
} else if (bytes < 1024) {
7+
private readonly SI_UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
8+
private readonly BINARY_UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
9+
10+
transform(bytes: number | null | undefined, si = true): string {
11+
if (bytes == null) return '0 B';
12+
13+
const threshold = si ? 1000 : 1024;
14+
const units = si ? this.SI_UNITS : this.BINARY_UNITS;
15+
const absBytes = Math.abs(bytes);
16+
17+
if (absBytes < threshold) {
1118
return `${bytes} B`;
12-
} else if (bytes < 1024 ** 2) {
13-
return `${(bytes / 1024).toFixed(1)} kB`;
14-
} else if (bytes < 1024 ** 3) {
15-
return `${(bytes / 1024 ** 2).toFixed(1)} MB`;
16-
} else {
17-
return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
1819
}
20+
21+
const exponent = Math.min(Math.floor(Math.log(absBytes) / Math.log(threshold)), units.length - 1);
22+
23+
const value = bytes / Math.pow(threshold, exponent);
24+
25+
return `${value.toFixed(1)} ${units[exponent]}`;
1926
}
2027
}

0 commit comments

Comments
 (0)