Revision 61120649

View differences:

src/oca/java/src/org/opennebula/client/user/User.java
33 33
    private static final String DELETE          = METHOD_PREFIX + "delete";
34 34
    private static final String PASSWD          = METHOD_PREFIX + "passwd";
35 35
    private static final String CHGRP           = METHOD_PREFIX + "chgrp";
36
    private static final String ADDGROUP        = METHOD_PREFIX + "addgroup";
37
    private static final String DELGROUP        = METHOD_PREFIX + "delgroup";
38 36
    
39 37
    /**
40 38
     * Creates a new User representation.
......
127 125
        return client.call(CHGRP, id, gid);
128 126
    }
129 127

  
130
    /**
131
     * Adds this user to a secondary group
132
     * 
133
     * @param client XML-RPC Client.
134
     * @param id The user id (uid) of the target user we want to modify.
135
     * @param gid The new group ID.
136
     * @return If an error occurs the error message contains the reason.
137
     */
138
    public static OneResponse addgroup(Client client, int id, int gid)
139
    {
140
        return client.call(ADDGROUP, id, gid);
141
    }
142

  
143
    /**
144
     * Removes this user from a secondary group
145
     * 
146
     * @param client XML-RPC Client.
147
     * @param id The user id (uid) of the target user we want to modify.
148
     * @param gid The new group ID.
149
     * @return If an error occurs the error message contains the reason.
150
     */
151
    public static OneResponse delgroup(Client client, int id, int gid)
152
    {
153
        return client.call(DELGROUP, id, gid);
154
    }
155

  
156 128
    // =================================
157 129
    // Instanced object XML-RPC methods
158 130
    // =================================
......
203 175
        return chgrp(client, id, gid);
204 176
    }
205 177

  
206
    /**
207
     * Adds this user to a secondary group
208
     * 
209
     * @param gid The new group ID.
210
     * @return If an error occurs the error message contains the reason.
211
     */
212
    public OneResponse addgroup(int gid)
213
    {
214
        return addgroup(client, id, gid);
215
    }
216

  
217
    /**
218
     * Removes this user from a secondary group
219
     * 
220
     * @param gid The new group ID.
221
     * @return If an error occurs the error message contains the reason.
222
     */
223
    public OneResponse delgroup(int gid)
224
    {
225
        return delgroup(client, id, gid);
226
    }
227

  
228 178
    // =================================
229 179
    // Helpers
230 180
    // =================================
......
239 189
        String enabled = xpath("ENABLED");
240 190
        return enabled != null && enabled.equals("1");
241 191
    }
242

  
243
    /**
244
     * Returns whether or not the user is part of the group
245
     * 
246
     * @param gid The group ID.
247
     * @return whether or not the user is part of the group
248
     */
249
    public boolean isPartOf(int gid)
250
    {
251
        String res = xpath("GROUPS/ID[.="+gid+"]");
252
        return res != null && res.equals(""+gid);
253
    }
254 192
}
src/oca/java/test/GroupTest.java
133 133
    }
134 134

  
135 135
//  Commented out, secondary groups do not exist any more
136
//    @Test
136
/*
137
    @Test
137 138
    public void userGroupRelations()
138 139
    {
139 140
        Hashtable<String, User> users   = new Hashtable<String, User>();
......
221 222
        assertTrue(  groups.get("d").contains( users.get("c").id() ) );
222 223
        assertTrue(  groups.get("d").contains( users.get("d").id() ) );
223 224
    }
224

  
225
*/
225 226
}
src/oca/ruby/OpenNebula/User.rb
26 26
            :allocate => "user.allocate",
27 27
            :delete   => "user.delete",
28 28
            :passwd   => "user.passwd",
29
            :chgrp    => "user.chgrp",
30
            :addgroup => "user.addgroup",
31
            :delgroup => "user.delgroup"
29
            :chgrp    => "user.chgrp"
32 30
        }
33 31

  
34 32
        SELF = -1
......
115 113
        def gid
116 114
            self['GID'].to_i
117 115
        end
118

  
119
        # Returns whether or not the user is part of the group 'gid'
120
        def is_part_of(gid)
121
            return self["GROUPS/ID[.=#{gid}]"] != nil
122
        end
123

  
124
        # Returns an array with the numeric group ids
125
        def group_ids
126
            array = Array.new
127

  
128
            self.each("GROUPS/ID") do |id|
129
                array << id.text.to_i
130
            end
131

  
132
            return array
133
        end
134 116
    end
135 117
end

Also available in: Unified diff