/*--------------------------------------------------------------------------------------------*/ private void AddMember(SetupMemberId pId, SetupAppId pSetupAppId, SetupUserId pSetupUserId, MemberType.Id pMemTypeId) { var m = new Member(); m.MemberType = (byte)pMemTypeId; AddVertex(m, (SetupVertexId)(long)pId); App app = Data.GetVertex <App>((long)pSetupAppId); User user = Data.GetVertex <User>((long)pSetupUserId); var adm = new AppDefinesMember(); adm.Timestamp = m.Timestamp; adm.MemberType = m.MemberType; adm.UserId = (long)pSetupUserId; AddEdge(app, adm, m); AddEdge(m, new MemberDefinedByApp(), app); var udm = new UserDefinesMember(); udm.Timestamp = m.Timestamp; udm.MemberType = m.MemberType; udm.AppId = (long)pSetupAppId; AddEdge(user, udm, m); AddEdge(m, new MemberDefinedByUser(), user); }
/*--------------------------------------------------------------------------------------------*/ public virtual void AddMemberDefinedByUser(ICreateOperationBuilder pCreCtx, Member pNewDom, CreateFabMember pNewCre, IWeaverVarAlias <Member> pAlias) { var a = AddEdge <Member, MemberDefinedByUser, User>( pCreCtx, pAlias, pNewCre.DefinedByUserId); var udmEdge = new UserDefinesMember(); udmEdge.Timestamp = pNewDom.Timestamp; udmEdge.MemberType = pNewDom.MemberType; udmEdge.AppId = pNewCre.DefinedByAppId; AddReverseEdge(pCreCtx, a, udmEdge, pAlias); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public void Perform(IOperationContext pOpCtx, string pPass, string pMemId, string pDelete) { vOpCtx = pOpCtx; #if LIVE && !DEBUG vResult = new { Error = "Not allowed in Release mode." }; return; #endif if (pPass != "internalFab030") { vResult = new { Error = "Password required." }; return; } long memId = long.Parse(pMemId); bool delete = (pDelete == "1"); Member mem = pOpCtx.Data.GetVertexById <Member>(memId); if (mem == null) { vResult = new { Error = "Member " + memId + " not found." }; return; } const string qName = "Internal-RemoveMember-"; IWeaverQuery getUser = Weave.Inst.Graph .V.ExactIndex <Member>(x => x.VertexId, memId) .DefinedByUser.ToUser .ToQuery(); IWeaverQuery getApp = Weave.Inst.Graph .V.ExactIndex <Member>(x => x.VertexId, memId) .DefinedByApp.ToApp .ToQuery(); User user = pOpCtx.Data.Get <User>(getUser, qName + "GetUser"); App app = pOpCtx.Data.Get <App>(getApp, qName + "GetApp"); if (user == null || app == null) { vResult = new { Member = new { VertexId = mem.VertexId + "", }, NullUser = (user == null), NullApp = (app == null), }; return; } ; IWeaverQuery getUserEdge = Weave.Inst.Graph .V.ExactIndex <User>(x => x.VertexId, user.VertexId) .DefinesMembers .Has(x => x.AppId, WeaverStepHasOp.EqualTo, app.VertexId) .ToQuery(); IWeaverQuery getAppEdge = Weave.Inst.Graph .V.ExactIndex <App>(x => x.VertexId, app.VertexId) .DefinesMembers .Has(x => x.UserId, WeaverStepHasOp.EqualTo, user.VertexId) .ToQuery(); IDataResult userEdge = pOpCtx.Data.Execute(getUserEdge, qName + "GetUserEdge"); IDataResult appEdge = pOpCtx.Data.Execute(getAppEdge, qName + "GetAppEdge"); IList <UserDefinesMember> userDefs = userEdge.ToElementList <UserDefinesMember>(); IList <AppDefinesMember> appDefs = appEdge.ToElementList <AppDefinesMember>(); if (userDefs.Count != 1 && appDefs.Count != 1) { delete = false; } UserDefinesMember remUserDef = null; AppDefinesMember remAppDef = null; Member remMem = null; if (delete) { IWeaverQuery removeUserDefQ = Weave.Inst.Graph .E.Id <UserDefinesMember>(userDefs[0].Id) .Remove() .ToQuery(); IWeaverQuery removeAppDefQ = Weave.Inst.Graph .E.Id <AppDefinesMember>(appDefs[0].Id) .Remove() .ToQuery(); IWeaverQuery removeMemQ = Weave.Inst.Graph .V.ExactIndex <Member>(x => x.VertexId, memId) .Remove() .ToQuery(); remUserDef = pOpCtx.Data.Get <UserDefinesMember>(removeUserDefQ, qName + "RemUserDef"); remAppDef = pOpCtx.Data.Get <AppDefinesMember>(removeAppDefQ, qName + "RemAppDef"); remMem = pOpCtx.Data.Get <Member>(removeMemQ, qName + "RemMem"); } vResult = new { Member = new { VertexId = mem.VertexId + "", Type = mem.MemberType, OauthGrantCode = mem.OauthGrantCode, OauthGrantExpires = mem.OauthGrantExpires, OauthGrantRedirectUri = mem.OauthGrantRedirectUri, OauthScopeAllow = mem.OauthScopeAllow }, User = new { VertexId = user.VertexId + "", Name = user.Name }, App = new { VertexId = app.VertexId + "", Name = app.Name }, UserEdges = userEdge.ToMap(), AppEdges = appEdge.ToMap(), RemUserDef = (remUserDef == null ? null : new { Id = remUserDef.Id }), RemAppDef = (remAppDef == null ? null : new { Id = remAppDef.Id }), RemMem = (remMem == null ? null : new { Id = remMem.VertexId + "" }), Delete = delete }; }