Example #1
0
        public static bool PublishPost(Core core, Job job)
        {
            core.LoadUserProfile(job.UserId);
            User owner = core.PrimitiveCache[job.UserId];
            ItemKey sharedItemKey = new ItemKey(job.ItemId, job.ItemTypeId);
            IActionableItem sharedItem = null;

            core.ItemCache.RequestItem(sharedItemKey);
            try
            {
                sharedItem = (IActionableItem)core.ItemCache[sharedItemKey];
            }
            catch
            {
                try
                {
                    sharedItem = (IActionableItem)NumberedItem.Reflect(core, sharedItemKey);
                    HttpContext.Current.Response.Write("<br />Fallback, had to reflect: " + sharedItemKey.ToString());
                }
                catch
                {
                    return true; // Item is probably deleted, report success to delete from queue
                }
            }

            UpdateQuery uQuery = new UpdateQuery(typeof(ItemInfo));
            uQuery.AddCondition("info_item_id", sharedItemKey.Id);
            uQuery.AddCondition("info_item_type_id", sharedItemKey.TypeId);

            try
            {
                if (owner.UserInfo.FacebookAuthenticated) // are we still authenticated
                {
                    string postDescription = job.Body;

                    Facebook fb = new Facebook(core.Settings.FacebookApiAppid, core.Settings.FacebookApiSecret);

                    FacebookAccessToken token = fb.OAuthAppAccessToken(core, owner.UserInfo.FacebookUserId);
                    FacebookPost post = fb.StatusesUpdate(token, postDescription, sharedItem.Info.ShareUri, owner.UserInfo.FacebookSharePermissions);

                    if (post != null)
                    {
                        uQuery.AddField("info_facebook_post_id", post.PostId);
                    }

                    core.Db.Query(uQuery);
                }
            }
            catch (System.Net.WebException ex)
            {
                HttpWebResponse response = (HttpWebResponse)ex.Response;
                if (response.StatusCode == HttpStatusCode.Forbidden)
                {
                    return true; // This request cannot succeed, so remove it from the queue
                }
                return false; // Failed for other reasons, retry
            }

            return true; // success
        }
Example #2
0
        public static void Show(Core core)
        {
            string path = core.Http.Query["path"];
            long ownerId = core.Functions.RequestLong("owner_id", 0);
            long ownerTypeId = core.Functions.RequestLong("owner_type_id", 0);
            ItemKey ownerKey = new ItemKey(ownerId, ownerTypeId);

            try
            {
                core.PrimitiveCache.LoadPrimitiveProfile(ownerKey);
                Primitive owner = core.PrimitiveCache[ownerKey];

                Page thePage = new Page(core, owner, path);

                JsonSerializer js;
                StringWriter jstw;
                JsonTextWriter jtw;

                js = new JsonSerializer();
                jstw = new StringWriter();
                jtw = new JsonTextWriter(jstw);

                js.NullValueHandling = NullValueHandling.Ignore;

                core.Http.WriteJson(js, thePage);
            }
            catch (PageNotFoundException)
            {

            }
            catch
            {
            }
        }
Example #3
0
 public AjaxPermissionGroupDictionaryItem(ItemKey ik, string value, string tile)
 {
     this.Id = ik.Id;
     this.TypeId = ik.TypeId;
     this.Value = value;
     this.Tile = tile;
 }
Example #4
0
        public static bool PublishPost(Core core, Job job)
        {
            core.LoadUserProfile(job.UserId);
            User owner = core.PrimitiveCache[job.UserId];
            ItemKey sharedItemKey = new ItemKey(job.ItemId, job.ItemTypeId);
            IActionableItem sharedItem = null;

            core.ItemCache.RequestItem(sharedItemKey);
            try
            {
                sharedItem = (IActionableItem)core.ItemCache[sharedItemKey];
            }
            catch
            {
                try
                {
                    sharedItem = (IActionableItem)NumberedItem.Reflect(core, sharedItemKey);
                    HttpContext.Current.Response.Write("<br />Fallback, had to reflect: " + sharedItemKey.ToString());
                }
                catch
                {
                    job.Cancel = true;
                    return true; // Item is probably deleted, report success to delete from queue
                }
            }

            UpdateQuery uQuery = new UpdateQuery(typeof(ItemInfo));
            uQuery.AddCondition("info_item_id", sharedItemKey.Id);
            uQuery.AddCondition("info_item_type_id", sharedItemKey.TypeId);

            try
            {
                if (owner.UserInfo.TumblrAuthenticated) // are we still authenticated
                {
                    string postDescription = job.Body;

                    Tumblr t = new Tumblr(core.Settings.TumblrApiKey, core.Settings.TumblrApiSecret);
                    TumblrPost post = t.StatusesUpdate(new TumblrAccessToken(owner.UserInfo.TumblrToken, owner.UserInfo.TumblrTokenSecret), owner.UserInfo.TumblrHostname, sharedItem.PostType, string.Empty, postDescription, sharedItem.Info.ShareUri, sharedItem.Data, sharedItem.DataContentType);

                    if (post != null)
                    {
                        uQuery.AddField("info_tumblr_post_id", post.Id);
                    }

                    core.Db.Query(uQuery);
                }
            }
            catch (System.Net.WebException ex)
            {
                HttpWebResponse response = (HttpWebResponse)ex.Response;
                if (response.StatusCode == HttpStatusCode.Forbidden)
                {
                    return true; // This request cannot succeed, so remove it from the queue
                }
                job.Error = ex.ToString();
                return false; // Failed for other reasons, retry
            }

            return true; // success
        }
Example #5
0
 public Primitive this[ItemKey key]
 {
     get
     {
         return (Primitive)core.ItemCache[key];
     }
 }
 public UnsavedAccessControlGrant(Core core, ItemKey primitiveKey, ItemKey itemKey, long permissionId, AccessControlGrants grantAllow)
 {
     this.core = core;
     this.itemKey = itemKey;
     this.primitiveKey = primitiveKey;
     this.permissionId = permissionId;
     this.grantAllow = (sbyte)grantAllow;
 }
