public void Accept(ManagedSecurityContext sec, string message)
        {
            GetACL().Check(sec, DataOperation.AllExceptUpdate);

            ManagedAccountGroup group = new ManagedAccountGroup(Session, mInstance.AccountGroup);

            if (!group.HasAccount(mInstance.Requester.Id))
            {
                Session.Delete(mInstance);

                throw new Exception(string.Format("Sorry, {0} is no longer member of \"{2}\".",
                                                  mInstance.Requester.Name));
            }

            // account may already a member (invited twice by different admins, etc.)
            if (!group.HasAccount(mInstance.Account.Id))
            {
                JoinGroup(sec, message);

                ManagedAccount recepient = new ManagedAccount(Session, mInstance.Requester);
                ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(
                    Session,
                    recepient,
                    string.Format("EmailAccountGroupAccountInvitationAccept.aspx?id={0}&aid={1}&message={2}",
                                  this.Id, sec.Account.Id, Renderer.UrlEncode(message)));
            }

            Session.Delete(mInstance);
        }
        public void JoinGroup(
            ManagedSecurityContext sec,
            string message)
        {
            ManagedAccountGroup group = new ManagedAccountGroup(Session, mInstance.AccountGroup);

            if (group.Instance.IsPrivate && !group.HasAdministratorAccount(mInstance.Requester.Id))
            {
                TransitAccountGroupAccountRequest t_request = new TransitAccountGroupAccountRequest();
                t_request.AccountGroupId = mInstance.AccountGroup.Id;
                t_request.AccountId      = mInstance.Account.Id;
                t_request.Message        = string.Format("{0} invited {1} to \"{2}\". " +
                                                         "The invitation was accepted and needs to be approved by the group administrator.\n{3}",
                                                         mInstance.Requester.Name, mInstance.Account.Name, mInstance.AccountGroup.Name, message);
                t_request.Submitted = DateTime.UtcNow;

                ManagedAccountGroupAccountRequest m_request = new ManagedAccountGroupAccountRequest(Session);
                m_request.CreateOrUpdate(t_request, sec);
            }
            else
            {
                TransitAccountGroupAccount t_account = new TransitAccountGroupAccount();
                t_account.AccountId      = mInstance.Account.Id;
                t_account.AccountGroupId = mInstance.AccountGroup.Id;
                t_account.Created        = t_account.Modified = DateTime.UtcNow;
                ManagedAccountGroupAccount m_accountgroupaccount = new ManagedAccountGroupAccount(Session);
                m_accountgroupaccount.CreateOrUpdate(t_account, sec);
            }
        }
        public override int CreateOrUpdate(TransitAccountGroupAccountRequest t_instance, ManagedSecurityContext sec)
        {
            ManagedAccountGroup m_group = new ManagedAccountGroup(Session, t_instance.AccountGroupId);

            if (m_group.HasAccountRequest(t_instance.AccountId))
            {
                throw new Exception(string.Format(
                                        "You already have a membership request pending to join \"{0}\".", m_group.Instance.Name));
            }

            if (m_group.HasAccount(t_instance.AccountId))
            {
                throw new Exception(string.Format(
                                        "You are already a member of \"{0}\".", m_group.Instance.Name));
            }

            int id = base.CreateOrUpdate(t_instance, sec);

            Session.Flush();

            foreach (AccountGroupAccount accountadmin in Collection <AccountGroupAccount> .GetSafeCollection(mInstance.AccountGroup.AccountGroupAccounts))
            {
                if (accountadmin.IsAdministrator)
                {
                    ManagedAccount recepient = new ManagedAccount(Session, accountadmin.Account.Id);
                    ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(
                        Session, recepient, string.Format("EmailAccountGroupAccountRequest.aspx?id={0}", id));
                }
            }

            return(id);
        }
        public override int CreateOrUpdate(TransitAccountGroupAccountInvitation t_instance, ManagedSecurityContext sec)
        {
            ManagedAccountGroup m_group   = new ManagedAccountGroup(Session, t_instance.AccountGroupId);
            ManagedAccount      m_account = new ManagedAccount(Session, t_instance.AccountId);

            if (m_group.HasAccountInvitation(t_instance.AccountId) || m_group.HasAccountRequest(t_instance.AccountId))
            {
                throw new Exception(string.Format("An invitation for {0} to join \"{1}\" is already pending.",
                                                  m_account.Instance.Name, m_group.Instance.Name));
            }

            if (m_group.HasAccount(t_instance.AccountId))
            {
                throw new Exception(string.Format("{0} is already a member of \"{1}\".",
                                                  m_account.Name, m_group.Instance.Name));
            }

            int id = base.CreateOrUpdate(t_instance, sec);

            Session.Flush();

            ManagedAccount recepient = new ManagedAccount(Session, t_instance.AccountId);

            ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(
                Session, recepient, string.Format("EmailAccountGroupAccountInvitation.aspx?id={0}", id));

            return(id);
        }
