Skip to content

Commit a8c62bd

Browse files
committed
Merge branch 'release/20.11.0'
2 parents b73efc9 + 9dc6946 commit a8c62bd

File tree

28 files changed

+550
-33
lines changed

28 files changed

+550
-33
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [20.11.0] - 2020-11-03
8+
### Added
9+
- storage caps support in quickfiles and draft registrations
10+
- translations for status message
11+
712
## [20.10.1] - 2020-10-01
813
### Fixed
914
- redundant wording for branded registries page title
@@ -1669,7 +1674,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
16691674
### Added
16701675
- Quick Files
16711676

1672-
[Unreleased]: https://github.com/CenterForOpenScience/ember-osf-web/compare/20.10.1...develop
1677+
[Unreleased]: https://github.com/CenterForOpenScience/ember-osf-web/compare/20.11.0...develop
1678+
[20.11.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/20.11.0
16731679
[20.10.1]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/20.10.1
16741680
[20.10.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/20.10.0
16751681
[20.9.1]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/20.9.1

app/adapters/node-storage.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import OsfAdapter from './osf-adapter';
2+
3+
export default class NodeStorageAdapter extends OsfAdapter {
4+
}
5+
6+
declare module 'ember-data/types/registries/adapter' {
7+
export default interface AdapterRegistry {
8+
'node-storage': NodeStorageAdapter;
9+
} // eslint-disable-line semi
10+
}

app/guid-user/quickfiles/controller.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@ export default class UserQuickfiles extends Controller {
107107
}),
108108
});
109109
}
110-
111110
yield file.move(node);
112111
yield this.flash.perform(file, this.intl.t('file_browser.successfully_moved'));
113112
this.allFiles.removeObject(file);
114113
return true;
115-
} catch (ex) {
116-
this.toast.error(this.intl.t('move_to_project.could_not_move_file'));
114+
} catch (e) {
115+
let toastMessage = this.intl.t('move_to_project.could_not_move_file');
116+
if (e.status === 507) {
117+
toastMessage = this.intl.t('move_to_project.storage_error');
118+
}
119+
captureException(e);
120+
this.toast.error(toastMessage);
117121
}
118122

119123
return false;

app/models/node-storage.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { computed } from '@ember/object';
2+
import DS from 'ember-data';
3+
4+
import OsfModel from './osf-model';
5+
6+
const { attr } = DS;
7+
8+
export enum StorageStatus {
9+
DEFAULT = 'DEFAULT',
10+
APPROACHING_PRIVATE = 'APPROACHING_PRIVATE',
11+
OVER_PRIVATE = 'OVER_PRIVATE',
12+
APPROACHING_PUBLIC = 'APPROACHING_PUBLIC',
13+
OVER_PUBLIC = 'OVER_PUBLIC',
14+
NOT_CALCULATED = 'NOT_CALCULATED',
15+
}
16+
17+
export default class NodeStorageModel extends OsfModel {
18+
@attr('string') storageLimitStatus!: StorageStatus;
19+
@attr('number') storageUsage!: number;
20+
21+
@computed('id', 'storageLimitStatus')
22+
get isOverStorageCap() {
23+
const node = this.store.peekRecord('node', this.id);
24+
if (node) {
25+
const status = this.storageLimitStatus;
26+
if (status === StorageStatus.OVER_PUBLIC) {
27+
return true;
28+
}
29+
if (!node.public) {
30+
if ([StorageStatus.OVER_PRIVATE, StorageStatus.APPROACHING_PUBLIC].includes(status)) {
31+
return true;
32+
}
33+
}
34+
}
35+
return false;
36+
}
37+
38+
@computed('id', 'storageLimitStatus')
39+
get isApproachingStorageCap() {
40+
const node = this.store.peekRecord('node', this.id);
41+
if (node) {
42+
if (!node.public && (this.storageLimitStatus === StorageStatus.APPROACHING_PRIVATE)) {
43+
return true;
44+
}
45+
if (node.public && (this.storageLimitStatus === StorageStatus.APPROACHING_PUBLIC)) {
46+
return true;
47+
}
48+
}
49+
return false;
50+
}
51+
}
52+
53+
declare module 'ember-data/types/registries/model' {
54+
export default interface ModelRegistry {
55+
'node-storage': NodeStorageModel;
56+
} // eslint-disable-line semi
57+
}

app/models/node.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import IdentifierModel from './identifier';
1717
import InstitutionModel from './institution';
1818
import LicenseModel from './license';
1919
import LogModel from './log';
20+
import NodeStorageModel from './node-storage';
2021
import { Permission } from './osf-model';
2122
import PreprintModel from './preprint';
2223
import RegionModel from './region';
@@ -163,6 +164,9 @@ export default class NodeModel extends BaseFileItem.extend(Validations, Collecta
163164
@belongsTo('node', { inverse: null })
164165
root!: DS.PromiseObject<NodeModel> & NodeModel;
165166

167+
@belongsTo('node-storage', { inverse: null })
168+
storage!: DS.PromiseObject<NodeStorageModel> & NodeStorageModel;
169+
166170
@hasMany('node', { inverse: null })
167171
linkedByNodes!: DS.PromiseManyArray<NodeModel>;
168172

app/serializers/node-storage.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import OsfSerializer from './osf-serializer';
2+
3+
export default class NodeStorageSerializer extends OsfSerializer {
4+
}
5+
6+
declare module 'ember-data/types/registries/serializer' {
7+
export default interface SerializerRegistry {
8+
'node-storage': NodeStorageSerializer;
9+
} // eslint-disable-line semi
10+
}

lib/osf-components/addon/components/file-browser/component.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import $ from 'jquery';
1414
import { layout, requiredAction } from 'ember-osf-web/decorators/component';
1515
import File from 'ember-osf-web/models/file';
1616
import Node from 'ember-osf-web/models/node';
17+
import NodeStorageModel from 'ember-osf-web/models/node-storage';
1718
import Analytics from 'ember-osf-web/services/analytics';
1819
import CurrentUser from 'ember-osf-web/services/current-user';
1920
import Ready from 'ember-osf-web/services/ready';
@@ -178,6 +179,20 @@ export default class FileBrowser extends Component {
178179
].filter(item => item.length);
179180
}
180181

182+
@computed('node.public', 'isProjectSelectorValid', 'isMoving')
183+
get isMoveButtonEnabled(): boolean {
184+
if (!this.isProjectSelectorValid || this.isMoving) {
185+
return false;
186+
}
187+
if (this.node) {
188+
const storage = this.node.belongsTo('storage').value() as NodeStorageModel;
189+
if (storage) {
190+
return !storage.isOverStorageCap;
191+
}
192+
}
193+
return true;
194+
}
195+
181196
didReceiveAttrs() {
182197
if (this.items && this.items.length) {
183198
this.items.filterBy('isSelected', true)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Component from '@ember/component';
2+
import { computed } from '@ember/object';
3+
import { alias, not } from '@ember/object/computed';
4+
5+
import { layout } from 'ember-osf-web/decorators/component';
6+
import Node from 'ember-osf-web/models/node';
7+
import NodeStorageModel from 'ember-osf-web/models/node-storage';
8+
9+
import template from './template';
10+
11+
@layout(template)
12+
export default class FileBrowserFileMoveMessages extends Component {
13+
project!: Node;
14+
15+
@alias('project.public') isPublicProject!: boolean;
16+
@not('project.isRoot') isChildNode!: boolean;
17+
18+
@computed('project.storage', 'isPublicProject')
19+
get shouldShowError(): boolean {
20+
return (this.project.belongsTo('storage').value() as NodeStorageModel).isOverStorageCap;
21+
}
22+
23+
@computed('project.storage', 'isPublicProject')
24+
get shouldShowWarning() {
25+
return (this.project.belongsTo('storage').value() as NodeStorageModel).isApproachingStorageCap;
26+
}
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<p class='m-t-lg'>
2+
{{t (concat
3+
'move_to_project.convert_or_copy_message.'
4+
(if this.isChildNode 'component' 'project')
5+
)}}
6+
</p>
7+
{{#unless this.isPublicProject}}
8+
<p data-test-no-longer-public class='text-danger m-t-sm'>
9+
{{t (concat
10+
'move_to_project.no_longer_public_warning.'
11+
(if this.isChildNode 'component' 'project')
12+
)}}
13+
</p>
14+
{{/unless}}
15+
{{#if this.shouldShowError}}
16+
<p data-test-file-move-error class='text-danger'>
17+
{{t 'move_to_project.storage_error'}}
18+
{{t 'move_to_project.storage_limit.learn_more' htmlSafe=true}}
19+
</p>
20+
{{/if}}
21+
{{#if this.shouldShowWarning}}
22+
<div data-test-file-move-warning class='text-warning'>
23+
{{t 'move_to_project.storage_limit.warning'}}
24+
</div>
25+
{{/if}}

lib/osf-components/addon/components/file-browser/template.hbs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,10 @@
369369
@validationChanged={{action (mut this.isProjectSelectorValid)}}
370370
@projectSelected={{action this.projectSelected}}
371371
@moveToNewProject={{action this.moveToNewProject}}
372-
/>
372+
as |projectSelector|
373+
>
374+
<FileBrowser::FileMoveMessages @project={{projectSelector.selected}} />
375+
</ProjectSelector>
373376
</modal.body>
374377
<modal.footer data-analytics-scope='File browser - Move to project Modal'>
375378
<OsfButton
@@ -394,7 +397,7 @@
394397
<OsfButton
395398
data-test-move-to-project-modal-perform-button
396399
data-analytics-name='Move'
397-
@disabled={{or (not this.isProjectSelectorValid) this.isMoving}}
400+
@disabled={{not this.isMoveButtonEnabled}}
398401
@onClick={{action (perform this.moveToProject)}}
399402
@type='primary'
400403
>

0 commit comments

Comments
 (0)