Example #7
0
        internal Access(Core core, ItemKey key, Primitive leafOwner)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            this.core = core;
            this.item = null;
            this.owner = leafOwner;
            this.itemKey = key;
            this.viewer = core.Session.LoggedInMember;
        }
        public PermissionGroupSelectBox(Core core, string name, ItemKey permissibleItem, List<PrimitivePermissionGroup> itemKeys)
        {
            this.core = core;
            this.name = name;
            this.permissibleItem = permissibleItem;
            this.itemKeys = itemKeys;

            disabled = false;
            visible = true;

            width = new StyleLength(100F, LengthUnits.Percentage);
            script = new ScriptProperty();
        }
Example #9
0
        public Access(Core core, IPermissibleItem item)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            this.core = core;
            this.item = item;
            this.owner = item.Owner;
            this.itemKey = item.ItemKey;
            this.viewer = core.Session.LoggedInMember;
        }
Example #10
0
        public bool IsNetworkMember(ItemKey key)
        {
            if (key != null)
            {
                if (networkMemberCache.ContainsKey(key))
                {
                    return networkMemberCache[key];
                }
                else
                {
                    DataTable memberTable = db.Query(string.Format("SELECT user_id FROM network_members WHERE network_id = {0} AND user_id = {1} AND member_active = 1",
                        networkId, key.Id));

                    if (memberTable.Rows.Count > 0)
                    {
                        networkMemberCache.Add(key, true);
                        return true;
                    }
                    else
                    {
                        networkMemberCache.Add(key, false);
                        return false;
                    }
                }
            }

            return false;
        }
Example #11
0
 public void LoadPrimitiveProfile(ItemKey key)
 {
     core.ItemCache.RequestItem(key);
 }
Example #12
0
        public override void ExecuteCall(string callName)
        {
            switch (callName)
            {
                case "list_galleries":
                    {
                        long ownerId = core.Functions.RequestLong("owner_id", core.Session.LoggedInMember.Id);
                        long ownerTypeId = core.Functions.RequestLong("owner_type_id", core.Session.LoggedInMember.ItemKey.TypeId);
                        long galleryId = core.Functions.RequestLong("gallery_id", 0);
                        ItemKey ownerKey = new ItemKey(ownerId, ownerTypeId);

                        Gallery gallery = null;
                        if (galleryId > 0)
                        {
                            gallery = new Gallery(core, galleryId);
                        }
                        else
                        {
                            core.PrimitiveCache.LoadPrimitiveProfile(ownerKey);
                            Primitive owner = core.PrimitiveCache[ownerKey];

                            gallery = new Gallery(core, owner);
                        }

                        if (gallery != null)
                        {
                            if (gallery.Access.Can("VIEW"))
                            {
                                List<Gallery> galleries = gallery.GetGalleries();
                                List<Gallery> responseGalleries = new List<Gallery>();

                                foreach (Gallery g in galleries)
                                {
                                    if (gallery.Access.Can("VIEW"))
                                    {
                                        responseGalleries.Add(g);
                                    }
                                }

                                core.Response.WriteObject(responseGalleries);
                            }
                            else
                            {

                            }
                        }
                    }
                    break;
                case "list_gallery_items":
                    {
                        long galleryId = core.Functions.RequestLong("gallery_id", 0);
                        long offsetId = core.Functions.RequestLong("offset_id", 0);

                        Gallery gallery = null;
                        if (galleryId > 0)
                        {
                            gallery = new Gallery(core, galleryId);
                        }

                        if (gallery != null)
                        {
                            if (gallery.Access.Can("VIEW_ITEMS"))
                            {
                                List<GalleryItem> galleryItems = gallery.GetItems(core, 1, 12, offsetId);

                                core.Response.WriteObject(galleryItems);
                            }
                        }
                    }
                    break;
                case "gallery_item":
                    GalleryItem.Show(core);
                    break;
                case "upload":
                    Gallery.Upload(core);
                    break;
            }
        }
Example #13
0
 public ItemSubscribedEventArgs(User rater, ItemKey itemKey)
 {
     this.rater = rater;
     this.itemKey = itemKey;
 }
