public object Post(CommunityCreateRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); if (string.IsNullOrEmpty(request.Identifier)) { throw new Exception("Invalid request - missing community identifier"); } context.LogInfo(this, string.Format("/community POST Identifier='{0}'", request.Identifier)); ThematicCommunity domain = new ThematicCommunity(context); domain = request.ToEntity(context, domain); domain.Store(); var manager = Role.FromIdentifier(context, RoleTep.MANAGER); User usr = User.FromId(context, context.UserId); manager.GrantToUser(usr, domain); domain.UpdateAppsLinks(request.Apps); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public object Put(CommunityUpdateRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); if (string.IsNullOrEmpty(request.Identifier)) { throw new Exception("Invalid request - missing community identifier"); } context.LogInfo(this, string.Format("/community PUT Identifier='{0}'", request.Identifier)); ThematicCommunity domain = ThematicCommunity.FromIdentifier(context, request.Identifier); if (!domain.CanUserManage(context.UserId)) { throw new UnauthorizedAccessException("Action only allowed to manager of the domain"); } domain = request.ToEntity(context, domain); domain.Store(); domain.UpdateAppsLinks(request.Apps); domain.UpdateDomainsLinks(domain.Links); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
private void Init() { //Create users UserTep usr1 = new UserTep(context); usr1.Username = "******"; usr1.Store(); UserTep usr2 = new UserTep(context); usr2.Username = "******"; usr2.Store(); UserTep usr3 = new UserTep(context); usr3.Username = "******"; usr3.Store(); UserTep usr4 = new UserTep(context); usr4.Username = "******"; usr4.Store(); //create domains Domain domain = new Domain(context); domain.Identifier = "myDomainTest"; domain.Kind = DomainKind.Public; domain.Store(); Domain domain2 = new Domain(context); domain2.Identifier = "otherDomainTest"; domain2.Kind = DomainKind.Hidden; domain2.Store(); Role role = new Role(context); role.Identifier = "member-test"; role.Store(); role.IncludePrivilege(Privilege.FromIdentifier(context, "wpsjob-v")); role.IncludePrivilege(Privilege.FromIdentifier(context, "wpsjob-s")); //Add users in the domain role.GrantToUser(usr1, domain); role.GrantToUser(usr2, domain); role.GrantToUser(usr3, domain); role.GrantToUser(usr3, domain2); //create community ThematicCommunity community1 = new ThematicCommunity(context); community1.Identifier = "community-public-1"; community1.Kind = DomainKind.Public; community1.Store(); community1.SetOwner(usr3); }
private void Init() { //Create users UserTep usr1 = new UserTep(context); usr1.Username = "******"; usr1.Store(); UserTep usr2 = new UserTep(context); usr2.Username = "******"; usr2.Store(); UserTep usr3 = new UserTep(context); usr3.Username = "******"; usr3.Store(); //create communities ThematicCommunity community1 = new ThematicCommunity(context); community1.Identifier = "community-public-1"; community1.Kind = DomainKind.Public; community1.Store(); community1.SetOwner(usr2); ThematicCommunity community2 = new ThematicCommunity(context); community2.Identifier = "community-private-1"; community2.Kind = DomainKind.Hidden; community2.Store(); community2.SetOwner(usr2); ThematicCommunity community3 = new ThematicCommunity(context); community3.Identifier = "community-private-2"; community3.Kind = DomainKind.Hidden; community3.Store(); community3.SetOwner(usr2); ThematicCommunity community4 = new ThematicCommunity(context); community4.Identifier = "community-public-2"; community4.Kind = DomainKind.Public; community4.Store(); community4.SetOwner(usr2); }