Ejemplo n.º 5
0
        public override int CreateOrUpdate(TransitAccountGroupPlace t_instance, ManagedSecurityContext sec)
        {
            ManagedAccountGroup m_group = new ManagedAccountGroup(Session, t_instance.AccountGroupId);

            // check whether the user is already a member
            if (t_instance.Id == 0 && m_group.HasPlace(t_instance.PlaceId))
            {
                throw new Exception(string.Format(
                                        "This place has already been added to \"{0}\".", m_group.Instance.Name));
            }

            return(base.CreateOrUpdate(t_instance, sec));
        }
Ejemplo n.º 6
0
        public override void Delete(ManagedSecurityContext sec)
        {
            ManagedAccountGroup m_group = new ManagedAccountGroup(Session, mInstance.AccountGroup);

            m_group.Leave(mInstance.Account.Id, sec);
            // delete group subscription
            AccountRssWatch watch = GetGroupRssWatch();

            if (watch != null)
            {
                Session.Delete(watch);
            }
            base.Delete(sec);
        }
Ejemplo n.º 7
0
 public override void SetInstance(AccountGroup value)
 {
     Name          = value.Name;
     Description   = value.Description;
     Created       = value.Created;
     Modified      = value.Modified;
     IsPrivate     = value.IsPrivate;
     AccountBlogId = (value.AccountBlog != null) ? value.AccountBlog.Id : 0;
     if (!IsPrivate)
     {
         PictureId = ManagedAccountGroup.GetRandomAccountGroupPictureId(value);
     }
     base.SetInstance(value);
 }
Ejemplo n.º 8
0
 public override void SetInstance(AccountGroupAccount value)
 {
     AccountId        = value.Account.Id;
     AccountName      = value.Account.Name;
     AccountPictureId = ManagedAccount.GetRandomAccountPictureId(value.Account);
     if (!value.AccountGroup.IsPrivate)
     {
         AccountGroupPictureId = ManagedAccountGroup.GetRandomAccountGroupPictureId(value.AccountGroup);
     }
     AccountGroupId   = value.AccountGroup.Id;
     AccountGroupName = value.AccountGroup.Name;
     IsAdministrator  = value.IsAdministrator;
     Created          = value.Created;
     Modified         = value.Modified;
     base.SetInstance(value);
 }
 public override void SetInstance(AccountGroupAccountInvitation value)
 {
     AccountId                = value.Account.Id;
     AccountName              = value.Account.Name;
     AccountPictureId         = ManagedAccount.GetRandomAccountPictureId(value.Account);
     RequesterId              = value.Requester.Id;
     RequesterIsAdministrator = ManagedAccountGroupAccountInvitation.IsRequesterAdministrator(value);
     RequesterName            = value.Requester.Name;
     RequesterPictureId       = ManagedAccount.GetRandomAccountPictureId(value.Requester);
     AccountGroupId           = value.AccountGroup.Id;
     AccountGroupName         = value.AccountGroup.Name;
     if (!value.AccountGroup.IsPrivate)
     {
         AccountGroupPictureId = ManagedAccountGroup.GetRandomAccountGroupPictureId(value.AccountGroup);
     }
     AccountGroupIsPrivate = value.AccountGroup.IsPrivate;
     Message  = value.Message;
     Created  = value.Created;
     Modified = value.Modified;
     base.SetInstance(value);
 }