Example #14
0
        public void ParseACL(Template template, Primitive owner, string variable)
        {
            Template aclTemplate = new Template("std.acl.html");
            aclTemplate.Medium = core.Template.Medium;
            aclTemplate.SetProse(core.Prose);

            if (itemPermissions == null)
            {
                itemPermissions = GetPermissions(core, item);
            }
            if (itemGrants == null)
            {
                itemGrants = AccessControlGrant.GetGrants(core, item);
            }
            if (unsavedGrants == null)
            {
                unsavedGrants = new List<UnsavedAccessControlGrant>();
            }

            if (itemGrants != null)
            {
                foreach (AccessControlGrant itemGrant in itemGrants)
                {
                    core.PrimitiveCache.LoadPrimitiveProfile(itemGrant.PrimitiveKey);
                }
            }

            bool simple = item.IsSimplePermissions;

            string mode = core.Http["aclmode"];
            switch (mode)
            {
                case "simple":
                    simple = true;
                    break;
                case "detailed":
                    simple = false;
                    break;
            }

            bool first = true;
            PermissionTypes lastType = PermissionTypes.View;
            VariableCollection permissionTypeVariableCollection = null;

            PermissionGroupSelectBox typeGroupSelectBox = null;
            List<PrimitivePermissionGroup> ownerGroups = null;

            if (itemPermissions != null)
            {
                foreach (AccessControlPermission itemPermission in itemPermissions)
                {
                    if (first || itemPermission.PermissionType != lastType)
                    {
                        if (typeGroupSelectBox != null)
                        {
                            permissionTypeVariableCollection.Parse("S_SIMPLE_SELECT", typeGroupSelectBox);
                        }

                        permissionTypeVariableCollection = aclTemplate.CreateChild("permision_types");
                        typeGroupSelectBox = new PermissionGroupSelectBox(core, "group-select-" + itemPermission.PermissionType.ToString(), item.ItemKey);

                        permissionTypeVariableCollection.Parse("TITLE", AccessControlLists.PermissionTypeToString(itemPermission.PermissionType));

                        first = false;
                        lastType = itemPermission.PermissionType;
                    }

                    if (simple)
                    {
                        if (ownerGroups == null)
                        {
                            ownerGroups = new List<PrimitivePermissionGroup>();
                            int itemGroups = 0;

                            Type type = item.GetType();
                            if (type.GetMethod(type.Name + "_GetItemGroups", new Type[] { typeof(Core) }) != null)
                            {
                                ownerGroups.AddRange((List<PrimitivePermissionGroup>)type.InvokeMember(type.Name + "_GetItemGroups", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, new object[] { core }));
                                itemGroups = ownerGroups.Count;
                            }

                            ownerGroups.AddRange(core.GetPrimitivePermissionGroups(owner));
                        }

                        VariableCollection permissionVariableCollection = permissionTypeVariableCollection.CreateChild("permission_desc");
                        permissionVariableCollection.Parse("ID", itemPermission.Id.ToString());
                        permissionVariableCollection.Parse("TITLE", itemPermission.Name);
                        permissionVariableCollection.Parse("DESCRIPTION", itemPermission.Description);

                        if (itemGrants != null)
                        {
                            foreach (AccessControlGrant itemGrant in itemGrants)
                            {
                                if (itemGrant.PermissionId == itemPermission.Id)
                                {
                                    switch (itemGrant.Allow)
                                    {
                                        case AccessControlGrants.Allow:
                                            PrimitivePermissionGroup ppg = null;

                                            ppg = new PrimitivePermissionGroup(itemGrant.PrimitiveKey, string.Empty, string.Empty);
                                            foreach (PrimitivePermissionGroup p in ownerGroups)
                                            {
                                                if (ppg.ItemKey.Equals(p.ItemKey))
                                                {
                                                    ppg = p;
                                                    break;
                                                }
                                            }

                                            if (!typeGroupSelectBox.ItemKeys.Contains(ppg))
                                            {
                                                typeGroupSelectBox.ItemKeys.Add(ppg);
                                            }
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        VariableCollection permissionVariableCollection = permissionTypeVariableCollection.CreateChild("permission");
                        permissionVariableCollection.Parse("ID", itemPermission.Id.ToString());
                        permissionVariableCollection.Parse("TITLE", itemPermission.Name);
                        permissionVariableCollection.Parse("DESCRIPTION", itemPermission.Description);

                        SelectBox groupsSelectBox = BuildGroupsSelectBox(string.Format("new-permission-group[{0}]", itemPermission.Id), owner);

                        if (itemGrants != null)
                        {
                            foreach (AccessControlGrant itemGrant in itemGrants)
                            {
                                if (itemGrant.PermissionId == itemPermission.Id)
                                {
                                    string gsbk = string.Format("{0},{1}", itemGrant.PrimitiveKey.TypeId, itemGrant.PrimitiveKey.Id);
                                    if (groupsSelectBox.ContainsKey(gsbk))
                                    {
                                        groupsSelectBox[gsbk].Selectable = false;
                                    }

                                    VariableCollection grantVariableCollection = permissionVariableCollection.CreateChild("grant");

                                    if (groupsSelectBox.ContainsKey(gsbk))
                                    {
                                        string text = groupsSelectBox[gsbk].Text;
                                        if (text.StartsWith(" -- ", StringComparison.Ordinal))
                                        {
                                            text = text.Substring(4);
                                        }
                                        grantVariableCollection.Parse("DISPLAY_NAME", text);
                                        groupsSelectBox[gsbk].Selectable = false;
                                    }
                                    else
                                    {
                                        try
                                        {
                                            grantVariableCollection.Parse("DISPLAY_NAME", core.PrimitiveCache[itemGrant.PrimitiveKey].DisplayName);
                                        }
                                        catch
                                        {
                                            grantVariableCollection.Parse("DISPLAY_NAME", "{{ERROR LOADING PRIMITIVE(" + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + ":" + (new ItemType(core, itemGrant.PrimitiveKey.TypeId)).Namespace + ")}}");
                                        }
                                    }

                                    RadioList allowrl = new RadioList("allow[" + itemGrant.PermissionId.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + "]");
                                    SelectBox allowsb = new SelectBox("allow[" + itemGrant.PermissionId.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + "]");
                                    Button deleteButton = new Button("delete", "Delete", itemGrant.PermissionId.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString());

                                    allowrl.Add(new RadioListItem(allowrl.Name, "allow", "Allow"));
                                    allowrl.Add(new RadioListItem(allowrl.Name, "deny", "Deny"));
                                    allowrl.Add(new RadioListItem(allowrl.Name, "inherit", "Inherit"));

                                    allowsb.Add(new SelectBoxItem("allow", "Allow"));
                                    allowsb.Add(new SelectBoxItem("deny", "Deny"));
                                    allowsb.Add(new SelectBoxItem("inherit", "Inherit"));

                                    switch (itemGrant.Allow)
                                    {
                                        case AccessControlGrants.Allow:
                                            allowrl.SelectedKey = "allow";
                                            allowsb.SelectedKey = "allow";
                                            break;
                                        case AccessControlGrants.Deny:
                                            allowrl.SelectedKey = "deny";
                                            allowsb.SelectedKey = "deny";
                                            break;
                                        case AccessControlGrants.Inherit:
                                            allowrl.SelectedKey = "inherit";
                                            allowsb.SelectedKey = "inherit";
                                            break;
                                    }

                                    if (core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + "]"] != null)
                                    {
                                        allowrl.SelectedKey = core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + "]"];
                                    }

                                    grantVariableCollection.Parse("S_GRANT", allowsb);

                                    grantVariableCollection.Parse("S_ALLOW", allowrl["allow"]);
                                    grantVariableCollection.Parse("S_DENY", allowrl["deny"]);
                                    grantVariableCollection.Parse("S_INHERIT", allowrl["inherit"]);

                                    grantVariableCollection.Parse("S_DELETE", deleteButton);

                                    grantVariableCollection.Parse("ID", string.Format("{0},{1}", itemGrant.PrimitiveKey.TypeId, itemGrant.PrimitiveKey.Id));
                                    grantVariableCollection.Parse("PERMISSION_ID", itemPermission.Id.ToString());
                                    grantVariableCollection.Parse("IS_NEW", "FALSE");
                                }
                            }

                            foreach (AccessControlGrant itemGrant in itemGrants)
                            {
                                VariableCollection grantsVariableCollection = template.CreateChild("grants");
                            }
                        }

                        if (core.Http.Form["save"] == null)
                        {
                            foreach (SelectBoxItem gsbi in groupsSelectBox)
                            {
                                if (core.Http.Form[string.Format("new-grant[{0},{1}]", itemPermission.Id, gsbi.Key)] != null)
                                {
                                    ItemKey ik = new ItemKey(gsbi.Key);

                                    UnsavedAccessControlGrant uacg = new UnsavedAccessControlGrant(core, ik, item.ItemKey, itemPermission.Id, AccessControlGrants.Inherit);

                                    VariableCollection grantVariableCollection = permissionVariableCollection.CreateChild("grant");

                                    grantVariableCollection.Parse("DISPLAY_NAME", gsbi.Text);

                                    RadioList allowrl = new RadioList("allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]");
                                    SelectBox allowsb = new SelectBox("allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]");

                                    allowrl.Add(new RadioListItem(allowrl.Name, "allow", "Allow"));
                                    allowrl.Add(new RadioListItem(allowrl.Name, "deny", "Deny"));
                                    allowrl.Add(new RadioListItem(allowrl.Name, "inherit", "Inherit"));

                                    allowsb.Add(new SelectBoxItem("allow", "Allow"));
                                    allowsb.Add(new SelectBoxItem("deny", "Deny"));
                                    allowsb.Add(new SelectBoxItem("inherit", "Inherit"));

                                    if (core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]"] != null)
                                    {
                                        allowrl.SelectedKey = core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]"];
                                    }
                                    else
                                    {
                                        switch (uacg.Allow)
                                        {
                                            case AccessControlGrants.Allow:
                                                allowrl.SelectedKey = "allow";
                                                allowsb.SelectedKey = "allow";
                                                break;
                                            case AccessControlGrants.Deny:
                                                allowrl.SelectedKey = "deny";
                                                allowsb.SelectedKey = "deny";
                                                break;
                                            case AccessControlGrants.Inherit:
                                                allowrl.SelectedKey = "inherit";
                                                allowsb.SelectedKey = "inherit";
                                                break;
                                        }
                                    }

                                    grantVariableCollection.Parse("S_GRANT", allowsb);

                                    grantVariableCollection.Parse("S_ALLOW", allowrl["allow"]);
                                    grantVariableCollection.Parse("S_DENY", allowrl["deny"]);
                                    grantVariableCollection.Parse("S_INHERIT", allowrl["inherit"]);

                                    grantVariableCollection.Parse("ID", string.Format("{0},{1}", ik.TypeId, ik.Id));
                                    grantVariableCollection.Parse("PERMISSION_ID", itemPermission.Id.ToString());
                                    grantVariableCollection.Parse("IS_NEW", "TRUE");

                                    gsbi.Selectable = false;
                                }
                            }
                        }

                        if (core.Http.Form[string.Format("add-permission[{0}]", itemPermission.Id)] != null)
                        {
                            string groupSelectBoxId = core.Http.Form[string.Format("new-permission-group[{0}]", itemPermission.Id)];

                            ItemKey ik = new ItemKey(groupSelectBoxId);

                            UnsavedAccessControlGrant uacg = new UnsavedAccessControlGrant(core, ik, item.ItemKey, itemPermission.Id, AccessControlGrants.Inherit);

                            VariableCollection grantVariableCollection = permissionVariableCollection.CreateChild("grant");

                            grantVariableCollection.Parse("DISPLAY_NAME", groupsSelectBox[groupSelectBoxId].Text);

                            RadioList allowrl = new RadioList("allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]");
                            SelectBox allowsb = new SelectBox("allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]");

                            allowrl.Add(new RadioListItem(allowrl.Name, "allow", "Allow"));
                            allowrl.Add(new RadioListItem(allowrl.Name, "deny", "Deny"));
                            allowrl.Add(new RadioListItem(allowrl.Name, "inherit", "Inherit"));

                            allowsb.Add(new SelectBoxItem("allow", "Allow"));
                            allowsb.Add(new SelectBoxItem("deny", "Deny"));
                            allowsb.Add(new SelectBoxItem("inherit", "Inherit"));

                            switch (uacg.Allow)
                            {
                                case AccessControlGrants.Allow:
                                    allowrl.SelectedKey = "allow";
                                    allowsb.SelectedKey = "allow";
                                    break;
                                case AccessControlGrants.Deny:
                                    allowrl.SelectedKey = "deny";
                                    allowsb.SelectedKey = "deny";
                                    break;
                                case AccessControlGrants.Inherit:
                                    allowrl.SelectedKey = "inherit";
                                    allowsb.SelectedKey = "inherit";
                                    break;
                            }

                            grantVariableCollection.Parse("S_GRANT", allowsb);

                            grantVariableCollection.Parse("S_ALLOW", allowrl["allow"]);
                            grantVariableCollection.Parse("S_DENY", allowrl["deny"]);
                            grantVariableCollection.Parse("S_INHERIT", allowrl["inherit"]);

                            grantVariableCollection.Parse("ID", string.Format("{0},{1}", ik.TypeId, ik.Id));
                            grantVariableCollection.Parse("PERMISSION_ID", itemPermission.Id.ToString());
                            grantVariableCollection.Parse("IS_NEW", "TRUE");

                            groupsSelectBox[groupSelectBoxId].Selectable = false;
                        }

                        permissionVariableCollection.Parse("S_PERMISSION_GROUPS", groupsSelectBox);

                        RadioList allowNewrl = new RadioList("new-permission-group-allow");
                        SelectBox allowNewsb = new SelectBox("new-permission-group-allow");

                        allowNewrl.Add(new RadioListItem(allowNewrl.Name, "allow", "Allow"));
                        allowNewrl.Add(new RadioListItem(allowNewrl.Name, "deny", "Deny"));
                        allowNewrl.Add(new RadioListItem(allowNewrl.Name, "inherit", "Inherit"));

                        allowNewsb.Add(new SelectBoxItem("allow", "Allow"));
                        allowNewsb.Add(new SelectBoxItem("deny", "Deny"));
                        allowNewsb.Add(new SelectBoxItem("inherit", "Inherit"));

                        allowNewrl.SelectedKey = "inherit";
                        allowNewsb.SelectedKey = "inherit";

                        permissionVariableCollection.Parse("S_GRANT", allowNewsb);

                        permissionVariableCollection.Parse("S_ALLOW", allowNewrl["allow"].ToString());
                        permissionVariableCollection.Parse("S_DENY", allowNewrl["deny"].ToString());
                        permissionVariableCollection.Parse("S_INHERIT", allowNewrl["inherit"].ToString());
                    }
                }

                if (typeGroupSelectBox != null)
                {
                    permissionTypeVariableCollection.Parse("S_SIMPLE_SELECT", typeGroupSelectBox);
                }
            }

            if (string.IsNullOrEmpty(variable))
            {
                variable = "S_PERMISSIONS";
            }

            /*PermissionGroupSelectBox groupSelectBox = new PermissionGroupSelectBox(core, "group-select", item.ItemKey);
            groupSelectBox.SelectMultiple = true;

            aclTemplate.Parse("S_SIMPLE_SELECT", groupSelectBox);*/

            if (simple)
            {
                aclTemplate.Parse("IS_SIMPLE", "TRUE");
            }

            aclTemplate.Parse("U_DETAILED", Access.BuildAclUri(core, item, false));
            aclTemplate.Parse("U_SIMPLE", Access.BuildAclUri(core, item, true));

            HiddenField modeField = new HiddenField("aclmode");
            if (simple)
            {
                modeField.Value = "simple";
            }
            else
            {
                modeField.Value = "detailed";
            }

            aclTemplate.Parse("S_ACLMODE", modeField);

            template.ParseRaw(variable, aclTemplate.ToString());
        }
Example #15
0
        public override SearchResult DoSearch(string input, int pageNumber, Primitive filterByOwner, Type filterByType)
        {
            Initialise();

            int perPage = 10;
            int start = (pageNumber - 1) * perPage;

            List<ISearchableItem> results = new List<ISearchableItem>();
            List<ItemKey> itemKeys = new List<ItemKey>();
            List<long> applicationIds = new List<long>();

            IndexSearcher searcher = new IndexSearcher(directory);

            QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "item_string", analyzer);

            BooleanQuery query = new BooleanQuery();
            Query bodyQuery = parser.Parse(input);

            query.Add(bodyQuery, Occur.MUST);

            BooleanQuery accessQuery = new BooleanQuery();
            TermQuery accessPublicQuery = new TermQuery(new Term("item_public", "1"));
            accessQuery.Add(accessPublicQuery, Occur.SHOULD);

            if (core.Session.IsLoggedIn)
            {
                List<long> friends = core.Session.LoggedInMember.GetFriendsWithMeIds();

                BooleanQuery accessFriendQuery = new BooleanQuery();
                TermQuery friendQuery = new TermQuery(new Term("item_public", "2"));
                accessFriendQuery.Add(friendQuery, Occur.MUST);

                string userTypeId =  ItemType.GetTypeId(core, typeof(User)).ToString();
                foreach (long friendId in friends)
                {
                    BooleanQuery ownerQuery = new BooleanQuery();
                    TermQuery ownerIdQuery = new TermQuery(new Term("owner_id", friendId.ToString()));
                    TermQuery ownerTypeQuery = new TermQuery(new Term("owner_type_id", userTypeId));

                    ownerQuery.Add(ownerIdQuery, Occur.MUST);
                    ownerQuery.Add(ownerTypeQuery, Occur.MUST);

                    accessFriendQuery.Add(ownerQuery, Occur.SHOULD);
                }

                accessQuery.Add(accessFriendQuery, Occur.SHOULD);
            }

            query.Add(accessQuery, Occur.MUST);

            if (filterByType != null)
            {
                TermQuery typeQuery = new TermQuery(new Term("item_type_id", ItemType.GetTypeId(core, filterByType).ToString()));

                query.Add(typeQuery, Occur.MUST);
            }

            if (filterByOwner != null)
            {
                TermQuery ownerIdQuery = new TermQuery(new Term("owner_id", filterByOwner.Id.ToString()));
                TermQuery ownerTypeIdQuery = new TermQuery(new Term("owner_type_id", filterByOwner.TypeId.ToString()));

                query.Add(ownerIdQuery, Occur.MUST);
                query.Add(ownerTypeIdQuery, Occur.MUST);
            }

            TopScoreDocCollector collector = TopScoreDocCollector.Create(start + perPage, true);

            searcher.Search(query, collector);

            ScoreDoc[] hits = collector.TopDocs().ScoreDocs;

            int totalResults = collector.TotalHits;
            int returnResults = hits.Length;

            int end = Math.Min(hits.Length, start + perPage);

            for (int i = start; i < end; i++)
            {
                Document doc = searcher.Doc(hits[i].Doc);

                long itemId = 0;
                long itemTypeId = 0;
                long applicationId = 0;

                long.TryParse(doc.GetField("item_id").StringValue, out itemId);
                long.TryParse(doc.GetField("item_type_id").StringValue, out itemTypeId);
                long.TryParse(doc.GetField("application_id").StringValue, out applicationId);

                ItemKey key = new ItemKey(itemId, itemTypeId);

                if (!applicationIds.Contains(applicationId))
                {
                    applicationIds.Add(applicationId);
                }

                itemKeys.Add(key);
            }

            // Force each application with results to load
            for (int i = 0; i < applicationIds.Count; i++)
            {
                if (applicationIds[i] > 0)
                {
                    ApplicationEntry ae = new ApplicationEntry(core, applicationIds[i]);

                    BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae);
                }
            }

            List<IPermissibleItem> tempResults = new List<IPermissibleItem>();

            foreach (ItemKey key in itemKeys)
            {
                core.ItemCache.RequestItem(key);
            }

            foreach (ItemKey key in itemKeys)
            {
                try
                {
                    NumberedItem thisItem = core.ItemCache[key];

                    if (thisItem != null)
                    {
                        if (thisItem is IPermissibleItem)
                        {
                            tempResults.Add((IPermissibleItem)thisItem);
                        }
                        if (thisItem is IPermissibleSubItem)
                        {
                            tempResults.Add(((IPermissibleSubItem)thisItem).PermissiveParent);
                        }
                        results.Add((ISearchableItem)thisItem);
                    }
                }
                catch (InvalidItemException)
                {
                }
            }

            if (tempResults.Count > 0)
            {
                core.AcessControlCache.CacheGrants(tempResults);
            }

            return new SearchResult(results, totalResults);
        }
