Skip to content

Commit 1ef11e4

Browse files
author
Adrian Herrmann
committed
feat: added column created_by and set access
1 parent 22bc287 commit 1ef11e4

File tree

10 files changed

+50
-16
lines changed

10 files changed

+50
-16
lines changed

app/api/helpers/cell_line_api_params_helpers.rb

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module CellLineApiParamsHelpers
3434
optional :mutation, type: String, desc: 'mutation of a cell line'
3535
optional :description, type: String, desc: 'description of a cell line sample'
3636
optional :short_label, type: String, desc: 'short label of a cell line sample'
37+
optional :created_by, type: Integer, desc: 'creator of cell line material'
3738
requires :container, type: Hash, desc: 'root Container of element'
3839
end
3940

app/javascript/src/apps/mydb/elements/details/cellLines/propertiesTab/GeneralProperties.js

+27-7
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,29 @@ import PropTypes from 'prop-types';
99
import CellLineName from 'src/apps/mydb/elements/details/cellLines/propertiesTab/CellLineName';
1010
import Amount from 'src/apps/mydb/elements/details/cellLines/propertiesTab/Amount';
1111
import InvalidPropertyWarning from 'src/apps/mydb/elements/details/cellLines/propertiesTab/InvalidPropertyWarning';
12+
import UserStore from 'src/stores/alt/stores/UserStore';
1213

1314
class GeneralProperties extends React.Component {
1415
// eslint-disable-next-line react/static-property-placement
1516
static contextType = StoreContext;
1617

18+
// eslint-disable-next-line class-methods-use-this
19+
checkPermission(attributeName) {
20+
const readonlyAttributes = [
21+
'Disease', 'Organism', 'Tissue', 'Growth medium', 'Mutation', 'Variant', 'Biosafety level',
22+
'Cryopreservation medium', 'Opt. growth temperature', 'Gender', 'Cell type', 'Material Description'
23+
];
24+
const { item } = this.props;
25+
const { currentUser } = UserStore.getState();
26+
if (item.created_by == null) {
27+
const { cellLineDetailsStore } = this.context;
28+
const cellLine = cellLineDetailsStore.cellLines(item.id);
29+
return readonlyAttributes.includes(attributeName)
30+
&& cellLine.created_by !== '' && cellLine.created_by !== currentUser.id.toString();
31+
}
32+
return readonlyAttributes.includes(attributeName) && item.created_by !== currentUser.id;
33+
}
34+
1735
renderOptionalAttribute(attributeName, defaultValue, onChangeCallBack) {
1836
return this.renderAttribute(attributeName, defaultValue, onChangeCallBack, true);
1937
}
@@ -43,7 +61,7 @@ class GeneralProperties extends React.Component {
4361
<Form.Label column sm={3}>{attributeName}</Form.Label>
4462
<Col sm={9}>
4563
<Form.Control
46-
disabled={readOnly}
64+
disabled={readOnly || this.checkPermission(attributeName)}
4765
className={styleClass}
4866
type="text"
4967
value={defaultValue}
@@ -69,10 +87,10 @@ class GeneralProperties extends React.Component {
6987
<Form.Label column sm={3}>Biosafety level</Form.Label>
7088
<Col sm={9}>
7189
<Select
72-
isDisabled={readOnly}
90+
isDisabled={readOnly || this.checkPermission('Biosafety level')}
7391
options={options}
7492
isClearable={false}
75-
value={options.find(({value}) => value === item.bioSafetyLevel)}
93+
value={options.find(({ value }) => value === item.bioSafetyLevel)}
7694
onChange={(e) => { cellLineDetailsStore.changeBioSafetyLevel(item.id, e.value); }}
7795
/>
7896
</Col>
@@ -117,7 +135,7 @@ class GeneralProperties extends React.Component {
117135
<Amount
118136
cellLineId={item.id}
119137
initialValue={item.amount}
120-
readOnly={readOnly}
138+
readOnly={readOnly || this.checkPermission('Amount')}
121139
/>
122140
</Col>
123141
<Col sm={3} className="amount-unit">
@@ -187,7 +205,7 @@ class GeneralProperties extends React.Component {
187205
{this.renderOptionalAttribute('Cell type', cellLineItem.cellType, (e) => {
188206
cellLineDetailsStore.changeCellType(cellLineId, e.target.value);
189207
})}
190-
{this.renderOptionalAttribute('Description', cellLineItem.materialDescription, (e) => {
208+
{this.renderOptionalAttribute('Material Description', cellLineItem.materialDescription, (e) => {
191209
cellLineDetailsStore.changeMaterialDescription(cellLineId, e.target.value);
192210
})}
193211
</Accordion.Body>
@@ -209,7 +227,7 @@ class GeneralProperties extends React.Component {
209227
{this.renderOptionalAttribute('Name of specific probe', cellLineItem.itemName, (e) => {
210228
cellLineDetailsStore.changeItemName(cellLineId, e.target.value);
211229
})}
212-
{this.renderOptionalAttribute('Description', cellLineItem.itemDescription, (e) => {
230+
{this.renderOptionalAttribute('Sample Description', cellLineItem.itemDescription, (e) => {
213231
cellLineDetailsStore.changeItemDescription(cellLineId, e.target.value);
214232
})}
215233
</Accordion.Body>
@@ -224,6 +242,8 @@ export default observer(GeneralProperties);
224242
GeneralProperties.propTypes = {
225243
readOnly: PropTypes.bool.isRequired,
226244
item: PropTypes.shape({
227-
id: PropTypes.string.isRequired
245+
id: PropTypes.string.isRequired,
246+
can_update: PropTypes.bool,
247+
created_by: PropTypes.number
228248
}).isRequired
229249
};

app/javascript/src/models/cellLine/CellLine.js

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default class CellLine extends Element {
4545
cellLine.cellType = response.cellline_material.cell_type;
4646
cellLine.bioSafetyLevel = response.cellline_material.biosafety_level;
4747
cellLine.cryopreservationMedium = response.cellline_material.cryo_pres_medium;
48+
cellLine.created_by = response.cellline_material.created_by;
4849
cellLine.is_new = false;
4950

5051
cellLine.container = response.container;
@@ -67,6 +68,7 @@ export default class CellLine extends Element {
6768
this.gender = cellLineItem.gender;
6869
this.materialDescription = cellLineItem.materialDescription;
6970
this.source = cellLineItem.source;
71+
this.created_by = cellLineItem.created_by;
7072
}
7173

7274
adoptPropsFromMobXModel(mobx) {
@@ -91,5 +93,6 @@ export default class CellLine extends Element {
9193
this.bioSafetyLevel = mobx.bioSafetyLevel;
9294
this.cellType = mobx.cellType;
9395
this.cryopreservationMedium = mobx.cryopreservationMedium;
96+
this.created_by = mobx.created_by;
9497
}
9598
}

app/javascript/src/stores/mobx/CellLineDetailsStore.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const CellLineItem = types
4444
growthMedium: '',
4545
itemDescription: '',
4646
itemName: '',
47+
created_by: '',
4748
changed: false
4849
}).views((self) => ({
4950
isAmountValid() {
@@ -165,6 +166,7 @@ export const CellLineDetailsStore = types
165166
item.mutation = properties.mutation;
166167
item.source = properties.source;
167168
item.growthMedium = properties.growth_medium;
169+
item.created_by = properties.created_by?.toString();
168170
},
169171
convertJsModelToMobxModel(container) {
170172
return CellLineAnalysis.create({
@@ -203,6 +205,7 @@ export const CellLineDetailsStore = types
203205
growthMedium: jsCellLineModel.growthMedium,
204206
itemName: jsCellLineModel.itemName,
205207
shortLabel: jsCellLineModel.short_label,
208+
created_by: jsCellLineModel.created_by?.toString(),
206209
}));
207210
}
208211
}))

app/models/cellline_material.rb

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# deleted_at :datetime
2323
# created_at :datetime not null
2424
# updated_at :datetime not null
25+
# created_by :integer
2526
#
2627
class CelllineMaterial < ApplicationRecord
2728
acts_as_paranoid

app/usecases/cell_lines/create.rb

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def create_cellline_material
4545
cryo_pres_medium: @params[:cryo_pres_medium],
4646
gender: @params[:gender],
4747
description: @params[:material_description],
48+
created_by: @current_user.id,
4849
)
4950
end
5051

app/usecases/cell_lines/update.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ def execute!
1616

1717
@cell_line_sample.cellline_material = find_material || create_new_material
1818
update_sample_properties
19-
update_material_properties(@cell_line_sample.cellline_material)
19+
if @cell_line_sample.cellline_material.created_by.nil? ||
20+
@cell_line_sample.cellline_material.created_by == @current_user.id
21+
update_material_properties(@cell_line_sample.cellline_material)
22+
end
2023
@cell_line_sample.save
2124
@cell_line_sample
2225
end

db/migrate/20250221105051_cell_lines_constraint.rb

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddColumnToCelllineMaterial < ActiveRecord::Migration[6.1]
4+
def change
5+
add_index :cellline_materials, %i[name source], unique: true
6+
add_column :cellline_materials, :created_by, :integer, null: true
7+
end
8+
end

db/schema.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2025_02_21_105051) do
13+
ActiveRecord::Schema.define(version: 2025_02_26_095051) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "hstore"
@@ -131,6 +131,7 @@
131131
t.datetime "deleted_at"
132132
t.datetime "created_at", precision: 6, null: false
133133
t.datetime "updated_at", precision: 6, null: false
134+
t.integer "created_by"
134135
t.index ["name", "source"], name: "index_cellline_materials_on_name_and_source", unique: true
135136
end
136137

0 commit comments

Comments
 (0)