Changeset 1092

Show
Ignore:
Timestamp:
07/14/09 12:21:08 (4 years ago)
Author:
glickn
Message:

Fixes #453 & #454 - Users will no longer see an edit or delete button for on a subsample or sample that they do not have permission to edit.

Users will no longer be able to add a subsample or a chemical analysis to a sample/subsample that they do not own. The link is still there, but if it is clicked and they do not have permission to add one, it will display a warning saying so. If the user is not logged in when they click the link, it will prompt them to log in.

Location:
trunk/mpdb-client/src/edu/rpi/metpetdb/client/ui/objects/details
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/mpdb-client/src/edu/rpi/metpetdb/client/ui/objects/details/SampleDetails.java

    r1088 r1092  
    4343import edu.rpi.metpetdb.client.ui.commands.ServerOp; 
    4444import edu.rpi.metpetdb.client.ui.dialogs.ConfirmationDialogBox; 
     45import edu.rpi.metpetdb.client.ui.dialogs.MDialogBox; 
    4546import edu.rpi.metpetdb.client.ui.input.ObjectEditorPanel; 
    4647import edu.rpi.metpetdb.client.ui.input.OnEnterPanel; 
     
    138139 
    139140                        protected boolean canEdit() { 
    140                                 // TODO temporary while testing permissions 
    141                                 // final Sample s = (Sample) getBean(); 
    142                                 // if (s.isPublicData()) 
    143                                 // return false; 
    144                                 // if (MpDb.isCurrentUser(s.getOwner())) 
    145                                 // return true; 
    146                                 // return false; 
    147                                 return true; 
     141                                final Sample s = (Sample) getBean(); 
     142                                if (MpDb.isCurrentUser(s.getOwner())) 
     143                                        return true; 
     144                                return false; 
    148145                        } 
    149146 
     
    202199                                        @Override 
    203200                                        public void command() { 
    204                                                 History.newItem(TokenSpace.createNewSubsample(p_sample 
     201                                                if(canEdit()){ 
     202                                                        History.newItem(TokenSpace.createNewSubsample(p_sample 
    205203                                                                .getBean())); 
     204                                                } else { 
     205                                                        noPermissionWarning(); 
     206                                                } 
    206207                                        } 
    207208                                }.begin(); 
     
    512513        } 
    513514         
     515        private boolean canEdit(){ 
     516                final Sample s = (Sample) p_sample.getBean(); 
     517                return MpDb.isCurrentUser(s.getOwner()); 
     518        } 
     519         
     520        private void noPermissionWarning(){ 
     521                final MDialogBox noPermissionBox = new MDialogBox(); 
     522                final FlowPanel container = new FlowPanel(); 
     523                container.add(new Label("You do not have the correct permissions to add a subsample.")); 
     524                Button ok = new Button("Ok"); 
     525                ok.addClickListener(new ClickListener(){ 
     526                        public void onClick(final Widget sender){ 
     527                                noPermissionBox.hide(); 
     528                        } 
     529                }); 
     530                container.add(ok); 
     531                noPermissionBox.setWidget(container); 
     532                noPermissionBox.show(); 
     533        } 
     534         
    514535        private void makeImagesPublicIfPublic(Sample sample) { 
    515536                //If it's private, just return, images default to private 
  • trunk/mpdb-client/src/edu/rpi/metpetdb/client/ui/objects/details/SubsampleDetails.java

    r1088 r1092  
    55import com.google.gwt.user.client.History; 
    66import com.google.gwt.user.client.rpc.AsyncCallback; 
     7import com.google.gwt.user.client.ui.Button; 
    78import com.google.gwt.user.client.ui.ClickListener; 
    89import com.google.gwt.user.client.ui.FlexTable; 
     10import com.google.gwt.user.client.ui.FlowPanel; 
    911import com.google.gwt.user.client.ui.HasHorizontalAlignment; 
    1012import com.google.gwt.user.client.ui.HasVerticalAlignment; 
     
    2628import edu.rpi.metpetdb.client.ui.commands.VoidLoggedInOp; 
    2729import edu.rpi.metpetdb.client.ui.dialogs.ConfirmationDialogBox; 
     30import edu.rpi.metpetdb.client.ui.dialogs.MDialogBox; 
    2831import edu.rpi.metpetdb.client.ui.input.ObjectEditorPanel; 
    2932import edu.rpi.metpetdb.client.ui.input.OnEnterPanel; 
     
    9598 
    9699                        protected boolean canEdit() { 
    97                                 // TODO temporary while testing permissions 
    98                                 // final Sample s = ((Subsample) getBean()).getSample(); 
    99                                 // if (s.isPublicData()) 
    100                                 // return false; 
    101                                 // if (MpDb.isCurrentUser(s.getOwner())) 
    102                                 // return true; 
    103                                 // return false; 
    104                                 return true; 
     100                                final Subsample s = ((Subsample) getBean()); 
     101                                if (MpDb.isCurrentUser(s.getOwner())) 
     102                                        return true; 
     103                                return false; 
    105104                        } 
    106105 
     
    171170                                new VoidLoggedInOp() { 
    172171                                        public void command() { 
    173                                                 History.newItem(TokenSpace 
     172                                                if(canEdit()){ 
     173                                                        History.newItem(TokenSpace 
    174174                                                                .createNewChemicalAnalysis(p_subsample 
    175175                                                                                .getBean())); 
     176                                                } else { 
     177                                                        noPermissionWarning(); 
     178                                                } 
    176179                                        } 
    177180                                }.begin(); 
     
    233236        } 
    234237         
     238        private boolean canEdit(){ 
     239                final Subsample s = ((Subsample) p_subsample.getBean()); 
     240                return MpDb.isCurrentUser(s.getOwner()); 
     241        } 
     242         
     243        private void noPermissionWarning(){ 
     244                final MDialogBox noPermissionBox = new MDialogBox(); 
     245                final FlowPanel container = new FlowPanel(); 
     246                container.add(new Label("You do not have the correct permissions to add a chemical analysis.")); 
     247                Button ok = new Button("Ok"); 
     248                ok.addClickListener(new ClickListener(){ 
     249                        public void onClick(final Widget sender){ 
     250                                noPermissionBox.hide(); 
     251                        } 
     252                }); 
     253                container.add(ok); 
     254                noPermissionBox.setWidget(container); 
     255                noPermissionBox.show(); 
     256        } 
     257         
    235258        private void makeImagesPublicIfPublic(Subsample subsample){ 
    236259                //If it's private, just return, images default to private