Example #16
0
 public bool GetDefaultCan(string permission, ItemKey viewer)
 {
     return false;
 }
Example #17
0
        public static List<User> GetUserSubscribers(Core core, ItemKey itemKey, int page, int perPage)
        {
            List<User> subscribers = new List<User>();

            SelectQuery query = Subscription.GetSelectQueryStub(core, typeof(Subscription));
            query.AddCondition("subscription_item_id", itemKey.Id);
            query.AddCondition("subscription_item_type_id", itemKey.TypeId);
            query.AddFields(User.GetFieldsPrefixed(core, typeof(User)));
            query.AddFields(UserInfo.GetFieldsPrefixed(core, typeof(UserInfo)));
            query.AddFields(UserProfile.GetFieldsPrefixed(core, typeof(UserProfile)));
            query.AddField(new DataField("gallery_items", "gallery_item_uri"));
            query.AddField(new DataField("gallery_items", "gallery_item_parent_path"));
            query.AddJoin(JoinTypes.Inner, User.GetTable(typeof(User)), "user_id", "user_id");
            query.AddJoin(JoinTypes.Inner, UserInfo.GetTable(typeof(UserInfo)), "user_id", "user_id");
            query.AddJoin(JoinTypes.Inner, UserProfile.GetTable(typeof(UserProfile)), "user_id", "user_id");
            query.AddJoin(JoinTypes.Left, new DataField("user_profile", "profile_country"), new DataField("countries", "country_iso"));
            query.AddJoin(JoinTypes.Left, new DataField("user_profile", "profile_religion"), new DataField("religions", "religion_id"));
            query.AddJoin(JoinTypes.Left, new DataField("user_info", "user_icon"), new DataField("gallery_items", "gallery_item_id"));
            query.AddSort(SortOrder.Ascending, "subscription_time_ut");
            query.LimitStart = (page - 1) * perPage;
            query.LimitCount = perPage;

            DataTable subscribersDataTable = core.Db.Query(query);

            foreach (DataRow dr in subscribersDataTable.Rows)
            {
                subscribers.Add(new User(core, dr, UserLoadOptions.All));
            }

            return subscribers;
        }
