私は、ユーザーがサイトのそのセクションにアクセスするための適切なアクセス許可を持っている場合、使用のアクセス許可レベルとグループメンバシップを確認し、ダイアログボックスを起動するためのコードを用意しています。それが最後に到達したときの対話は、ユーザーごとに自動的に起動しますのでJavaScriptで複数変数間でグローバル変数を使用するにはどうすればよいですか?
function bindSettingsButton() {
$("#mt-ngw-personalsettings").on("click", function() {
RequestNewSite();
});
}
function RequestNewSite() {
var HasPermission = false;
var isGroupMember = false;
CheckCurrentUserMembership();
CheckUserHasEditPermissions();
CheckUserPermissions();
}
function CheckCurrentUserMembership() {
var clientContext = new SP.ClientContext.get_current();
this.currentUser = clientContext.get_web().get_currentUser();
clientContext.load(this.currentUser);
this.userGroups = this.currentUser.get_groups();
clientContext.load(this.userGroups);
clientContext.executeQueryAsync(OnQuerySucceeded, OnQueryFailed);
}
function OnQuerySucceeded() {
var isMember = false;
var groupsEnumerator = userGroups.getEnumerator();
while (groupsEnumerator.moveNext()) {
var group = groupsEnumerator.get_current();
if(group.get_title() == "Create Site OptOut") {
isMember = true;
this.isGroupMember = true;
break;
}
}
}
function OnQueryFailed()
{
alert("Couldn't check user group membership. Please contact to resolve this issue.");
}
function CheckUserHasEditPermissions() {
context = new SP.ClientContext.get_current();
web = context.get_web();
this._currentUser = web.get_currentUser();
this._theList = web.get_lists().getByTitle('siterequests');
context.load(this._currentUser);
context.load(this._theList, 'EffectiveBasePermissions')
context.executeQueryAsync(Function.createDelegate(this, this.onPermissionsSuccessMethod), Function.createDelegate(this, this.onPermissionsFailureMethod));
}
function onPermissionsSuccessMethod(sender, args) {
if (this._theList.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems))
{
this.HasPermission = true;
}
else
{
this.HasPermission = false;
}
}
function onPermissionsFailureMethod()
{
alert("Couldn't check permissions. Please contact to resolve this issue.");
}
function CheckUserPermissions() {
if(this.isGroupMember == true)
{
alert("You do not have permission to create sites. If you believe you should have access to this functionality, please contact .");
}
else if(this.HasPermission == false)
{
alert("You do not have permission to create sites. If you believe you should have access to this functionality, please contact .");
}
else
{
showDialogue();
document.getElementById("next-stage").focus();
}
}
は、残念ながら、このセクションでは、変数HasPermissionとisGroupMemberはまだ定義されていません。 私はこのキーワードを悪用したと感じていますが、これはスコープのエラーですが、私はJSの中で確かに知っている、または修正できるほど専門家ではありません。誰かが私が間違ってやったことを正確に教えてもらえますか?
便利なヒント:オブジェクト/ javascriptデザインパターン – GottZ
あなたはJavaScriptを操作できることを認識しています。クライアント側で行うチェックはバイパスできますか?したがって、ユーザーが制御権を持っていないときにもサーバー上で実行する必要があります。 – Richard
残念ながら、この環境ではサーバサイドコードはオプションではありません。このセキュリティの弱点は経営陣に指摘され、容認されたものとみなされています。 – JonS