Ejemplo n.º 10
0
        public override void SetInstance(AccountGroupPlace instance)
        {
            Created               = instance.Created;
            AccountGroupId        = instance.AccountGroup.Id;
            PlaceId               = instance.Place.Id;
            AccountGroupName      = instance.AccountGroup.Name;
            PlaceName             = instance.Place.Name;
            AccountGroupPictureId = ManagedAccountGroup.GetRandomAccountGroupPictureId(instance.AccountGroup);
            PlacePictureId        = ManagedService <PlacePicture, TransitPlacePicture> .GetRandomElementId(instance.Place.PlacePictures);

            if (instance.Place.City != null)
            {
                PlaceCity = instance.Place.City.Name;
            }
            if (instance.Place.City != null && instance.Place.City.State != null)
            {
                PlaceState = instance.Place.City.State.Name;
            }
            if (instance.Place.City != null && instance.Place.City.Country != null)
            {
                PlaceCountry = instance.Place.City.Country.Name;
            }
            base.SetInstance(instance);
        }
Ejemplo n.º 11
0
        public override int CreateOrUpdate(TransitAccountGroupAccount t_instance, ManagedSecurityContext sec)
        {
            ManagedAccountGroup m_group = new ManagedAccountGroup(Session, t_instance.AccountGroupId);

            // check whether the user is already a member
            if (t_instance.Id == 0 && m_group.HasAccount(t_instance.AccountId))
            {
                throw new Exception(string.Format(
                                        "You are already a member of \"{0}\".", m_group.Instance.Name));
            }

            // ensure that user isn't trying to self promote
            if (t_instance.Id > 0 && t_instance.IsAdministrator)
            {
                // the caller isn't a group admin
                if (!m_group.HasAdministratorAccount(sec.Account.Id))
                {
                    throw new ManagedAccount.AccessDeniedException();
                }
            }

            // ensure that not removing last admin
            if (t_instance.Id > 0 && !t_instance.IsAdministrator)
            {
                AccountGroupAccount existing_instance = Session.Load <AccountGroupAccount>(t_instance.Id);
                if (existing_instance.IsAdministrator)
                {
                    bool fHasAnotherAdmin = false;
                    foreach (AccountGroupAccount instance in existing_instance.AccountGroup.AccountGroupAccounts)
                    {
                        if (instance.IsAdministrator && instance != existing_instance)
                        {
                            fHasAnotherAdmin = true;
                            break;
                        }
                    }

                    if (!fHasAnotherAdmin)
                    {
                        throw new Exception("Cannot demote the last group administrator.");
                    }
                }
            }

            int id = base.CreateOrUpdate(t_instance, sec);

            if (t_instance.Id == 0)
            {
                if (mInstance.AccountGroup.AccountGroupAccounts == null)
                {
                    mInstance.AccountGroup.AccountGroupAccounts = new List <AccountGroupAccount>();
                }
                mInstance.AccountGroup.AccountGroupAccounts.Add(mInstance);

                // subscribe the user to a group feed
                TransitAccountRssWatch t_watch = new TransitAccountRssWatch();
                t_watch.UpdateFrequency = 24;
                t_watch.Name            = mInstance.AccountGroup.Name;
                t_watch.Url             = string.Format("AccountGroupRss.aspx?id={0}", mInstance.AccountGroup.Id);
                t_watch.Enabled         = true;
                t_watch.AccountId       = mInstance.Account.Id;
                ManagedAccountRssWatch m_watch = new ManagedAccountRssWatch(Session);
                m_watch.CreateOrUpdate(t_watch, ManagedAccount.GetUserSecurityContext(Session, mInstance.Account.Id));
                Session.Flush();

                // e-mail the user a welcome message
                ManagedAccount recepient = new ManagedAccount(Session, mInstance.Account);
                ManagedSiteConnector.TrySendAccountEmailMessageUriAsAdmin(Session, recepient,
                                                                          string.Format("EmailAccountGroupAccount.aspx?id={0}",
                                                                                        id));
            }

            return(id);
        }