Example #18
0
        public static Notification Create(Core core, ApplicationEntry application, User actionBy, User receiver, ItemKey itemOwnerKey, ItemKey itemKey, string verb, string url, string action)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            int applicationId = 0;

            if (application != null)
            {
                // TODO: ensure only internals can call a null application
                applicationId = (int)application.Id;
            }

            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] randomNumber = new byte[16];
            rng.GetBytes(randomNumber);

            string rand = SessionState.HexRNG(randomNumber);
            string verificationString = SessionState.SessionMd5(rand + "bsseed" + DateTime.Now.Ticks.ToString() + core.Session.IPAddress.ToString()).ToLower();

            InsertQuery iQuery = new InsertQuery("notifications");
            iQuery.AddField("notification_primitive_id", receiver.Id);
            iQuery.AddField("notification_primitive_type_id", ItemKey.GetTypeId(core, typeof(User)));
            if (itemKey != null)
            {
                iQuery.AddField("notification_item_id", itemKey.Id);
                iQuery.AddField("notification_item_type_id", itemKey.TypeId);
            }
            if (itemOwnerKey != null)
            {
                iQuery.AddField("notification_item_owner_id", itemOwnerKey.Id);
                iQuery.AddField("notification_item_owner_type_id", itemOwnerKey.TypeId);
            }
            iQuery.AddField("notification_user_id", actionBy.Id);
            iQuery.AddField("notification_user_count", 1);
            iQuery.AddField("notification_verb", verb);
            iQuery.AddField("notification_action", action);
            iQuery.AddField("notification_url", url);
            iQuery.AddField("notification_time_ut", UnixTime.UnixTimeStamp());
            iQuery.AddField("notification_read", false);
            iQuery.AddField("notification_seen", false);
            iQuery.AddField("notification_application", applicationId);
            iQuery.AddField("notification_verification_string", verificationString);

            long notificationId = core.Db.Query(iQuery);

            core.Db.BeginTransaction();
            UpdateQuery query = new UpdateQuery(typeof(UserInfo));
            query.AddField("user_unread_notifications", new QueryOperation("user_unread_notifications", QueryOperations.Addition, 1));
            query.AddCondition("user_id", receiver.Id);

            core.Db.Query(query);

            Notification notification = new Notification(core, receiver, notificationId, string.Empty, string.Empty, UnixTime.UnixTimeStamp(), applicationId);
            // this is not elegant
            // TODO: write appropriate constructor
            notification.userId = actionBy.Id;
            notification.verb = verb;
            notification.action = action;
            notification.url = url;
            notification.itemKey = itemKey;
            notification.itemOwnerKey = itemOwnerKey;
            notification.verificationString = verificationString;

            return notification;
        }
