Google グループ: メンバー, 削除
Google グループ: メンバー, 削除 (Google Groups: Members, Delete)
Google グループから1件のメールアドレスを削除します。複数のグループから一括して削除することも可能です。人事異動時のオペレーションを自動化できます。
Configs
  • A: HTTP認証設定を選択してください *
  • B: 削除するアドレスをセットしてください *#{EL}
  • B2: メールアドレスのログ出力についての真偽値をセットしてください (true:デフォルト, false:出力しない)#{EL}
  • C: 削除元 Google グループ(複数行可)のアドレスをセットしてください *#{EL}
Script (click to open)
// GraalJS Script (engine type: 2)
/*
NOTES
- Google Group for Google Workspace can be used as a team mailing list.
- This addon will automatically delete one email to groups via Google APIs. (Admin SDK Directory API)
- You can delete group email addresses as well as user email addresses.
- If the email does not already exists, the Warning log (409) will be output.
- If the log output of the target email address is not appropriate, set "false".
    - Personal information protection, various laws and regulations, security policies, etc.

NOTES-ja
- ビジネス向けGoogleグループは、メーリングリストとして利用ができます。(Google Workspace)
- このアドオンは、1つのメールアドレスを Google API 経由で自動削除します。(Admin SDK Directory API)
- ユーザアドレスだけでなく、グループアドレスも削除できます。
- 当該メールアドレスが、既に存在しない場合は、Warning ログ(404)が出力されます。
- 対象メールアドレスのログが適切でない場合、ログ出力に "false" を設定して下さい。
    - 個人情報保護の観点や各種法令セキュリティポリシーなど
*/


/*
APPENDIX
- OAuth Setting sample [HTTP Authorization Setting]
    - "Authorization Endpoint URL"
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - "Token Endpoint URL"
        - https://accounts.google.com/o/oauth2/token
    - to get your "ClientId" and "Secret"
        - Access to https://console.developers.google.com/apis/credentials
- Authorization Scopes (one of the following)
    - https://apps-apis.google.com/a/feeds/groups/
    - https://www.googleapis.com/auth/admin.directory.group
    - https://www.googleapis.com/auth/admin.directory.group.member

APPENDIX-ja
- OAuth 設定例([HTTP認証設定]の例)
    - "Authorization Endpoint URL"
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - "Token Endpoint URL"
        - https://accounts.google.com/o/oauth2/token
    - なお "ClientId" と "Secret" は開発者コンソールにアクセスして取得します。
        - Access to https://console.developers.google.com/apis/credentials
- 認可スコープ(以下のいずれか)
    - https://apps-apis.google.com/a/feeds/groups/
    - https://www.googleapis.com/auth/admin.directory.group
    - https://www.googleapis.com/auth/admin.directory.group.member
*/


//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting   = configs.get( "AuthzConfA" ); // required (Authz by Basic_AuthN)
  engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strLog            = configs.get( "StrConfB2" ) + "";
  let boolLog           = true;
  if( strLog          === "false" ){
      boolLog           = false;
  }
const strTargetEmail    = configs.get( "StrConfB" ) + "";
  if( boolLog ){
    engine.log( " AutomatedTask Config: Target Email: " + strTargetEmail );
  }
const strGroupEmails    = configs.get( "StrConfC" ) + ""; // "groupKey"
  if( strGroupEmails   === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {C Group Address} not specified \n" );
  }
  const arrGroupEmails  = strGroupEmails.split("\n");
  engine.log( " AutomatedTask Config: Group Emails: " + arrGroupEmails.length );
  engine.log( strGroupEmails );


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing)


//// == Calculating / 演算 ==

/// Removes a member from a group.
/// (Google Workspace Developer > Admin SDK > Directory API)
/// https://developers.google.com/admin-sdk/directory/reference/rest/v1/members/delete

for( let i = 0; i < arrGroupEmails.length; i++ ){
  // request1, prepare
  let deleteUri1  = "https://admin.googleapis.com/admin/directory/v1/groups/" +
                 arrGroupEmails[i] + "/members/" + strTargetEmail;
  let request1 = httpClient.begin(); // HttpRequestWrapper
      request1 = request1.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
  // request1, try
  const response1     = request1.delete( deleteUri1 ); // HttpResponseWrapper
  if( boolLog ){
    engine.log( " AutomatedTask ApiRequest1 Start: " + deleteUri1 );
  }else{
    engine.log( " AutomatedTask ApiRequest1 Start: " + arrGroupEmails[i] );
  }
  const response1Code = response1.getStatusCode() + ""; // (primitive string)
  const response1Body = response1.getResponseAsString() + "";
  engine.log( " AutomatedTask ApiResponse Status: " + response1Code );
  if( response1Code === "404"){
    engine.log( " AutomatedTask ConflictWarning:" +
                      response1Code + "\n" + response1Body );
  }else if( response1Code !== "204"){
    throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                      response1Code + "\n" + response1Body + "\n" );
  }
  // response1, parse
  /* engine.log( response1Body ); // debug
  (response none)
  */
}


//// == Data Updating / ワークフローデータへの代入 ==
// (No Output except Console Log)


} //////// END "main()" /////////////////////////////////////////////////////////////////



Download

2021-01-23 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/google-groups-members-delete/
Addonファイルのインポートは Professional でのみご利用いただけます

Notes

  • ビジネス向けGoogleグループは、メーリングリストとして利用ができます。(Google Workspace)
  • このアドオンは、1つのメールアドレスを Google API 経由で自動削除します。(Admin SDK Directory API)
  • ユーザアドレスだけでなく、グループアドレスも削除できます。
  • 当該メールアドレスが、既に存在しない場合は、Warning ログ(404)が出力されます。
  • 対象メールアドレスのログが適切でない場合、ログ出力に “false” を設定して下さい。
    • 個人情報保護の観点や各種法令セキュリティポリシーなど

Capture

Google グループから1件のメールアドレスを削除します。複数のグループから一括して削除することも可能です。人事異動時のオペレーションを自動化できます。

Appendix

See also

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

%d人のブロガーが「いいね」をつけました。