ユーザやグループを操作する

このセクションでは、ユーザやグループを作成する方法、ユーザをグループに割り当てる方法を学びます。

これはifPeople(http://www.ifpeople.net)のPlone/Zopeトレーニングのために書かれた、Plone APIの紹介資料です(Plone 2.0と2.1に対応)。原文はEmanuel Sartor(http://www.menttes.com)によって書かれ、Natalia B. Bidartによって英訳されました。スペイン語バージョンはhttp://www.ifpeople.net/fairsource/courses/material/apiPloneで見ることができます。
Page 4 of 5.

例10: ユーザを追加する

下記のスクリプトを見てください。

id = "user"
fullname = "Emanuel Sartor"
password = "changeme"
email = "emanuel@menttes.com"
roles = ("Manager",)
status=""
props = {"username": id,
         "fullname": fullname,
         "password": password,
         "email": email}
# add a new member to the Portal
try:
    context.portal_registration.addMember(id, password, roles,domains="",
                                          properties=props)
    status+="The user "+fullname+" was successfully added.\n"
except:
    status+="The user "+fullname+" was not added.\n"
print status
return printed
  • addMember(self, id, password, roles, domains, properties) このメソッドはPortalMemberを生成して返します。

More on RegistrationTool-class.html

例11: Group0.という名前のグループを作成する

次の例を見てください。

groupname = "Group0"
status=""
# add a new group
try:
    context.portal_groups.addGroup(groupname,)
    status += "The group was successfully added.\n"
except:
    status += "Manager group couldn't be added\n"
print status
return printed
  • addGroup(self, id, roles, groups, args, *kw)

More on GroupsTool-class.html

例12: グループにユーザを追加する

次のようにします。

id = "usuario"
groupname = "Group0"
status=""
# assign the user "user" to the group "groupname"
try:
    group = context.portal_groups.getGroupById(groupname)
    group.addMember(id)
    status += "The user "+id+" was successfully added to "+groupname+".\n"
except:
    status += "The user "+id+" was not added to group "+groupname+".\n"
print status
return printed