Example #19
0
 internal static Notification Create(Core core, User receiver, ItemKey itemKey, string subject, string body)
 {
     return Create(core, null, receiver, itemKey, subject, body);
 }
Example #20
0
        public static Notification Create(Core core, ApplicationEntry application, User receiver, ItemKey itemKey, string subject, string body)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            int applicationId = 0;

            if (application != null)
            {
                // TODO: ensure only internals can call a null application
                applicationId = (int)application.Id;
            }

            InsertQuery iQuery = new InsertQuery("notifications");
            iQuery.AddField("notification_primitive_id", receiver.Id);
            iQuery.AddField("notification_primitive_type_id", ItemKey.GetTypeId(core, typeof(User)));
            if (itemKey != null)
            {
                iQuery.AddField("notification_item_id", itemKey.Id);
                iQuery.AddField("notification_item_type_id", itemKey.TypeId);
            }
            iQuery.AddField("notification_title", subject);
            iQuery.AddField("notification_body", body);
            iQuery.AddField("notification_time_ut", UnixTime.UnixTimeStamp());
            iQuery.AddField("notification_read", false);
            iQuery.AddField("notification_seen", false);
            iQuery.AddField("notification_application", applicationId);

            long notificationId = core.Db.Query(iQuery);

            UpdateQuery query = new UpdateQuery(typeof(UserInfo));
            query.AddField("user_unread_notifications", new QueryOperation("user_unread_notifications", QueryOperations.Addition, 1));
            query.AddCondition("user_id", receiver.Id);

            core.Db.Query(query);

            Notification notification = new Notification(core, receiver, notificationId, subject, body, UnixTime.UnixTimeStamp(), applicationId);

            return notification;
        }
Example #21
0
        private Notification(Core core, Primitive owner, long notificationId, string subject, string body, long timeRaw, int applicationId)
            : base(core)
        {
            this.db = db;
            this.recipient = owner;

            this.notificationId = notificationId;
            this.applicationId = applicationId;
            this.title = subject;
            this.body = body;
            this.ownerKey = new ItemKey(owner.Id, owner.TypeId);
            this.timeRaw = timeRaw;
        }
Example #22
0
        public void SavePermissions()
        {
            if (itemPermissions == null)
            {
                itemPermissions = GetPermissions(core, item);
            }
            if (itemGrants == null)
            {
                itemGrants = AccessControlGrant.GetGrants(core, item);
            }
            if (unsavedGrants == null)
            {
                unsavedGrants = new List<UnsavedAccessControlGrant>();
            }

            bool simple = item.IsSimplePermissions;

            string mode = core.Http.Form["aclmode"];
            switch (mode)
            {
                case "simple":
                    simple = true;
                    break;
                case "detailed":
                    simple = false;
                    break;
            }

            if (itemPermissions != null)
            {
                if (simple)
                {
                    //
                    // Simple
                    //

                    //HttpContext.Current.Response.Write("Simple<br />");
                    bool first = true;
                    PermissionTypes lastType = PermissionTypes.View;
                    List<PrimitivePermissionGroup> groups = null;

                    foreach (AccessControlPermission itemPermission in itemPermissions)
                    {
                        if (first || itemPermission.PermissionType != lastType)
                        {
                            groups = PermissionGroupSelectBox.FormPermissionGroups(core, "group-select-" + itemPermission.PermissionType.ToString());
                            //HttpContext.Current.Response.Write("Groups: " + groups.Count.ToString() + "<br />");

                            first = false;
                            lastType = itemPermission.PermissionType;
                        }

                        List<ItemKey> keysGranted = new List<ItemKey>();
                        foreach (AccessControlGrant grant in itemGrants)
                        {
                            if (grant.PermissionId == itemPermission.Id)
                            {
                                if (grant.Allow == AccessControlGrants.Allow)
                                {
                                    keysGranted.Add(grant.PrimitiveKey);
                                }
                            }
                        }

                        List<ItemKey> keysPosted = new List<ItemKey>();
                        foreach (PrimitivePermissionGroup ppg in groups)
                        {
                            // Only create if not exists
                            if (!keysGranted.Contains(ppg.ItemKey))
                            {
                                AccessControlGrant newACG = AccessControlGrant.Create(core, ppg.ItemKey, item.ItemKey, itemPermission.Id, AccessControlGrants.Allow);
                                itemGrants.Add(newACG);
                                //HttpContext.Current.Response.Write("Created<br />");
                            }
                            keysPosted.Add(ppg.ItemKey);
                        }

                        List<AccessControlGrant> grantsGrandfathered = new List<AccessControlGrant>();
                        foreach (AccessControlGrant grant in itemGrants)
                        {
                            if (grant.PermissionId == itemPermission.Id)
                            {
                                if (!keysPosted.Contains(grant.PrimitiveKey))
                                {
                                    grantsGrandfathered.Add(grant);
                                }
                            }
                        }

                        foreach (AccessControlGrant grant in grantsGrandfathered)
                        {
                            itemGrants.Remove(grant);
                            grant.Delete();
                            //HttpContext.Current.Response.Write("Deleted<br />");
                        }
                    }

                    item.IsSimplePermissions = true;
                    item.Update();
                }
                else
                {
                    //
                    // Detailed
                    //

                    foreach (AccessControlPermission itemPermission in itemPermissions)
                    {
                        SelectBox groupsSelectBox = BuildGroupsSelectBox(string.Format("new-permission-group[{0}]", itemPermission.Id), item.Owner);

                        foreach (SelectBoxItem gsbi in groupsSelectBox)
                        {
                            if (core.Http.Form[string.Format("new-grant[{0},{1}]", itemPermission.Id, gsbi.Key)] != null)
                            {
                                ItemKey ik = new ItemKey(gsbi.Key);

                                UnsavedAccessControlGrant uacg = new UnsavedAccessControlGrant(core, ik, item.ItemKey, itemPermission.Id, AccessControlGrants.Inherit);

                                if (core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]"] != null)
                                {
                                    switch (core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]"])
                                    {
                                        case "allow":
                                            uacg.Allow = AccessControlGrants.Allow;
                                            break;
                                        case "deny":
                                            uacg.Allow = AccessControlGrants.Deny;
                                            break;
                                        case "inherit":
                                            uacg.Allow = AccessControlGrants.Inherit;
                                            break;
                                    }
                                }

                                try
                                {
                                    AccessControlGrant newACG = AccessControlGrant.Create(core, ik, item.ItemKey, itemPermission.Id, uacg.Allow);
                                    itemGrants.Add(newACG);
                                }
                                catch (InvalidAccessControlGrantException)
                                {
                                }
                            }
                        }

                    }
                    foreach (string key in core.Http.Form.AllKeys)
                    {
                        if (key.StartsWith("allow[", StringComparison.Ordinal) && key.EndsWith("]", StringComparison.Ordinal))
                        {
                            string[] parts = key.Substring(6, key.Length - 7).Split(new char[] { ',' });

                            if (parts.Length == 3)
                            {
                                long itemPermissionId = 0;
                                long primitiveKeyTypeId = 0;
                                long primitiveKeyId = 0;

                                long.TryParse(parts[0], out itemPermissionId);
                                long.TryParse(parts[1], out primitiveKeyTypeId);
                                long.TryParse(parts[2], out primitiveKeyId);

                                //HttpContext.Current.Response.Write("Reading perms key: " + key + "<br />");

                                ItemKey pk = new ItemKey(primitiveKeyId, primitiveKeyTypeId);

                                UnsavedAccessControlGrant uacg = new UnsavedAccessControlGrant(core, pk, item.ItemKey, itemPermissionId, AccessControlGrants.Inherit);

                                if (core.Http.Form[key] != null)
                                {
                                    switch (core.Http.Form[key])
                                    {
                                        case "allow":
                                            uacg.Allow = AccessControlGrants.Allow;
                                            break;
                                        case "deny":
                                            uacg.Allow = AccessControlGrants.Deny;
                                            break;
                                        case "inherit":
                                            uacg.Allow = AccessControlGrants.Inherit;
                                            break;
                                    }
                                }

                                foreach (AccessControlGrant grant in itemGrants)
                                {
                                    if (grant.ItemKey.Equals(uacg.ItemKey) && grant.PrimitiveKey.Equals(uacg.PrimitiveKey) && grant.PermissionId.Equals(uacg.PermissionId))
                                    {
                                        //HttpContext.Current.Response.Write("Found grant: " + key + "<br />");
                                        // We only want to trigger a database update if things have changed
                                        if (grant.Allow != uacg.Allow)
                                        {
                                            //HttpContext.Current.Response.Write("Saving perms key: " + key + ", " + uacg.Allow + "<br />");
                                            grant.Allow = uacg.Allow;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    item.IsSimplePermissions = false;
                    item.Update();
                }
            }
        }
Example #23
0
 public override bool GetDefaultCan(string permission, ItemKey viewer)
 {
     switch (permission)
     {
         case "COMMENT":
             return IsNetworkMember(viewer);
         case "DELETE_COMMENTS":
             return false;
     }
     return false;
 }
Example #24
0
        public static bool IsSubscribed(Core core, ItemKey itemKey)
        {
            bool subscribed = false;

            if (core.Session.SignedIn)
            {
                SelectQuery query = Subscription.GetSelectQueryStub(core, typeof(Subscription));
                query.AddCondition("subscription_item_id", itemKey.Id);
                query.AddCondition("subscription_item_type_id", itemKey.TypeId);
                query.AddCondition("user_id", core.LoggedInMemberId);

                System.Data.Common.DbDataReader subscriptionReader = core.Db.ReaderQuery(query);

                subscribed = subscriptionReader.HasRows;

                subscriptionReader.Close();
                subscriptionReader.Dispose();
            }

            return subscribed;
        }
Example #25
0
        public override bool GetIsMemberOfPrimitive(ItemKey viewer, ItemKey primitiveKey)
        {
            if (core.LoggedInMemberId > 0)
            {
                return IsNetworkMember(viewer);
            }

            return false;
        }
Example #26
0
        public static bool SubscribeToItem(Core core, ItemKey itemKey)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            core.Db.BeginTransaction();

            SelectQuery query = Subscription.GetSelectQueryStub(core, typeof(Subscription));
            query.AddCondition("subscription_item_id", itemKey.Id);
            query.AddCondition("subscription_item_type_id", itemKey.TypeId);
            query.AddCondition("user_id", core.LoggedInMemberId);

            DataTable subscriptionDataTable = core.Db.Query(query);

            if (subscriptionDataTable.Rows.Count == 0)
            {
                InsertQuery iQuery = new InsertQuery(typeof(Subscription));
                iQuery.AddField("subscription_item_id", itemKey.Id);
                iQuery.AddField("subscription_item_type_id", itemKey.TypeId);
                iQuery.AddField("user_id", core.LoggedInMemberId);
                iQuery.AddField("subscription_time_ut", UnixTime.UnixTimeStamp());
                iQuery.AddField("subscription_ip", core.Session.IPAddress.ToString());

                core.Db.Query(iQuery);

                ItemInfo info = new ItemInfo(core, itemKey);
                info.IncrementSubscribers();

                UpdateQuery uQuery = new UpdateQuery(typeof(UserInfo));
                uQuery.AddField("user_subscriptions", new QueryOperation("user_subscriptions", QueryOperations.Addition, 1));
                uQuery.AddCondition("user_id", core.LoggedInMemberId);
                core.Db.Query(uQuery);

                return true;
            }
            else
            {
                throw new AlreadySubscribedException();
            }
        }
Example #27
0
 public bool IsItemGroupMember(ItemKey viewer, ItemKey key)
 {
     return false;
 }
Example #28
0
        public static bool UnsubscribeFromItem(Core core, ItemKey itemKey)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            core.Db.BeginTransaction();

            SelectQuery query = Subscription.GetSelectQueryStub(core, typeof(Subscription));
            query.AddCondition("subscription_item_id", itemKey.Id);
            query.AddCondition("subscription_item_type_id", itemKey.TypeId);
            query.AddCondition("user_id", core.LoggedInMemberId);

            DataTable subscriptionDataTable = core.Db.Query(query);

            if (subscriptionDataTable.Rows.Count == 1)
            {
                DeleteQuery dQuery = new DeleteQuery(typeof(Subscription));
                dQuery.AddCondition("subscription_item_id", itemKey.Id);
                dQuery.AddCondition("subscription_item_type_id", itemKey.TypeId);
                dQuery.AddCondition("user_id", core.LoggedInMemberId);

                core.Db.Query(dQuery);

                ItemInfo info = new ItemInfo(core, itemKey);
                info.DecrementSubscribers();

                UpdateQuery uQuery = new UpdateQuery(typeof(UserInfo));
                uQuery.AddField("user_subscriptions", new QueryOperation("user_subscriptions", QueryOperations.Subtraction, 1));
                uQuery.AddCondition("user_id", core.LoggedInMemberId);
                core.Db.Query(uQuery);

                return true;
            }

            return false;
        }
Example #29
0
        public static List<ItemKey> GetSubscribers(Core core, ItemKey itemKey, int page, int perPage)
        {
            List<ItemKey> subscribers = new List<ItemKey>();

            SelectQuery query = Subscription.GetSelectQueryStub(core, typeof(Subscription));
            query.AddCondition("subscription_item_id", itemKey.Id);
            query.AddCondition("subscription_item_type_id", itemKey.TypeId);
            query.AddSort(SortOrder.Ascending, "subscription_time_ut");
            if (page > 0 && perPage > 0)
            {
                query.LimitStart = (page - 1) * perPage;
                query.LimitCount = perPage;
            }

            DataTable subscribersDataTable = core.Db.Query(query);

            foreach (DataRow dr in subscribersDataTable.Rows)
            {
                Subscription subscription = new Subscription(core, dr);

                subscribers.Add(subscription.SubscriberKey);
            }

            return subscribers;
        }
Example #30
0
        public static List<AccessControlPermission> GetPermissions(Core core, ItemKey itemKey)
        {
            List<AccessControlPermission> permissions = new List<AccessControlPermission>();

            SelectQuery query = Item.GetSelectQueryStub(core, typeof(AccessControlPermission));
            query.AddCondition("permission_item_type_id", itemKey.TypeId);
            query.AddSort(SortOrder.Ascending, "permission_type");

            System.Data.Common.DbDataReader permissionsReader = core.Db.ReaderQuery(query);

            while (permissionsReader.Read())
            {
                permissions.Add(new AccessControlPermission(core, permissionsReader));
            }

            permissionsReader.Close();
            permissionsReader.Dispose();

            return permissions;
        }