~dhis2-devs-core/+junk/dhis2-xml-ng

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/RemoveRoleAction.java

  • Committer: Tran Chau
  • Date: 2009-12-21 08:11:39 UTC
  • Revision ID: tran.hispvietnam@gmail.com-20091221081139-p5hkaoklgey32vcz
Fix bug: Allowed to remove superuser user role

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
 */
29
29
 
 
30
import java.sql.BatchUpdateException;
 
31
 
 
32
import org.hibernate.exception.ConstraintViolationException;
 
33
import org.hisp.dhis.i18n.I18n;
 
34
import org.hisp.dhis.i18n.I18nFormat;
30
35
import org.hisp.dhis.user.UserAuthorityGroup;
 
36
import org.hisp.dhis.user.UserCredentials;
31
37
import org.hisp.dhis.user.UserStore;
 
38
import org.springframework.dao.DataIntegrityViolationException;
32
39
 
33
40
import com.opensymphony.xwork2.Action;
34
41
 
35
42
/**
36
43
 * @author Thanh Nguyen
37
44
 * @version $Id: RemoveRoleAction.java 5724 2008-09-18 14:37:01Z larshelg $
 
45
 * @version $Id: RemoveRoleAction.java 339942 2009-12-21 10:21:03Z chauthutran $
38
46
 */
39
 
public class RemoveRoleAction
40
 
    implements Action
41
 
{
42
 
    // -------------------------------------------------------------------------
43
 
    // Dependencies
44
 
    // -------------------------------------------------------------------------
45
 
 
46
 
    private UserStore userStore;
47
 
 
48
 
    public void setUserStore( UserStore userStore )
49
 
    {
50
 
        this.userStore = userStore;
51
 
    }
52
 
 
53
 
    // -------------------------------------------------------------------------
54
 
    // Input
55
 
    // -------------------------------------------------------------------------
56
 
 
57
 
    private Integer id;
58
 
 
59
 
    public void setId( Integer id )
60
 
    {
61
 
        this.id = id;
62
 
    }
63
 
 
64
 
    // -------------------------------------------------------------------------
65
 
    // Action implementation
66
 
    // -------------------------------------------------------------------------
67
 
    
68
 
    public String execute()
69
 
        throws Exception
70
 
    {
71
 
        UserAuthorityGroup authorityGroup = userStore.getUserAuthorityGroup( id );
72
 
        
73
 
        if ( authorityGroup != null )
74
 
        {
75
 
            userStore.deleteUserAuthorityGroup( authorityGroup );
76
 
        }
77
 
        
78
 
        return SUCCESS;
79
 
    }
 
47
public class RemoveRoleAction implements Action {
 
48
        // -------------------------------------------------------------------------
 
49
        // Dependencies
 
50
        // -------------------------------------------------------------------------
 
51
 
 
52
        private UserStore userStore;
 
53
 
 
54
        public void setUserStore(UserStore userStore) {
 
55
                this.userStore = userStore;
 
56
        }
 
57
 
 
58
        // -------------------------------------------------------------------------
 
59
        // Input
 
60
        // -------------------------------------------------------------------------
 
61
 
 
62
        private Integer id;
 
63
 
 
64
        public void setId(Integer id) {
 
65
                this.id = id;
 
66
        }
 
67
 
 
68
        private String message;
 
69
 
 
70
        public String getMessage() {
 
71
                return message;
 
72
        }
 
73
 
 
74
        private I18n i18n;
 
75
 
 
76
        public void setI18n(I18n i18n) {
 
77
                this.i18n = i18n;
 
78
        }
 
79
 
 
80
        // -------------------------------------------------------------------------
 
81
        // Action implementation
 
82
        // -------------------------------------------------------------------------
 
83
 
 
84
        public String execute() throws Exception {
 
85
                
 
86
                UserAuthorityGroup authorityGroup = userStore.getUserAuthorityGroup(id);
 
87
 
 
88
                if (authorityGroup != null) {
 
89
                        try{
 
90
                                userStore.deleteUserAuthorityGroup(authorityGroup);
 
91
                        }catch(DataIntegrityViolationException e){
 
92
                                message = i18n.getString("user_use_group");
 
93
                                return ERROR;   
 
94
                        }
 
95
                }
 
96
 
 
97
                return SUCCESS;
 
98
        }
80
99
}