Commit e5b74698 authored by Florian Hübsch's avatar Florian Hübsch
Browse files

Merge pull request #220 from ninjaconcept/220-for-ui-state-with-user-scope

Checking All Checkbox of Samples disables share button
parents 3746c3b3 be83acee
...@@ -106,10 +106,10 @@ module Chemotion ...@@ -106,10 +106,10 @@ module Chemotion
end end
before do before do
samples = Sample.for_ui_state(params[:elements_filter][:sample]) samples = Sample.for_user(current_user.id).for_ui_state(params[:elements_filter][:sample])
reactions = Reaction.for_ui_state(params[:elements_filter][:reaction]) reactions = Reaction.for_user(current_user.id).for_ui_state(params[:elements_filter][:reaction])
wellplates = Wellplate.for_ui_state(params[:elements_filter][:wellplate]) wellplates = Wellplate.for_user(current_user.id).for_ui_state(params[:elements_filter][:wellplate])
screens = Screen.for_ui_state(params[:elements_filter][:screen]) screens = Screen.for_user(current_user.id).for_ui_state(params[:elements_filter][:screen])
top_secret_sample = samples.pluck(:is_top_secret).any? top_secret_sample = samples.pluck(:is_top_secret).any?
top_secret_reaction = reactions.flat_map(&:samples).map(&:is_top_secret).any? top_secret_reaction = reactions.flat_map(&:samples).map(&:is_top_secret).any?
...@@ -160,7 +160,7 @@ module Chemotion ...@@ -160,7 +160,7 @@ module Chemotion
current_collection_id = ui_state[:currentCollectionId] current_collection_id = ui_state[:currentCollectionId]
collection_id = params[:collection_id] collection_id = params[:collection_id]
sample_ids = Sample.for_ui_state_with_collection( sample_ids = Sample.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:sample], ui_state[:sample],
CollectionsSample, CollectionsSample,
current_collection_id current_collection_id
...@@ -175,7 +175,7 @@ module Chemotion ...@@ -175,7 +175,7 @@ module Chemotion
CollectionsSample.find_or_create_by(sample_id: id, collection_id: collection_id) CollectionsSample.find_or_create_by(sample_id: id, collection_id: collection_id)
} }
reaction_ids = Reaction.for_ui_state_with_collection( reaction_ids = Reaction.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:reaction], ui_state[:reaction],
CollectionsReaction, CollectionsReaction,
current_collection_id current_collection_id
...@@ -190,7 +190,7 @@ module Chemotion ...@@ -190,7 +190,7 @@ module Chemotion
CollectionsReaction.find_or_create_by(reaction_id: id, collection_id: collection_id) CollectionsReaction.find_or_create_by(reaction_id: id, collection_id: collection_id)
} }
wellplate_ids = Wellplate.for_ui_state_with_collection( wellplate_ids = Wellplate.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:wellplate], ui_state[:wellplate],
CollectionsWellplate, CollectionsWellplate,
current_collection_id current_collection_id
...@@ -205,7 +205,7 @@ module Chemotion ...@@ -205,7 +205,7 @@ module Chemotion
CollectionsWellplate.find_or_create_by(wellplate_id: id, collection_id: collection_id) CollectionsWellplate.find_or_create_by(wellplate_id: id, collection_id: collection_id)
} }
screen_ids = Screen.for_ui_state_with_collection( screen_ids = Screen.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:screen], ui_state[:screen],
CollectionsScreen, CollectionsScreen,
current_collection_id current_collection_id
...@@ -231,7 +231,7 @@ module Chemotion ...@@ -231,7 +231,7 @@ module Chemotion
collection_id = params[:collection_id] collection_id = params[:collection_id]
current_collection_id = ui_state[:currentCollectionId] current_collection_id = ui_state[:currentCollectionId]
Sample.for_ui_state_with_collection( Sample.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:sample], ui_state[:sample],
CollectionsSample, CollectionsSample,
current_collection_id current_collection_id
...@@ -239,7 +239,7 @@ module Chemotion ...@@ -239,7 +239,7 @@ module Chemotion
CollectionsSample.find_or_create_by(sample_id: id, collection_id: collection_id) CollectionsSample.find_or_create_by(sample_id: id, collection_id: collection_id)
end end
Reaction.for_ui_state_with_collection( Reaction.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:reaction], ui_state[:reaction],
CollectionsReaction, CollectionsReaction,
current_collection_id current_collection_id
...@@ -247,7 +247,7 @@ module Chemotion ...@@ -247,7 +247,7 @@ module Chemotion
CollectionsReaction.find_or_create_by(reaction_id: id, collection_id: collection_id) CollectionsReaction.find_or_create_by(reaction_id: id, collection_id: collection_id)
end end
Wellplate.for_ui_state_with_collection( Wellplate.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:wellplate], ui_state[:wellplate],
CollectionsWellplate, CollectionsWellplate,
current_collection_id current_collection_id
...@@ -255,7 +255,7 @@ module Chemotion ...@@ -255,7 +255,7 @@ module Chemotion
CollectionsWellplate.find_or_create_by(wellplate_id: id, collection_id: collection_id) CollectionsWellplate.find_or_create_by(wellplate_id: id, collection_id: collection_id)
end end
Screen.for_ui_state_with_collection( Screen.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:screen], ui_state[:screen],
CollectionsScreen, CollectionsScreen,
current_collection_id current_collection_id
......
...@@ -33,10 +33,10 @@ module Chemotion ...@@ -33,10 +33,10 @@ module Chemotion
end end
post do post do
top_secret_sample = Sample.for_ui_state(params[:elements_filter][:sample]).pluck(:is_top_secret).any? top_secret_sample = Sample.for_user(current_user.id).for_ui_state(params[:elements_filter][:sample]).pluck(:is_top_secret).any?
top_secret_reaction = Reaction.for_ui_state(params[:elements_filter][:reaction]).flat_map(&:samples).map(&:is_top_secret).any? top_secret_reaction = Reaction.for_user(current_user.id).for_ui_state(params[:elements_filter][:reaction]).flat_map(&:samples).map(&:is_top_secret).any?
top_secret_wellplate = Wellplate.for_ui_state(params[:elements_filter][:wellplate]).flat_map(&:samples).map(&:is_top_secret).any? top_secret_wellplate = Wellplate.for_user(current_user.id).for_ui_state(params[:elements_filter][:wellplate]).flat_map(&:samples).map(&:is_top_secret).any?
top_secret_screen = Screen.for_ui_state(params[:elements_filter][:screen]).flat_map(&:wellplates).flat_map(&:samples).map(&:is_top_secret).any? top_secret_screen = Screen.for_user(current_user.id).for_ui_state(params[:elements_filter][:screen]).flat_map(&:wellplates).flat_map(&:samples).map(&:is_top_secret).any?
is_top_secret = top_secret_sample || top_secret_wellplate || top_secret_reaction || top_secret_screen is_top_secret = top_secret_sample || top_secret_wellplate || top_secret_reaction || top_secret_screen
...@@ -75,10 +75,10 @@ module Chemotion ...@@ -75,10 +75,10 @@ module Chemotion
end end
post do post do
sharing_allowed_sample = ElementsPolicy.new(current_user, Sample.for_ui_state(params[:elements_filter][:sample])).share? sharing_allowed_sample = ElementsPolicy.new(current_user, Sample.for_user(current_user.id).for_ui_state(params[:elements_filter][:sample])).share?
sharing_allowed_reaction = ElementsPolicy.new(current_user, Reaction.for_ui_state(params[:elements_filter][:reaction])).share? sharing_allowed_reaction = ElementsPolicy.new(current_user, Reaction.for_user(current_user.id).for_ui_state(params[:elements_filter][:reaction])).share?
sharing_allowed_wellplate = ElementsPolicy.new(current_user, Wellplate.for_ui_state(params[:elements_filter][:wellplate])).share? sharing_allowed_wellplate = ElementsPolicy.new(current_user, Wellplate.for_user(current_user.id).for_ui_state(params[:elements_filter][:wellplate])).share?
sharing_allowed_screen = ElementsPolicy.new(current_user, Screen.for_ui_state(params[:elements_filter][:screen])).share? sharing_allowed_screen = ElementsPolicy.new(current_user, Screen.for_user(current_user.id).for_ui_state(params[:elements_filter][:screen])).share?
sharing_allowed = sharing_allowed_sample && sharing_allowed_reaction && sharing_allowed_wellplate && sharing_allowed_screen sharing_allowed = sharing_allowed_sample && sharing_allowed_reaction && sharing_allowed_wellplate && sharing_allowed_screen
...@@ -117,10 +117,10 @@ module Chemotion ...@@ -117,10 +117,10 @@ module Chemotion
end end
post do post do
deletion_allowed_sample = ElementsPolicy.new(current_user, Sample.for_ui_state(params[:elements_filter][:sample])).destroy? deletion_allowed_sample = ElementsPolicy.new(current_user, Sample.for_user(current_user.id).for_ui_state(params[:elements_filter][:sample])).destroy?
deletion_allowed_reaction = ElementsPolicy.new(current_user, Reaction.for_ui_state(params[:elements_filter][:reaction])).destroy? deletion_allowed_reaction = ElementsPolicy.new(current_user, Reaction.for_user(current_user.id).for_ui_state(params[:elements_filter][:reaction])).destroy?
deletion_allowed_wellplate = ElementsPolicy.new(current_user, Wellplate.for_ui_state(params[:elements_filter][:wellplate])).destroy? deletion_allowed_wellplate = ElementsPolicy.new(current_user, Wellplate.for_user(current_user.id).for_ui_state(params[:elements_filter][:wellplate])).destroy?
deletion_allowed_screen = ElementsPolicy.new(current_user, Screen.for_ui_state(params[:elements_filter][:screen])).share? deletion_allowed_screen = ElementsPolicy.new(current_user, Screen.for_user(current_user.id).for_ui_state(params[:elements_filter][:screen])).share?
deletion_allowed = deletion_allowed_sample && deletion_allowed_reaction && deletion_allowed_wellplate && deletion_allowed_screen deletion_allowed = deletion_allowed_sample && deletion_allowed_reaction && deletion_allowed_wellplate && deletion_allowed_screen
......
...@@ -14,11 +14,11 @@ module Chemotion ...@@ -14,11 +14,11 @@ module Chemotion
end end
before do before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Reaction.for_ui_state(params[:ui_state])).destroy? error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Reaction.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end end
delete do delete do
Reaction.for_ui_state(params[:ui_state]).destroy_all Reaction.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end end
end end
...@@ -72,7 +72,7 @@ module Chemotion ...@@ -72,7 +72,7 @@ module Chemotion
end end
delete do delete do
Reaction.for_ui_state(params[:ui_state]).destroy_all Reaction.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end end
end end
......
...@@ -15,11 +15,11 @@ module Chemotion ...@@ -15,11 +15,11 @@ module Chemotion
end end
before do before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Sample.for_ui_state(params[:ui_state])).destroy? error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Sample.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end end
delete do delete do
Sample.for_ui_state(params[:ui_state]).destroy_all Sample.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end end
end end
...@@ -31,7 +31,7 @@ module Chemotion ...@@ -31,7 +31,7 @@ module Chemotion
post do post do
ui_state = params[:ui_state] ui_state = params[:ui_state]
currentCollectionId = ui_state[:currentCollectionId] currentCollectionId = ui_state[:currentCollectionId]
sample_ids = Sample.for_ui_state_with_collection(ui_state[:sample], CollectionsSample, currentCollectionId) sample_ids = Sample.for_user(current_user.id).for_ui_state_with_collection(ui_state[:sample], CollectionsSample, currentCollectionId)
Sample.where(id: sample_ids).each do |sample| Sample.where(id: sample_ids).each do |sample|
#todo: extract method into Sample #todo: extract method into Sample
subsample = sample.dup subsample = sample.dup
......
...@@ -119,11 +119,11 @@ module Chemotion ...@@ -119,11 +119,11 @@ module Chemotion
end end
before do before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Screen.for_ui_state(params[:ui_state])).destroy? error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Screen.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end end
delete do delete do
Screen.for_ui_state(params[:ui_state]).destroy_all Screen.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end end
end end
......
...@@ -14,11 +14,11 @@ module Chemotion ...@@ -14,11 +14,11 @@ module Chemotion
end end
before do before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Wellplate.for_ui_state(params[:ui_state])).destroy? error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Wellplate.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end end
delete do delete do
Wellplate.for_ui_state(params[:ui_state]).destroy_all Wellplate.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end end
end end
...@@ -167,11 +167,11 @@ module Chemotion ...@@ -167,11 +167,11 @@ module Chemotion
end end
before do before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Screen.for_ui_state(params[:ui_state])).destroy? error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Screen.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end end
delete do delete do
Screen.for_ui_state(params[:ui_state]).destroy_all Screen.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end end
end end
......
...@@ -9,7 +9,8 @@ export default class ShareButton extends React.Component { ...@@ -9,7 +9,8 @@ export default class ShareButton extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
isTopSecret: false isTopSecret: false,
isDisabled: props.isDisabled
} }
} }
...@@ -21,6 +22,12 @@ export default class ShareButton extends React.Component { ...@@ -21,6 +22,12 @@ export default class ShareButton extends React.Component {
PermissionStore.unlisten(this.onPermissionChange.bind(this)); PermissionStore.unlisten(this.onPermissionChange.bind(this));
} }
componentWillReceiveProps(nextProps) {
this.setState({
isDisabled: nextProps.isDisabled
})
}
onPermissionChange(state) { onPermissionChange(state) {
this.setState({ this.setState({
isTopSecret: state.is_top_secret isTopSecret: state.is_top_secret
...@@ -60,13 +67,12 @@ export default class ShareButton extends React.Component { ...@@ -60,13 +67,12 @@ export default class ShareButton extends React.Component {
} }
render() { render() {
const {isDisabled} = this.props;
const tooltip = ( const tooltip = (
<Tooltip>Share</Tooltip> <Tooltip>Share</Tooltip>
); );
return ( return (
<OverlayTrigger placement="bottom" overlay={tooltip}> <OverlayTrigger placement="bottom" overlay={tooltip}>
<Button bsStyle="info" onClick={this.showShareModal.bind(this)} disabled={isDisabled}> <Button bsStyle="info" onClick={this.showShareModal.bind(this)} disabled={this.state.isDisabled}>
<i className="fa fa-share-alt"></i> <i className="fa fa-share-alt"></i>
</Button> </Button>
</OverlayTrigger> </OverlayTrigger>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment